Commit 776fe66e authored by Roque's avatar Roque

erp5_officejs: refactoring - moving code to utils gadget

parent 67c7345e
...@@ -27,6 +27,30 @@ ...@@ -27,6 +27,30 @@
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("getFormInfo", function (form_definition) {
var child_gadget_url,
form_type,
action_category = form_definition.action_type;
switch (action_category) {
case 'object_list':
form_type = 'list';
child_gadget_url = 'gadget_erp5_pt_form_list.html';
break;
case 'object_dialog':
form_type = 'dialog';
child_gadget_url = 'gadget_erp5_pt_form_dialog.html';
break;
case 'object_jio_js_script':
form_type = 'dialog';
child_gadget_url = 'gadget_erp5_pt_form_dialog.html';
break;
default:
form_type = 'page';
child_gadget_url = 'gadget_erp5_pt_form_view_editable.html';
}
return [form_type, child_gadget_url];
})
.declareMethod("createDocument", function (options) { .declareMethod("createDocument", function (options) {
var gadget = this, var gadget = this,
doc = { doc = {
......
...@@ -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.39669.47531.23961</string> </value> <value> <string>975.39673.49091.10956</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>1557436424.93</float> <float>1557436563.26</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -3,31 +3,6 @@ ...@@ -3,31 +3,6 @@
(function (window, rJS, document) { (function (window, rJS, document) {
"use strict"; "use strict";
// TODO: move this to common utils
function getFormInfo(form_definition) {
var child_gadget_url,
form_type,
action_category = form_definition.action_type;
switch (action_category) {
case 'object_list':
form_type = 'list';
child_gadget_url = 'gadget_erp5_pt_form_list.html';
break;
case 'object_dialog':
form_type = 'dialog';
child_gadget_url = 'gadget_erp5_pt_form_dialog.html';
break;
case 'object_jio_js_script':
form_type = 'dialog';
child_gadget_url = 'gadget_erp5_pt_form_dialog.html';
break;
default:
form_type = 'page';
child_gadget_url = 'gadget_erp5_pt_form_view_editable.html';
}
return [form_type, child_gadget_url];
}
rJS(window) rJS(window)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -54,6 +29,7 @@ ...@@ -54,6 +29,7 @@
var gadget = this, var gadget = this,
default_view = "jio_view", default_view = "jio_view",
common_utils_gadget_url = "gadget_officejs_common_utils.html", common_utils_gadget_url = "gadget_officejs_common_utils.html",
form_definition,
gadget_utils, gadget_utils,
jio_document, jio_document,
portal_type, portal_type,
...@@ -83,9 +59,12 @@ ...@@ -83,9 +59,12 @@
front_page = portal_type === parent_portal_type; front_page = portal_type === parent_portal_type;
return gadget_utils.getFormDefinition(portal_type, default_view); return gadget_utils.getFormDefinition(portal_type, default_view);
}) })
.push(function (form_definition) { .push(function (result) {
var form_info = getFormInfo(form_definition), form_definition = result;
form_type = form_info[0], return gadget_utils.getFormInfo(form_definition);
})
.push(function (form_info) {
var form_type = form_info[0],
child_gadget_url = form_info[1]; child_gadget_url = form_info[1];
return gadget.changeState({ return gadget.changeState({
jio_key: options.jio_key, jio_key: options.jio_key,
...@@ -103,8 +82,7 @@ ...@@ -103,8 +82,7 @@
.onStateChange(function () { .onStateChange(function () {
var fragment = document.createElement('div'), var fragment = document.createElement('div'),
gadget = this, gadget = this;
options;
while (this.element.firstChild) { while (this.element.firstChild) {
this.element.removeChild(this.element.firstChild); this.element.removeChild(this.element.firstChild);
} }
......
...@@ -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.39482.5501.59630</string> </value> <value> <string>975.39691.34802.60091</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>1557425018.64</float> <float>1557437553.02</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -4,31 +4,6 @@ ...@@ -4,31 +4,6 @@
(function (window, document, rJS, RSVP) { (function (window, document, rJS, RSVP) {
"use strict"; "use strict";
// TODO: move this to common utils
function getFormInfo(form_definition) {
var child_gadget_url,
form_type,
action_category = form_definition.action_type;
switch (action_category) {
case 'object_list':
form_type = 'list';
child_gadget_url = 'gadget_erp5_pt_form_list.html';
break;
case 'object_dialog':
form_type = 'dialog';
child_gadget_url = 'gadget_erp5_pt_form_dialog.html';
break;
case 'object_jio_js_script':
form_type = 'dialog';
child_gadget_url = 'gadget_erp5_pt_form_dialog.html';
break;
default:
form_type = 'page';
child_gadget_url = 'gadget_erp5_pt_form_view_editable.html';
}
return [form_type, child_gadget_url];
}
rJS(window) rJS(window)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Acquired methods // Acquired methods
...@@ -60,7 +35,7 @@ ...@@ -60,7 +35,7 @@
}) })
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, action_reference; var gadget = this, action_reference, gadget_utils, form_definition;
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
...@@ -68,19 +43,24 @@ ...@@ -68,19 +43,24 @@
gadget.getUrlParameter('parent_relative_url'), gadget.getUrlParameter('parent_relative_url'),
gadget.getSetting('portal_type'), gadget.getSetting('portal_type'),
gadget.getSetting('parent_relative_url'), gadget.getSetting('parent_relative_url'),
gadget.getUrlParameter("action") gadget.getUrlParameter("action"),
gadget.declareGadget("gadget_officejs_common_utils.html")
]); ]);
}) })
.push(function (result) { .push(function (result) {
action_reference = result[4]; action_reference = result[4];
if (result[0] !== undefined) {options.portal_type = result[0]; } else {options.portal_type = result[2]; } if (result[0] !== undefined) {options.portal_type = result[0]; } else {options.portal_type = result[2]; }
if (result[1] !== undefined) {options.parent_relative_url = result[1]; } else {options.parent_relative_url = result[3]; } if (result[1] !== undefined) {options.parent_relative_url = result[1]; } else {options.parent_relative_url = result[3]; }
gadget_utils = result[5];
return gadget.getActionFormDefinition(action_reference); return gadget.getActionFormDefinition(action_reference);
}) })
.push(function (form_definition) { .push(function (result) {
form_definition = result;
return gadget_utils.getFormInfo(form_definition);
})
.push(function (form_info) {
var fragment = document.createElement('div'), var fragment = document.createElement('div'),
action_gadget_url, action_gadget_url,
form_info = getFormInfo(form_definition),
form_type = form_info[0], form_type = form_info[0],
child_gadget_url = form_info[1], child_gadget_url = form_info[1],
valid_action = form_definition.action_type === "object_jio_js_script" && valid_action = form_definition.action_type === "object_jio_js_script" &&
......
...@@ -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.39668.29926.39628</string> </value> <value> <string>975.39692.31170.31266</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>1557436203.22</float> <float>1557437551.19</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