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 @@
(function (window, rJS) {
"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)
/////////////////////////////////////////////////////////////////
......@@ -32,6 +27,9 @@
.declareMethod("render", function (options) {
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,
jio_document;
return gadget.declareGadget(common_utils_gadget_url)
......@@ -64,7 +62,7 @@
.onStateChange(function () {
var gadget = this;
return gadget.declareGadget(form_view_gadget_url)
return gadget.declareGadget("gadget_officejs_form_view.html")
.push(function (form_view_gadget) {
return form_view_gadget.renderGadget(gadget);
});
......
......@@ -225,7 +225,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.16237.58964.50022</string> </value>
<value> <string>975.17968.931.9949</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -243,7 +243,7 @@
</tuple>
<state>
<tuple>
<float>1556122084.05</float>
<float>1556220490.79</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, document, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*jslint evil: true */
(function (window, document, rJS, RSVP) {
"use strict";
var common_utils_gadget_url = "gadget_officejs_common_utils.html",
gadget_utils,
action_reference,
action_type,
action_gadget;
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
......@@ -27,49 +20,69 @@
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var gadget = this, parent_portal_type, action_gadget_url;
.declareMethod("getActionFormDefinition", function (action_reference) {
var gadget = this, parent_portal_type;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getUrlParameter("action"),
gadget.getUrlParameter("parent_portal_type"),
gadget.getSetting('parent_portal_type'),
gadget.declareGadget(common_utils_gadget_url)
gadget.declareGadget("gadget_officejs_common_utils.html")
]);
})
.push(function (result) {
action_reference = result[0];
parent_portal_type = result[1] || result[2];
gadget_utils = result[3];
return gadget_utils.getFormDefinition(parent_portal_type, action_reference)
.push(function (form_definition) {
action_type = form_definition.action_type;
if (action_type === "object_jio_js_script") {
if (form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script")) {
action_gadget_url = form_definition.fields_raw_properties.gadget_field_action_js_script.values.gadget_url;
var fragment = document.createElement('div');
gadget.element.appendChild(fragment);
return gadget.declareGadget(action_gadget_url, {
scope: "action_field",
element: fragment
})
.push(function (declared_gadget) {
action_gadget = declared_gadget;
return action_gadget.handleRender(gadget, options, action_reference, form_definition);
});
} 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.";
}
});
parent_portal_type = result[0] || result[1];
return result[2].getFormDefinition(parent_portal_type, action_reference);
});
})
.declareMethod("render", function (options) {
var gadget = this, action_reference;
return gadget.getUrlParameter("action")
.push(function (action_parameter) {
action_reference = action_parameter;
return gadget.getActionFormDefinition(action_reference);
})
.push(function (form_definition) {
if (form_definition.action_type === "object_jio_js_script") {
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.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 () {
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 () {
......@@ -87,8 +100,23 @@
jio_key = options[0],
//target_url = options[1],
content_dict = options[2];
if (action_type === "object_jio_js_script") {
action_gadget.handleSubmit(gadget, jio_key, content_dict);
}
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.handleSubmit(gadget, jio_key, content_dict);
});
}
});
});
}(window, document, rJS, RSVP));
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.17664.59173.20292</string> </value>
<value> <string>975.17966.28995.38997</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1556202915.67</float>
<float>1556220394.2</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