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 @@ ...@@ -83,19 +83,25 @@
}); });
}) })
.allowPublicAcquisition("jio_post", function (param_list) { .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) { .push(function (jio_gadget) {
return jio_gadget.post.apply(jio_gadget, param_list); 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) { .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) { .push(function (jio_gadget) {
return jio_gadget.putAttachment.apply(jio_gadget, param_list); return jio_gadget.putAttachment.apply(jio_gadget, param_list);
}); });
......
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html manifest="audioPlayer.appcache">
<head> <head>
<!-- renderjs --> <!-- renderjs -->
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script> <script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
......
/*global rJS, jIO, console, RSVP */ /*global rJS, jIO, console, RSVP, encodeURI */
/*jslint nomen: true*/ /*jslint nomen: true*/
(function (rJS, jIO) { (function (rJS, jIO) {
"use strict"; "use strict";
...@@ -13,15 +13,12 @@ ...@@ -13,15 +13,12 @@
.declareMethod('createJio', function (jio_options) { .declareMethod('createJio', function (jio_options) {
this.state_parameter_dict.jio_storage = jIO.createJIO(jio_options); this.state_parameter_dict.jio_storage = jIO.createJIO(jio_options);
}) })
.declareMethod('invalideJioSave', function (jio_options) {
this.save = {};
})
.declareMethod('allDocs', function () { .declareMethod('allDocs', function () {
var storage = this.state_parameter_dict.jio_storage, var storage = this.state_parameter_dict.jio_storage,
that = this; that = this;
if (that.save.data !== undefined) { /* if (that.save.data !== undefined) {
return that.save; return that.save;
} }*/
return storage.allDocs.apply(storage, arguments) return storage.allDocs.apply(storage, arguments)
.then(function (result) { .then(function (result) {
that.save = result; that.save = result;
...@@ -36,8 +33,7 @@ ...@@ -36,8 +33,7 @@
if (result.data !== undefined) { if (result.data !== undefined) {
length = result.data.rows.length; length = result.data.rows.length;
for (i = 0; i < length; i += 1) { for (i = 0; i < length; i += 1) {
if ((result.data.rows[i].doc.title === param._id) || if (result.data.rows[i].id === encodeURI(param._id)) { //xxx
(result.data.rows[i].id === param._id)) { //xxx
return ({"data": {"title" : result.data.rows[i].doc.title}}); return ({"data": {"title" : result.data.rows[i].doc.title}});
} }
} }
...@@ -65,6 +61,10 @@ ...@@ -65,6 +61,10 @@
.declareMethod('post', function () { .declareMethod('post', function () {
var storage = this.state_parameter_dict.jio_storage; var storage = this.state_parameter_dict.jio_storage;
return storage.post.apply(storage, arguments); 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)); }(rJS, jIO));
...@@ -216,7 +216,8 @@ ...@@ -216,7 +216,8 @@
g.url = URL.createObjectURL(blob); g.url = URL.createObjectURL(blob);
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
throw error; window.location = g.__element
.getElementsByClassName("next")[0].href;
}); });
} }
}) })
......
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
}) })
.fail(function (error) { .fail(function (error) {
document.getElementsByTagName('body')[0].textContent = document.getElementsByTagName('body')[0].textContent =
"network error: ip maybe not set"; "network error: ip maybe not defined";
}); });
}) })
.declareMethod('startService', function () { .declareMethod('startService', function () {
......
/*global window, rJS, RSVP, jIO, JSON, promiseEventListener, console, Error*/ /*global window, rJS, RSVP, jIO, JSON, promiseEventListener, console,
Error*/
/*jslint nomen: true*/ /*jslint nomen: true*/
(function (window, jIO, rJS) { (function (window, jIO, rJS) {
"use strict"; "use strict";
...@@ -10,7 +11,6 @@ ...@@ -10,7 +11,6 @@
.declareAcquiredMethod("displayThisTitle", "displayThisTitle") .declareAcquiredMethod("displayThisTitle", "displayThisTitle")
.declareAcquiredMethod("plEnablePage", "plEnablePage") .declareAcquiredMethod("plEnablePage", "plEnablePage")
.declareAcquiredMethod("plDisablePage", "plDisablePage") .declareAcquiredMethod("plDisablePage", "plDisablePage")
.declareAcquiredMethod("invalideJioSave", "invalideJioSave")
.declareMethod("render", function () { .declareMethod("render", function () {
return this.displayThisTitle("upload"); return this.displayThisTitle("upload");
}) })
...@@ -20,41 +20,43 @@ ...@@ -20,41 +20,43 @@
g.__element.getElementsByTagName('input')[0], g.__element.getElementsByTagName('input')[0],
info_context = info_context =
g.__element.getElementsByClassName('info')[0], g.__element.getElementsByClassName('info')[0],
i,
queue, queue,
uploaded = 0, uploaded = 0,
length; length;
function post() {
if (uploaded === length) {
return;
function post(index) { }
var now = new Date(); var now = new Date();
return g.jio_post({"title" : input_context.files[index].name, return g.jio_post({ "title" : input_context.files[uploaded].name,
"type" : "file", "type" : "file",
"format" : input_context.files[index].type, "format" : input_context.files[uploaded].type,
"size" : input_context.files[index].size, "size" : input_context.files[uploaded].size,
"modified" : now.toUTCString(), "modified" : now.toUTCString(),
"date" : now.getFullYear() + "-" + "date" : now.getFullYear() + "-" +
(now.getMonth() + 1) + "-" + now.getDate() (now.getMonth() + 1) + "-" + now.getDate()
}) }, 0)
.push(function (res) { .then(function (res) {
return g.jio_putAttachment({ return g.jio_putAttachment({
"_id" : res.id, "_id" : res.id,
"_attachment" : "enclosure", "_attachment" : "enclosure",
"_blob": input_context.files[index] "_blob": input_context.files[uploaded]
}); }, 0);
}) })
.push(function () { .then(function () {
uploaded += 1; 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>"; + " uploaded " + uploaded + "/" + length + " </li>";
if (uploaded === length) { if (uploaded === length) {
return g.plEnablePage(); return g.plEnablePage();
} }
queue.push(post);
}) })
.fail(function (e) { .fail(function (e) {
document.getElementsByTagName('body')[0].textContent = uploaded += 1;
JSON.stringify(e); console.log("error");
return post();
}); });
} }
queue = new RSVP.Queue(); queue = new RSVP.Queue();
...@@ -67,14 +69,9 @@ ...@@ -67,14 +69,9 @@
.push(function () { .push(function () {
return g.plDisablePage(); return g.plDisablePage();
}) })
.push(function () {
return g.invalideJioSave();
})
.push(function () { .push(function () {
length = input_context.files.length; length = input_context.files.length;
for (i = 0; i < length; i += 1) { queue.push(post);
queue.push(post(i));
}
}); });
return queue; 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