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
}); });
}); });
...@@ -201,67 +199,67 @@ ...@@ -201,67 +199,67 @@
form_json: form_json form_json: form_json
}) })
// render the header // render the header
.push(function () { .push(function () {
var url_for_parameter_list = [ var url_for_parameter_list = [
{command: 'change', options: {page: "tab"}}, {command: 'change', options: {page: "tab"}},
{command: 'change', options: {page: "action_offline"}}, {command: 'change', options: {page: "action_offline"}},
{command: 'history_previous'}, {command: 'history_previous'},
{command: 'selection_previous'}, {command: 'selection_previous'},
{command: 'selection_next'}, {command: 'selection_next'},
{command: 'change', options: {page: "export"}}, {command: 'change', options: {page: "export"}},
{command: 'display', options: {}} {command: 'display', options: {}}
]; ];
erp5_document = form_json.erp5_document; erp5_document = form_json.erp5_document;
if (erp5_document._links && erp5_document._links.action_object_new_content_action) { if (erp5_document._links && erp5_document._links.action_object_new_content_action) {
url_for_parameter_list.push({command: 'change', options: erp5_document._links.action_object_new_content_action}); url_for_parameter_list.push({command: 'change', options: erp5_document._links.action_object_new_content_action});
} }
return RSVP.all([ return RSVP.all([
gadget.getUrlForList(url_for_parameter_list), gadget.getUrlForList(url_for_parameter_list),
gadget.isDesktopMedia(), gadget.isDesktopMedia(),
gadget.getSetting('document_title_plural'), gadget.getSetting('document_title_plural'),
gadget.getSetting('upload_dict', false) gadget.getSetting('upload_dict', false)
]); ]);
}) })
.push(function (result_list) { .push(function (result_list) {
var url_list = result_list[0], header_dict; var url_list = result_list[0], header_dict;
if (gadget.state.is_form_list) { if (gadget.state.is_form_list) {
header_dict = { header_dict = {
panel_action: true, panel_action: true,
jump_url: "", jump_url: "",
fast_input_url: "", fast_input_url: "",
front_url: url_list[6], front_url: url_list[6],
filter_action: true, filter_action: true,
page_title: result_list[2] page_title: result_list[2]
}; };
} else { } else {
header_dict = { header_dict = {
selection_url: url_list[2], selection_url: url_list[2],
previous_url: url_list[3], previous_url: url_list[3],
next_url: url_list[4], next_url: url_list[4],
page_title: gadget.state.doc.title page_title: gadget.state.doc.title
}; };
if (gadget.state.has_more_views) { if (gadget.state.has_more_views) {
header_dict.tab_url = url_list[0]; header_dict.tab_url = url_list[0];
}
if (gadget.state.editable === "true") {
header_dict.save_action = true;
}
} }
if (gadget.state.editable === "true") { if (gadget.state.has_more_actions) {
header_dict.save_action = true; header_dict.actions_url = url_list[1];
} }
} if (url_list[7]) {
if (gadget.state.has_more_actions) { header_dict.add_url = url_list[7];
header_dict.actions_url = url_list[1]; }
} if (result_list[1]) {
if (url_list[7]) { header_dict.export_url = (
header_dict.add_url = url_list[7]; erp5_document._links.action_object_jio_report ||
} erp5_document._links.action_object_jio_exchange ||
if (result_list[1]) { erp5_document._links.action_object_jio_print
header_dict.export_url = ( ) ? url_list[5] : '';
erp5_document._links.action_object_jio_report || }
erp5_document._links.action_object_jio_exchange || return gadget.updateHeader(header_dict);
erp5_document._links.action_object_jio_print });
) ? url_list[5] : '';
}
return gadget.updateHeader(header_dict);
});
}) })
.onStateChange(function () { .onStateChange(function () {
...@@ -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) {
...@@ -75,29 +74,31 @@ ...@@ -75,29 +74,31 @@
}) })
.push(function (action_document_list) { .push(function (action_document_list) {
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) {
page = "handle_action"; if (action_document_list.hasOwnProperty(action_key)) {
action_doc = action_document_list[action_key]; page = "handle_action";
if (action_doc.reference == "view" || action_doc.reference == "jio_view") { action_doc = action_document_list[action_key];
page = "ojs_controller"; if (action_doc.reference === "view" || action_doc.reference === "jio_view") {
page = "ojs_controller";
}
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};
i += 1;
} }
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};
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,52 +19,41 @@ ...@@ -19,52 +19,41 @@
// 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;
return gadget.jio_get(jio_key); return gadget.jio_get(jio_key);
}) })
.push(function (document) { .push(function (document) {
// 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 = {
title: title,
//thread parent: same as base post
source_reference: document.source_reference,
portal_type: document.portal_type,
parent_relative_url: document.parent_relative_url
};
return gadget.jio_post(doc)
.push(function (id) {
return [id, action_reference];
});
} }
doc = { return [jio_key, action_reference];
title: title, });
//thread parent: same as base post
source_reference: document.source_reference,
portal_type: document.portal_type,
parent_relative_url: document.parent_relative_url
};
return gadget.jio_post(doc)
.push(function (id) {
jio_key = id;
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];
});
}) })
.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