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