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 */
(function (document, window, rJS, RSVP) {
(function (window, rJS) {
"use strict";
var default_view = "jio_view",
......@@ -33,35 +33,35 @@
child_gadget_url = 'gadget_erp5_pt_form_view_editable.html',
jio_document;
return gadget.declareGadget("gadget_officejs_form_view.html")
.push(function (result) {
gadget_utils = result;
return gadget.jio_get(options.jio_key);
})
.push(function (result) {
jio_document = result;
if (jio_document.portal_type === undefined) {
throw new Error('Can not display document: ' + options.jio_key);
}
return gadget_utils.getFormDefinition(jio_document.portal_type, default_view);
})
.push(function (form_definition) {
return gadget.changeState({
jio_key: options.jio_key,
doc: jio_document,
child_gadget_url: child_gadget_url,
form_definition: form_definition,
editable: false,
view: options.view,
//HARDCODED: following fields should be indicated by the configuration
has_more_views: false,
has_more_actions: options.view === "view",
is_form_list: false
.push(function (result) {
gadget_utils = result;
return gadget.jio_get(options.jio_key);
})
.push(function (result) {
jio_document = result;
if (jio_document.portal_type === undefined) {
throw new Error('Can not display document: ' + options.jio_key);
}
return gadget_utils.getFormDefinition(jio_document.portal_type, default_view);
})
.push(function (form_definition) {
return gadget.changeState({
jio_key: options.jio_key,
doc: jio_document,
child_gadget_url: child_gadget_url,
form_definition: form_definition,
editable: false,
view: options.view,
//HARDCODED: following fields should be indicated by the configuration
has_more_views: false,
has_more_actions: options.view === "view",
is_form_list: false
});
});
});
})
.onStateChange(function () {
return gadget_utils.renderGadget(this);
});
}(document, window, rJS, RSVP));
\ No newline at end of file
}(window, rJS));
\ No newline at end of file
......@@ -225,7 +225,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.64565.20677.40089</string> </value>
<value> <string>975.9054.53655.8977</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -243,7 +243,7 @@
</tuple>
<state>
<tuple>
<float>1555626551.51</float>
<float>1555685699.99</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -67,7 +67,9 @@
title: "Untitled Document",
portal_type: options.portal_type,
parent_relative_url: options.parent_relative_url
}, key, doc_key, doc_id;
},
key,
doc_key;
for (key in options) {
if (options.hasOwnProperty(key)) {
if (key.startsWith("my_")) {
......@@ -133,7 +135,8 @@
.declareMethod("renderGadget", function (target_gadget) {
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)
.push(function (json) {
form_json = json;
......
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.7931.50394.10308</string> </value>
<value> <string>975.9052.17383.43895</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1555618316.02</float>
<float>1555685570.38</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -55,7 +55,8 @@
.declareMethod("render", function (options) {
var gadget = this,
action_info_list = [],
document_title, portal_type;
document_title,
portal_type;
return gadget.jio_get(options.jio_key)
.push(function (document) {
var parent = "portal_types/" + document.portal_type,
......
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1555418496.64</float>
<float>1555685607.37</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (document, window, rJS, RSVP) {
/*jslint evil: true */
(function (window, rJS, RSVP) {
"use strict";
var gadget_utils, action_reference, action_type;
......@@ -43,19 +45,12 @@
if (action_type === "object_jio_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];
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]);
}
else {
throw "Field 'gadget_field_action_js_script' missing in action \
form. Please check '" + action_reference + "' action configuration.";
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]);
} else {
throw "Field 'gadget_field_action_js_script' missing in action form. Please check '" + action_reference + "' action configuration.";
}
} else {
throw "Action type must be 'object_jio_js_script'. Please check \
'" + action_reference + "' action configuration.";
throw "Action type must be 'object_jio_js_script'. Please check '" + action_reference + "' action configuration.";
}
});
});
......@@ -81,8 +76,7 @@
content_dict = options[2],
submit_code = gadget.state.submit_code;
if (action_type === "object_jio_js_script") {
return window.eval.call(window, '(function (gadget, gadget_utils, jio_key, content_dict)\
{' + submit_code + '})')(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);
}
});
}(document, window, rJS, RSVP));
}(window, rJS, RSVP));
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.7932.44543.51438</string> </value>
<value> <string>975.9050.9155.58845</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1555618542.84</float>
<float>1555685432.75</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