Commit 5d19966a authored by Roque's avatar Roque

erp5_officejs: some code cleanup

parent f64c3237
/*global document, window, rJS, RSVP */ /*global window, rJS */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (document, window, rJS, RSVP) { (function (window, rJS) {
"use strict"; "use strict";
var default_view = "jio_view", var default_view = "jio_view",
...@@ -33,35 +33,35 @@ ...@@ -33,35 +33,35 @@
child_gadget_url = 'gadget_erp5_pt_form_view_editable.html', child_gadget_url = 'gadget_erp5_pt_form_view_editable.html',
jio_document; jio_document;
return gadget.declareGadget("gadget_officejs_form_view.html") return gadget.declareGadget("gadget_officejs_form_view.html")
.push(function (result) { .push(function (result) {
gadget_utils = result; gadget_utils = result;
return gadget.jio_get(options.jio_key); return gadget.jio_get(options.jio_key);
}) })
.push(function (result) { .push(function (result) {
jio_document = result; jio_document = result;
if (jio_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_utils.getFormDefinition(jio_document.portal_type, default_view); return gadget_utils.getFormDefinition(jio_document.portal_type, default_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: jio_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: false, editable: false,
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
});
}); });
});
}) })
.onStateChange(function () { .onStateChange(function () {
return gadget_utils.renderGadget(this); return gadget_utils.renderGadget(this);
}); });
}(document, window, rJS, RSVP)); }(window, rJS));
\ 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.64565.20677.40089</string> </value> <value> <string>975.9054.53655.8977</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>1555626551.51</float> <float>1555685699.99</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -67,7 +67,9 @@ ...@@ -67,7 +67,9 @@
title: "Untitled Document", title: "Untitled Document",
portal_type: options.portal_type, portal_type: options.portal_type,
parent_relative_url: options.parent_relative_url parent_relative_url: options.parent_relative_url
}, key, doc_key, doc_id; },
key,
doc_key;
for (key in options) { for (key in options) {
if (options.hasOwnProperty(key)) { if (options.hasOwnProperty(key)) {
if (key.startsWith("my_")) { if (key.startsWith("my_")) {
...@@ -133,7 +135,8 @@ ...@@ -133,7 +135,8 @@
.declareMethod("renderGadget", function (target_gadget) { .declareMethod("renderGadget", function (target_gadget) {
var fragment = document.createElement('div'), var fragment = document.createElement('div'),
gadget = this, form_json; gadget = this,
form_json;
return gadget.renderForm(target_gadget.state.form_definition, target_gadget.state.doc) return gadget.renderForm(target_gadget.state.form_definition, target_gadget.state.doc)
.push(function (json) { .push(function (json) {
form_json = json; form_json = json;
......
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>975.7931.50394.10308</string> </value> <value> <string>975.9052.17383.43895</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>1555618316.02</float> <float>1555685570.38</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -55,7 +55,8 @@ ...@@ -55,7 +55,8 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
action_info_list = [], action_info_list = [],
document_title, portal_type; document_title,
portal_type;
return gadget.jio_get(options.jio_key) return gadget.jio_get(options.jio_key)
.push(function (document) { .push(function (document) {
var parent = "portal_types/" + document.portal_type, var parent = "portal_types/" + document.portal_type,
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1555418496.64</float> <float>1555685607.37</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 (document, window, rJS, RSVP) { /*jslint evil: true */
(function (window, rJS, RSVP) {
"use strict"; "use strict";
var gadget_utils, action_reference, action_type; var gadget_utils, action_reference, action_type;
...@@ -43,19 +45,12 @@ ...@@ -43,19 +45,12 @@
if (action_type === "object_jio_js_script") { if (action_type === "object_jio_js_script") {
if (form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script")) { if (form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script")) {
action_code = form_definition.fields_raw_properties.gadget_field_action_js_script.values.renderjs_extra[0]; action_code = form_definition.fields_raw_properties.gadget_field_action_js_script.values.renderjs_extra[0];
return window.eval.call(window, '(function (gadget, gadget_utils, options,\ return window.eval.call(window, '(function (gadget, gadget_utils, options, action_reference, parent_portal_type, form_definition, submit_code) {' + action_code[0] + '})')(gadget, gadget_utils, options, action_reference, parent_portal_type, form_definition, action_code[1]);
action_reference, parent_portal_type,\ } else {
form_definition, submit_code)\ throw "Field 'gadget_field_action_js_script' missing in action form. Please check '" + action_reference + "' action configuration.";
{' + action_code[0] + '})')
(gadget, gadget_utils, options, action_reference, parent_portal_type, form_definition, action_code[1]);
}
else {
throw "Field 'gadget_field_action_js_script' missing in action \
form. Please check '" + action_reference + "' action configuration.";
} }
} else { } else {
throw "Action type must be 'object_jio_js_script'. Please check \ throw "Action type must be 'object_jio_js_script'. Please check '" + action_reference + "' action configuration.";
'" + action_reference + "' action configuration.";
} }
}); });
}); });
...@@ -81,8 +76,7 @@ ...@@ -81,8 +76,7 @@
content_dict = options[2], content_dict = options[2],
submit_code = gadget.state.submit_code; submit_code = gadget.state.submit_code;
if (action_type === "object_jio_js_script") { if (action_type === "object_jio_js_script") {
return window.eval.call(window, '(function (gadget, gadget_utils, jio_key, content_dict)\ return window.eval.call(window, '(function (gadget, gadget_utils, jio_key, content_dict) {' + submit_code + '})')(gadget, gadget_utils, jio_key, content_dict);
{' + submit_code + '})')(gadget, gadget_utils, jio_key, content_dict);
} }
}); });
}(document, window, rJS, RSVP)); }(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>975.7932.44543.51438</string> </value> <value> <string>975.9050.9155.58845</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>1555618542.84</float> <float>1555685432.75</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