Commit b800a43e authored by Roque's avatar Roque

erp5_officejs: remove global variables in handle action and controller gadgets

parent 74e549c7
...@@ -3,11 +3,6 @@ ...@@ -3,11 +3,6 @@
(function (window, rJS) { (function (window, rJS) {
"use strict"; "use strict";
var default_view = "jio_view",
common_utils_gadget_url = "gadget_officejs_common_utils.html",
form_view_gadget_url = "gadget_officejs_form_view.html",
child_gadget_url = 'gadget_erp5_pt_form_view_editable.html';
rJS(window) rJS(window)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -32,6 +27,9 @@ ...@@ -32,6 +27,9 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
default_view = "jio_view",
common_utils_gadget_url = "gadget_officejs_common_utils.html",
child_gadget_url = 'gadget_erp5_pt_form_view_editable.html',
gadget_utils, gadget_utils,
jio_document; jio_document;
return gadget.declareGadget(common_utils_gadget_url) return gadget.declareGadget(common_utils_gadget_url)
...@@ -64,7 +62,7 @@ ...@@ -64,7 +62,7 @@
.onStateChange(function () { .onStateChange(function () {
var gadget = this; var gadget = this;
return gadget.declareGadget(form_view_gadget_url) return gadget.declareGadget("gadget_officejs_form_view.html")
.push(function (form_view_gadget) { .push(function (form_view_gadget) {
return form_view_gadget.renderGadget(gadget); return form_view_gadget.renderGadget(gadget);
}); });
......
...@@ -225,7 +225,7 @@ ...@@ -225,7 +225,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>975.16237.58964.50022</string> </value> <value> <string>975.17968.931.9949</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>1556122084.05</float> <float>1556220490.79</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, document, rJS, RSVP */ /*global window, document, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
/*jslint evil: true */
(function (window, document, rJS, RSVP) { (function (window, document, rJS, RSVP) {
"use strict"; "use strict";
var common_utils_gadget_url = "gadget_officejs_common_utils.html",
gadget_utils,
action_reference,
action_type,
action_gadget;
rJS(window) rJS(window)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Acquired methods // Acquired methods
...@@ -27,49 +20,69 @@ ...@@ -27,49 +20,69 @@
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) { .declareMethod("getActionFormDefinition", function (action_reference) {
var gadget = this, parent_portal_type, action_gadget_url; var gadget = this, parent_portal_type;
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
gadget.getUrlParameter("action"),
gadget.getUrlParameter("parent_portal_type"), gadget.getUrlParameter("parent_portal_type"),
gadget.getSetting('parent_portal_type'), gadget.getSetting('parent_portal_type'),
gadget.declareGadget(common_utils_gadget_url) gadget.declareGadget("gadget_officejs_common_utils.html")
]); ]);
}) })
.push(function (result) { .push(function (result) {
action_reference = result[0]; parent_portal_type = result[0] || result[1];
parent_portal_type = result[1] || result[2]; return result[2].getFormDefinition(parent_portal_type, action_reference);
gadget_utils = result[3]; });
return gadget_utils.getFormDefinition(parent_portal_type, action_reference) })
.push(function (form_definition) {
action_type = form_definition.action_type; .declareMethod("render", function (options) {
if (action_type === "object_jio_js_script") { var gadget = this, action_reference;
if (form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script")) { return gadget.getUrlParameter("action")
action_gadget_url = form_definition.fields_raw_properties.gadget_field_action_js_script.values.gadget_url; .push(function (action_parameter) {
var fragment = document.createElement('div'); action_reference = action_parameter;
gadget.element.appendChild(fragment); return gadget.getActionFormDefinition(action_reference);
return gadget.declareGadget(action_gadget_url, { })
scope: "action_field", .push(function (form_definition) {
element: fragment if (form_definition.action_type === "object_jio_js_script") {
}) if (form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script")) {
.push(function (declared_gadget) { var fragment = document.createElement('div'),
action_gadget = declared_gadget; action_gadget_url = form_definition.fields_raw_properties.gadget_field_action_js_script.values.gadget_url;
return action_gadget.handleRender(gadget, options, action_reference, form_definition); gadget.element.appendChild(fragment);
}); return gadget.declareGadget(action_gadget_url, {
} else { scope: "action_field",
throw "Field 'gadget_field_action_js_script' missing in action form. Please check '" + action_reference + "' action configuration."; element: fragment
} })
} else { .push(function (action_gadget) {
throw "Action type must be 'object_jio_js_script'. Please check '" + action_reference + "' action configuration."; return action_gadget.handleRender(gadget, options, action_reference, form_definition);
} });
}); }
}
// avoid crash if form doesn't have gadget_field_action_js_script or object_jio_js_script action
// render form without submit (and warn/inform user?)
}); });
}) })
.onStateChange(function () { .onStateChange(function () {
return action_gadget.render(this); var gadget = this;
return gadget.getUrlParameter("action")
.push(function (action_reference) {
return gadget.getActionFormDefinition(action_reference);
})
.push(function (form_definition) {
if (form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script")) {
var fragment = document.createElement('div'),
action_gadget_url = form_definition.fields_raw_properties.gadget_field_action_js_script.values.gadget_url;
gadget.element.appendChild(fragment);
return gadget.declareGadget(action_gadget_url, {
scope: "action_field",
element: fragment
})
.push(function (action_gadget) {
return action_gadget.render(gadget);
});
}
});
}) })
.allowPublicAcquisition('notifySubmit', function () { .allowPublicAcquisition('notifySubmit', function () {
...@@ -87,8 +100,23 @@ ...@@ -87,8 +100,23 @@
jio_key = options[0], jio_key = options[0],
//target_url = options[1], //target_url = options[1],
content_dict = options[2]; content_dict = options[2];
if (action_type === "object_jio_js_script") { return gadget.getUrlParameter("action")
action_gadget.handleSubmit(gadget, jio_key, content_dict); .push(function (action_reference) {
} return gadget.getActionFormDefinition(action_reference);
})
.push(function (form_definition) {
if (form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script")) {
var fragment = document.createElement('div'),
action_gadget_url = form_definition.fields_raw_properties.gadget_field_action_js_script.values.gadget_url;
gadget.element.appendChild(fragment);
return gadget.declareGadget(action_gadget_url, {
scope: "action_field",
element: fragment
})
.push(function (action_gadget) {
return action_gadget.handleSubmit(gadget, jio_key, content_dict);
});
}
});
}); });
}(window, document, rJS, RSVP)); }(window, document, 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.17664.59173.20292</string> </value> <value> <string>975.17966.28995.38997</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>1556202915.67</float> <float>1556220394.2</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