Commit fd120a1c authored by Xiaowu Zhang's avatar Xiaowu Zhang

improved upload files

parent 37945473
CACHE MANIFEST
# v1
CACHE:
audioplayer.css
audioplayer.js
../audioplayer_bridge/index.html
../audioplayer_bridge/audiogadget.js
../audioplayer_control/index.html
../audioplayer_control/control.js
../audioplayer_control/control.css
../audioplayer_playlist/index.html
../audioplayer_playlist/playlist.js
../audioplayer_upload/upload.js
../audioplayer_upload/index.js
../lib/URI.js
../lib/handlebars.min.js
../lib/jio.js
../lib/jquery.js
../lib/jquerymobile.css
../lib/jquerymobile.js
../lib/renderjs.min.js
../lib/rsvp.min.js
../lib/uritemplate.min.js
\ No newline at end of file
......@@ -83,19 +83,25 @@
});
})
.allowPublicAcquisition("jio_post", function (param_list) {
return this.getDeclaredGadget(storageType(this.storageType))
var type;
if (param_list[1] === 0) {
type = 0;
} else {
type = this.storageType;
}
return this.getDeclaredGadget(storageType(type))
.push(function (jio_gadget) {
return jio_gadget.post.apply(jio_gadget, param_list);
});
})
.allowPublicAcquisition("invalideJioSave", function (param_list) {
return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) {
return jio_gadget.invalideJioSave.apply(jio_gadget, param_list);
});
})
.allowPublicAcquisition("jio_putAttachment", function (param_list) {
return this.getDeclaredGadget(storageType(this.storageType))
var type;
if (param_list[1] === 0) {
type = 0;
} else {
type = this.storageType;
}
return this.getDeclaredGadget(storageType(type))
.push(function (jio_gadget) {
return jio_gadget.putAttachment.apply(jio_gadget, param_list);
});
......
<!DOCTYPE html>
<html lang="en">
<html manifest="audioPlayer.appcache">
<head>
<!-- renderjs -->
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
......
/*global rJS, jIO, console, RSVP */
/*global rJS, jIO, console, RSVP, encodeURI */
/*jslint nomen: true*/
(function (rJS, jIO) {
"use strict";
......@@ -13,15 +13,12 @@
.declareMethod('createJio', function (jio_options) {
this.state_parameter_dict.jio_storage = jIO.createJIO(jio_options);
})
.declareMethod('invalideJioSave', function (jio_options) {
this.save = {};
})
.declareMethod('allDocs', function () {
var storage = this.state_parameter_dict.jio_storage,
that = this;
if (that.save.data !== undefined) {
/* if (that.save.data !== undefined) {
return that.save;
}
}*/
return storage.allDocs.apply(storage, arguments)
.then(function (result) {
that.save = result;
......@@ -36,8 +33,7 @@
if (result.data !== undefined) {
length = result.data.rows.length;
for (i = 0; i < length; i += 1) {
if ((result.data.rows[i].doc.title === param._id) ||
(result.data.rows[i].id === param._id)) { //xxx
if (result.data.rows[i].id === encodeURI(param._id)) { //xxx
return ({"data": {"title" : result.data.rows[i].doc.title}});
}
}
......@@ -65,6 +61,10 @@
.declareMethod('post', function () {
var storage = this.state_parameter_dict.jio_storage;
return storage.post.apply(storage, arguments);
})
.declareMethod('put', function () {
var storage = this.state_parameter_dict.jio_storage;
return storage.put.apply(storage, arguments);
});
}(rJS, jIO));
......@@ -216,7 +216,8 @@
g.url = URL.createObjectURL(blob);
})
.push(undefined, function (error) {
throw error;
window.location = g.__element
.getElementsByClassName("next")[0].href;
});
}
})
......
......@@ -68,7 +68,7 @@
})
.fail(function (error) {
document.getElementsByTagName('body')[0].textContent =
"network error: ip maybe not set";
"network error: ip maybe not defined";
});
})
.declareMethod('startService', function () {
......
/*global window, rJS, RSVP, jIO, JSON, promiseEventListener, console, Error*/
/*global window, rJS, RSVP, jIO, JSON, promiseEventListener, console,
Error*/
/*jslint nomen: true*/
(function (window, jIO, rJS) {
"use strict";
......@@ -10,7 +11,6 @@
.declareAcquiredMethod("displayThisTitle", "displayThisTitle")
.declareAcquiredMethod("plEnablePage", "plEnablePage")
.declareAcquiredMethod("plDisablePage", "plDisablePage")
.declareAcquiredMethod("invalideJioSave", "invalideJioSave")
.declareMethod("render", function () {
return this.displayThisTitle("upload");
})
......@@ -20,41 +20,43 @@
g.__element.getElementsByTagName('input')[0],
info_context =
g.__element.getElementsByClassName('info')[0],
i,
queue,
uploaded = 0,
length;
function post(index) {
function post() {
if (uploaded === length) {
return;
}
var now = new Date();
return g.jio_post({"title" : input_context.files[index].name,
"type" : "file",
"format" : input_context.files[index].type,
"size" : input_context.files[index].size,
"modified" : now.toUTCString(),
"date" : now.getFullYear() + "-" +
(now.getMonth() + 1) + "-" + now.getDate()
})
.push(function (res) {
return g.jio_post({ "title" : input_context.files[uploaded].name,
"type" : "file",
"format" : input_context.files[uploaded].type,
"size" : input_context.files[uploaded].size,
"modified" : now.toUTCString(),
"date" : now.getFullYear() + "-" +
(now.getMonth() + 1) + "-" + now.getDate()
}, 0)
.then(function (res) {
return g.jio_putAttachment({
"_id" : res.id,
"_attachment" : "enclosure",
"_blob": input_context.files[index]
});
"_blob": input_context.files[uploaded]
}, 0);
})
.push(function () {
.then(function () {
uploaded += 1;
info_context.innerHTML += "<li>" + input_context.files[index].name
info_context.innerHTML += "<li>" +
input_context.files[uploaded - 1].name
+ " uploaded " + uploaded + "/" + length + " </li>";
if (uploaded === length) {
return g.plEnablePage();
}
queue.push(post);
})
.fail(function (e) {
document.getElementsByTagName('body')[0].textContent =
JSON.stringify(e);
uploaded += 1;
console.log("error");
return post();
});
}
queue = new RSVP.Queue();
......@@ -67,14 +69,9 @@
.push(function () {
return g.plDisablePage();
})
.push(function () {
return g.invalideJioSave();
})
.push(function () {
length = input_context.files.length;
for (i = 0; i < length; i += 1) {
queue.push(post(i));
}
queue.push(post);
});
return queue;
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment