Commit 025e4a14 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

crib-enable: Add Improvement from work in ERP5

parent 9bd914cd
/*global window, rJS, jIO, FormData */ /*global window, rJS, jIO, FormData, navigator, RSVP */
/*jslint indent: 2, maxerr: 3 */ /*jslint indent: 2, maxerr: 3 */
(function (window, rJS, jIO) { (function (window, rJS, jIO) {
"use strict"; "use strict";
...@@ -30,33 +30,65 @@ ...@@ -30,33 +30,65 @@
.ready(function (gadget) { .ready(function (gadget) {
// Initialize the gadget local parameters // Initialize the gadget local parameters
var path = "", path_list = window.location.pathname.split("/");
if (path_list) {
if (path_list[path_list.length - 1] !== "") {
if (path_list[path_list.length - 1].endsWith(".html")) {
path_list[path_list.length - 1] = "";
} else {
path_list.push("");
}
}
path = path_list.join("/");
}
gadget.state_parameter_dict = {}; gadget.state_parameter_dict = {};
gadget.state_parameter_dict.default_document = window.location.protocol + gadget.state_parameter_dict.default_document = window.location.protocol +
"//" + window.location.host + "//" + window.location.host + path;
window.location.pathname.substring(
0,
window.location.pathname.length - "gadget_jio_crib.html".length
) + "/";
this.state_parameter_dict.jio_storage = jIO.createJIO({ this.state_parameter_dict.jio_storage = jIO.createJIO({
"type": "indexeddb", "type": "indexeddb",
"database": "ojs_source_code" "database": "ojs_source_code"
}); });
return this.state_parameter_dict.jio_storage.put(gadget.state_parameter_dict.default_document, {}) return this.state_parameter_dict.jio_storage.put(gadget.state_parameter_dict.default_document, {});
}) })
.ready(function (gadget) { .ready(function (gadget) {
var jio_storage;
return RSVP.Queue()
.push(function () {
jio_storage = jIO.createJIO({
type: "indexeddb",
database: "setting"
});
return jio_storage.get("setting");
})
.push(function (result) {
if (result.site_editor_gadget_url) {
return;
}
result.site_editor_gadget_url = window.location.href;
return jio_storage.put("setting", result);
}, function (error) {
if (error.status_code === 404) {
return jio_storage.put(
"setting", {
site_editor_gadget_url: window.location.href
});
}
});
})
.ready(function () {
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
// XXX Hack to not add a new service worker when one is already declared // XXX Hack to not add a new service worker when one is already declared
if (!navigator.serviceWorker.controller) { if (!navigator.serviceWorker.controller) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return navigator.serviceWorker.register( return navigator.serviceWorker.register(
'/gadget_cribjs_bootloader_serviceworker.js', 'gadget_cribjs_bootloader_serviceworker.js',
{scope: '/'} {scope: './'}
); );
}) })
.push(function (registration) { .push(function (registration) {
return waitForServiceWorkerActive(registration); return waitForServiceWorkerActive(registration);
}) });
} }
} else { } else {
throw "Service Worker are not available in your browser"; throw "Service Worker are not available in your browser";
...@@ -85,9 +117,9 @@ ...@@ -85,9 +117,9 @@
.declareMethod('allDocs', function () { .declareMethod('allDocs', function () {
var storage = this.state_parameter_dict.jio_storage; var storage = this.state_parameter_dict.jio_storage;
return storage.allAttachments(this.state_parameter_dict.default_document) return storage.allAttachments(this.state_parameter_dict.default_document)
.push(function(result) { .push(function (result) {
return result; return result;
}) });
}) })
.declareMethod('remove', function (url) { .declareMethod('remove', function (url) {
var storage = this.state_parameter_dict.jio_storage; var storage = this.state_parameter_dict.jio_storage;
......
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