Commit ae55033e authored by Roque's avatar Roque

erp5_officejs: code cleanup and minor fixes

parent 36f83e78
/*global window, rJS, jIO, FormData, UriTemplate */
/*global window, window, rJS, jIO, RSVP, document, URLSearchParams, UriTemplate, console */
/*jslint indent: 2, maxerr: 3 */
(function (window, rJS, jIO, RSVP, document, URLSearchParams, console) {
(function (window, rJS, jIO, RSVP, document, URLSearchParams, UriTemplate, console) {
"use strict";
// jIO call wrapper for redirection to authentication page if needed
......@@ -63,8 +63,8 @@
function processHateoasDict(raw_dict) {
var raw_fields, type, parent, field_key, field_id, return_dict = {};
return_dict.raw_dict = raw_dict;
if ("_embedded" in raw_dict && "_view" in raw_dict._embedded) {
/*jslint nomen: true*/
/*jslint nomen: true*/
if (raw_dict.hasOwnProperty("_embedded") && raw_dict._embedded.hasOwnProperty("_view")) {
raw_fields = raw_dict._embedded._view;
type = raw_dict._links.type.name;
parent = raw_dict._links.parent.name;
......@@ -158,7 +158,6 @@
if (jio_storage_name === undefined) { return; }
appcache_storage = jIO.createJIO(jio_appchache_options);
// verify if appcache-local sync needs to be done
// TODO: find a better flag for this?
return appcache_storage.get(sync_flag)
.push(undefined, function (error) {
if (error && String(error.status_code) !== "404") {
......@@ -168,41 +167,38 @@
.push(function () {
return appcache_storage.allAttachments(origin_url)
.push(function (attachment_dict) {
return new RSVP.Queue()
.push(function () {
var id, promise_list = [], i = 0;
for (id in attachment_dict) {
if (attachment_dict.hasOwnProperty(id)) {
if (id.indexOf(hateoas_script) === -1) {
promise_list.push(appcache_storage.getAttachment(origin_url, id));
} else {
promise_list.push(appcache_storage.getAttachment(origin_url, id, {"format": "json"}));
}
configuration_ids_list[i] = id;
i += 1;
}
var id, promise_list = [], i = 0;
for (id in attachment_dict) {
if (attachment_dict.hasOwnProperty(id)) {
if (id.indexOf(hateoas_script) === -1) {
promise_list.push(appcache_storage.getAttachment(origin_url, id));
} else {
promise_list.push(appcache_storage.getAttachment(origin_url, id, {"format": "json"}));
}
return RSVP.all(promise_list);
})
.push(function (content_list) {
var i, id, parser, urlParams, content, promise_list = [];
for (i = 0; i < content_list.length; i += 1) {
id = configuration_ids_list[i];
parser = document.createElement('a');
parser.href = id;
urlParams = new URLSearchParams(parser.search);
id = urlParams.get("relative_url");
if (id !== null) { // ignore non configuration elements
content = processHateoasDict(content_list[i]);
promise_list.push(appcache_storage.put(id, content));
}
}
return RSVP.all(promise_list);
})
.push(function () {
return appcache_storage.put(sync_flag, {})
.push(undefined);
});
configuration_ids_list[i] = id;
i += 1;
}
}
return RSVP.all(promise_list);
})
.push(function (content_list) {
var i, id, parser, urlParams, content, promise_list = [];
for (i = 0; i < content_list.length; i += 1) {
id = configuration_ids_list[i];
parser = document.createElement('a');
parser.href = id;
urlParams = new URLSearchParams(parser.search);
id = urlParams.get("relative_url");
if (id !== null) { // ignore non configuration elements
content = processHateoasDict(content_list[i]);
promise_list.push(appcache_storage.put(id, content));
}
}
return RSVP.all(promise_list);
})
.push(function () {
return appcache_storage.put(sync_flag, {})
.push(undefined);
});
}, function (error) {
console.log("Error while appcache-local storage synchronization");
......@@ -246,4 +242,4 @@
return wrapJioCall(this, 'repair', arguments);
});
}(window, rJS, jIO, RSVP, document, URLSearchParams, console));
\ No newline at end of file
}(window, rJS, jIO, RSVP, document, URLSearchParams, UriTemplate, console));
\ No newline at end of file
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.60870.58404.40738</string> </value>
<value> <string>975.60897.16999.55244</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1558708599.95</float>
<float>1558709867.09</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -55,13 +55,14 @@
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("getHTMLElements", function (element_list) {
.declareMethod("getHTMLElementList", function (element_list) {
var gadget = this,
i = 0,
element_info_list = [],
url_for_parameter_list = [],
element_info;
for (var key in element_list) {
element_info,
key;
for (key in element_list) {
if (element_list.hasOwnProperty(key)) {
element_info = element_list[key];
url_for_parameter_list.push({ command: 'change', options: element_info });
......@@ -71,19 +72,19 @@
}
return gadget.getUrlForList(url_for_parameter_list)
.push(function (url_list) {
var html_element_list = [], i, element;
for (i = 0; i < url_list.length; i += 1) {
element = { href: url_list[i],
var html_element_list = [], j, element;
for (j = 0; j < url_list.length; j += 1) {
element = { href: url_list[j],
icon: null,
name: element_info_list[i].reference,
title: element_info_list[i].title };
name: element_info_list[j].reference,
title: element_info_list[j].title };
html_element_list.push(element);
}
return html_element_list;
});
})
.declareMethod("getAllActions", function (portal_type, action_category, options) {
.declareMethod("getAllActions", function (portal_type, options) {
var gadget = this,
action_info_dict = {views: {}, actions: {}},
query = 'portal_type: "Action Information" AND parent_relative_url: "portal_types/' + portal_type + '"';
......@@ -98,7 +99,7 @@
return RSVP.all(path_for_jio_get_list);
})
.push(function (action_document_list) {
var action_settings_list = [], page, action_key, action_doc;
var action_settings_list = [], page, action_key, action_doc, key, action_settings;
for (action_key in action_document_list) {
if (action_document_list.hasOwnProperty(action_key)) {
action_doc = action_document_list[action_key];
......@@ -117,9 +118,9 @@
});
}
}
for (var key in action_settings_list) {
for (key in action_settings_list) {
if (action_settings_list.hasOwnProperty(key)) {
var action_settings = action_settings_list[key];
action_settings = action_settings_list[key];
if (view_categories.includes(action_settings.action_type)) {
action_info_dict.views[action_settings.action] = action_settings;
} else {
......@@ -144,17 +145,17 @@
.push(function (document) {
document_title = document.title;
return document.portal_type;
}, function (error) {
}, function () {
document_title = options.portal_type;
return options.portal_type;
})
.push(function (portal_type) {
return gadget.getAllActions(portal_type, view_categories[0], options);
return gadget.getAllActions(portal_type, options);
})
.push(function (action_info_dict) {
return RSVP.all([
gadget.getHTMLElements(action_info_dict.views),
gadget.getHTMLElements(action_info_dict.actions)
gadget.getHTMLElementList(action_info_dict.views),
gadget.getHTMLElementList(action_info_dict.actions)
]);
})
// TODO: check other lists like clone or delete?
......
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.40561.441.8482</string> </value>
<value> <string>975.60908.18646.37734</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1557499265.0</float>
<float>1558710504.54</float>
<string>UTC</string>
</tuple>
</state>
......
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