Commit d756e23e authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Make Upload from Zip file functionnal on landing page

parent 2f90a5af
...@@ -19,28 +19,8 @@ ...@@ -19,28 +19,8 @@
return default_value; return default_value;
} }
function loadContentFromZIPURL(gadget, options) { function loadZipIntoCrib(crib_sw_gadget, zip, from_path, path_to_load) {
var path_to_load = options.to_path, path_to_load_length, file_list, crib_sw_gadget, var promise_list = [], url_number = 0;
from_path = options.from_path, zip_url = options.zip_url,
jio_gadget, url_list = [], url_number = 0;
return new RSVP.Queue()
.push(function () {
return gadget.getDeclaredGadget('crib_sw_gadget');
})
.push(function (returned_gadget) {
crib_sw_gadget = returned_gadget;
return fetch(zip_url)
.then(function (response) { // 2) filter on 200 OK
if (response.status === 200 || response.status === 0) {
return Promise.resolve(response.blob());
} else {
return Promise.reject(new Error(response.statusText));
}
});
})
.push(JSZip.loadAsync)
.push(function (zip) {
var promise_list = [];
zip.forEach(function (relativePath, zipEntry) { zip.forEach(function (relativePath, zipEntry) {
var end_url; var end_url;
url_number += 1; url_number += 1;
...@@ -79,6 +59,51 @@ ...@@ -79,6 +59,51 @@
) )
}) })
return RSVP.all(promise_list) return RSVP.all(promise_list)
}
function loadContentFromZIPFile(gadget, options) {
var path_to_load = options.to_path,
from_path = options.from_path,
file_list = options.file_list;
if (file_list.length === 0) {
return "No File to Load";
}
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('crib_sw_gadget'),
JSZip.loadAsync(file_list[0])
]);
})
.push(function (result_list) {
return loadZipIntoCrib(result_list[0], result_list[1], from_path, path_to_load);
})
.push(console.log, console.log)
}
function loadContentFromZIPURL(gadget, options) {
var path_to_load = options.to_path, file_list, crib_sw_gadget,
from_path = options.from_path, zip_url = options.zip_url,
jio_gadget, url_list = [], url_number = 0;
return new RSVP.Queue()
.push(function () {
return gadget.getDeclaredGadget('crib_sw_gadget');
})
.push(function (returned_gadget) {
crib_sw_gadget = returned_gadget;
return fetch(zip_url)
.then(function (response) { // 2) filter on 200 OK
if (response.status === 200 || response.status === 0) {
return Promise.resolve(response.blob());
} else {
return Promise.reject(new Error(response.statusText));
}
});
})
.push(JSZip.loadAsync)
.push(function (zip) {
return loadZipIntoCrib(crib_sw_gadget, zip, from_path, path_to_load);
}) })
.push(console.log, console.log) .push(console.log, console.log)
} }
...@@ -91,7 +116,7 @@ ...@@ -91,7 +116,7 @@
return loadContentFromZIPURL(this, options); return loadContentFromZIPURL(this, options);
}) })
.declareMethod('loadFromZipFile', function (options) { .declareMethod('loadFromZipFile', function (options) {
return loadContentFromZIPURL(gadget, options); return loadContentFromZIPFile(this, options);
}) })
.allowPublicAcquisition("getSetting", function (argument_list) { .allowPublicAcquisition("getSetting", function (argument_list) {
return getSetting(this, argument_list[0], argument_list[1]); return getSetting(this, argument_list[0], argument_list[1]);
......
...@@ -13,9 +13,6 @@ ...@@ -13,9 +13,6 @@
return params; return params;
} }
function loadCribJSFromZipFile (gadget, event) {
}
function makeid(length) { function makeid(length) {
var result = ''; var result = '';
var characters = 'abcdefghijklmnopqrstuvwxyz0123456789'; var characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
...@@ -26,6 +23,26 @@ ...@@ -26,6 +23,26 @@
return result; return result;
} }
function loadCribJSFromZipFile (gadget, event) {
return RSVP.Queue()
.push(function() {
return gadget.getDeclaredGadget("jio_cribjs");
})
.push(function(jio_cribjs_gadget) {
return jio_cribjs_gadget.loadFromZipFile({
path: document.location.href,
file_list: gadget.props.element.querySelector("form.crib-load-from-zip-file .load-zip-file").files,
from_path: gadget.props.element.querySelector("form.crib-load-from-zip-file .load-from-zip-path").value,
to_path: gadget.props.element.querySelector("form.crib-load-from-zip-file .load-zip-to-path").value,
application_id: "cribjs"
})
})
.push(function (url_list) {
document.location = gadget.props.element.querySelector("form.crib-load-from-zip-file .redirect-url").value;
})
.push(console.log, console.log);
}
function loadCribJSFromZipUrl (gadget, event) { function loadCribJSFromZipUrl (gadget, event) {
return RSVP.Queue() return RSVP.Queue()
.push(function() { .push(function() {
......
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