Commit a5397a63 authored by Roque's avatar Roque

erp5_officejs: code refactoring and cleanup

parent 133113b3
/*global document, window, rJS, RSVP, URLSearchParams */ /*global document, window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (document, window, rJS, RSVP, URLSearchParams) { (function (document, window, rJS, RSVP) {
"use strict"; "use strict";
var default_view = "jio_view";
function renderField(field_id, field_definition, document) { function renderField(field_id, field_definition, document) {
var key, raw_value, tales_expr, override, final_value, result = {}; var key, raw_value, tales_expr, override, final_value, result = {};
for (key in field_definition.values) { for (key in field_definition.values) {
...@@ -155,25 +153,25 @@ ...@@ -155,25 +153,25 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
child_gadget_url = 'gadget_erp5_pt_form_view_editable.html', child_gadget_url = 'gadget_erp5_pt_form_view_editable.html',
document, action_reference; jio_document;
return gadget.jio_get(options.jio_key) return gadget.jio_get(options.jio_key)
.push(function (jio_document) { .push(function (result) {
document = jio_document; jio_document = result;
if (document.portal_type === undefined) { if (jio_document.portal_type === undefined) {
throw new Error('Can not display document: ' + options.jio_key); throw new Error('Can not display document: ' + options.jio_key);
} }
return gadget.getFormDefinition(document.portal_type, options.view) return gadget.getFormDefinition(jio_document.portal_type, options.view)
.push(function (form_definition) { .push(function (form_definition) {
return gadget.changeState({ return gadget.changeState({
jio_key: options.jio_key, jio_key: options.jio_key,
doc: document, doc: jio_document,
child_gadget_url: child_gadget_url, child_gadget_url: child_gadget_url,
form_definition: form_definition, form_definition: form_definition,
editable: options.editable, editable: options.editable,
view: options.view, view: options.view,
//HARDCODED: following fields should be indicated by the configuration //HARDCODED: following fields should be indicated by the configuration
has_more_views: false, has_more_views: false,
has_more_actions: options.view == "view", has_more_actions: options.view === "view",
is_form_list: false is_form_list: false
}); });
}); });
...@@ -281,4 +279,4 @@ ...@@ -281,4 +279,4 @@
}); });
}); });
}(document, window, rJS, RSVP, URLSearchParams)); }(document, window, rJS, RSVP));
\ No newline at end of file \ No newline at end of file
...@@ -225,7 +225,7 @@ ...@@ -225,7 +225,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>974.59024.11735.30037</string> </value> <value> <string>974.60126.24569.41489</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -243,7 +243,7 @@ ...@@ -243,7 +243,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1554751815.26</float> <float>1554817831.18</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP, Handlebars, UriTemplate, calculatePageTitle, ensureArray */ /*global window, rJS, RSVP, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, UriTemplate, calculatePageTitle, ensureArray) { (function (window, rJS, RSVP, Handlebars) {
"use strict"; "use strict";
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
action_info_list = [], action_info_list = [],
erp5_document,
document_title; document_title;
return gadget.jio_get(options.jio_key) return gadget.jio_get(options.jio_key)
.push(function (document) { .push(function (document) {
...@@ -77,27 +76,29 @@ ...@@ -77,27 +76,29 @@
var url_for_parameter_list = [], i = 0, var url_for_parameter_list = [], i = 0,
page, action_key, action_doc; page, action_key, action_doc;
for (action_key in action_document_list) { for (action_key in action_document_list) {
if (action_document_list.hasOwnProperty(action_key)) {
page = "handle_action"; page = "handle_action";
action_doc = action_document_list[action_key]; action_doc = action_document_list[action_key];
if (action_doc.reference == "view" || action_doc.reference == "jio_view") { if (action_doc.reference === "view" || action_doc.reference === "jio_view") {
page = "ojs_controller"; page = "ojs_controller";
} }
url_for_parameter_list.push({command: 'change', options: {page: page, action: action_doc.reference}}); url_for_parameter_list.push({command: 'change', options: {page: page, action: action_doc.reference}});
action_info_list[i] = { reference: action_doc.reference, title: action_doc.title}; action_info_list[i] = { reference: action_doc.reference, title: action_doc.title};
i += 1; i += 1;
} }
}
return gadget.getUrlForList(url_for_parameter_list); return gadget.getUrlForList(url_for_parameter_list);
}) })
.push(function (url_list) { .push(function (url_list) {
var action_list = [], view_list = [], url, i, element; var action_list = [], view_list = [], i, element;
for (i = 0; i < url_list.length; i += 1) { for (i = 0; i < url_list.length; i += 1) {
element = { href: url_list[i], element = { href: url_list[i],
icon: null, icon: null,
name: action_info_list[i].reference, name: action_info_list[i].reference,
title: action_info_list[i].title }; title: action_info_list[i].title };
// TODO: maybe both view and jio_view should be ignored here // TODO: maybe both view and jio_view should be ignored here
if (element.name != "view") { if (element.name !== "view") {
if (element.name == "jio_view") { if (element.name === "jio_view") {
view_list.push(element); view_list.push(element);
} else { } else {
action_list.push(element); action_list.push(element);
...@@ -125,4 +126,4 @@ ...@@ -125,4 +126,4 @@
return; return;
}); });
}(window, rJS, RSVP, Handlebars, UriTemplate, calculatePageTitle, ensureArray)); }(window, rJS, RSVP, Handlebars));
\ No newline at end of file \ No newline at end of file
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>974.58836.59077.24849</string> </value> <value> <string>974.60153.5925.35891</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>1554740463.74</float> <float>1554819442.65</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP */ /*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Blob) { (function (window, rJS, RSVP) {
"use strict"; "use strict";
rJS(window) rJS(window)
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("handleAction", function (jio_key, portal_type) { .declareMethod("handleAction", function (jio_key) {
var gadget = this, jio_document, action_reference; var gadget = this, action_reference;
return gadget.getUrlParameter("action") return gadget.getUrlParameter("action")
.push(function (action_parameter) { .push(function (action_parameter) {
action_reference = action_parameter; action_reference = action_parameter;
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
// This is the custom code to handle this specific reply action // This is the custom code to handle this specific reply action
if (action_reference == "reply") { if (action_reference == "reply") {
var doc, title = document.title; var doc, title = document.title;
if (! title.startsWith("Re: ")) { if (!title.startsWith("Re: ")) {
title = "Re: " + document.title; title = "Re: " + document.title;
} }
doc = { doc = {
...@@ -42,29 +42,18 @@ ...@@ -42,29 +42,18 @@
}; };
return gadget.jio_post(doc) return gadget.jio_post(doc)
.push(function (id) { .push(function (id) {
jio_key = id; return [id, action_reference];
return gadget.jio_get(jio_key);
})
.push(function (created_doc) {
jio_document = created_doc;
return [jio_key, jio_document, action_reference];
}); });
} }
return [jio_key, jio_document, action_reference]; return [jio_key, action_reference];
}); });
}) })
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, doc_id; var gadget = this;
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return gadget.handleAction(options.jio_key);
gadget.getSetting('portal_type'),
gadget.getSetting('parent_relative_url')
]);
})
.push(function (result) {
return gadget.handleAction(options.jio_key, result[0]);
}) })
.push(function (action_result) { .push(function (action_result) {
return gadget.redirect({ return gadget.redirect({
...@@ -72,9 +61,9 @@ ...@@ -72,9 +61,9 @@
options: { options: {
page: undefined, page: undefined,
jio_key: action_result[0], jio_key: action_result[0],
view: action_result[2] view: action_result[1]
} }
}); });
}); });
}); });
}(window, rJS, RSVP, Blob)); }(window, rJS, RSVP));
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>974.59012.7910.14933</string> </value> <value> <string>974.60145.32757.53879</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -287,7 +287,7 @@ ...@@ -287,7 +287,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1554751292.19</float> <float>1554818976.22</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