Commit c340bb96 authored by Roque's avatar Roque

erp5_officejs: handle action uses action code from configuration side

parent b31889dd
...@@ -251,10 +251,11 @@ jio_appcachestorage.js\n ...@@ -251,10 +251,11 @@ jio_appcachestorage.js\n
#configuration resources\n #configuration resources\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_officejs_jio_connector%2FHTMLPost_viewAsJio&view=jio_view&appcache=1\n hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_officejs_jio_connector%2FHTMLPost_viewAsJio&view=jio_view&appcache=1\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_officejs_jio_connector%2FHTMLPost_viewReplyDialog&view=jio_view&appcache=1\n hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_officejs_jio_connector%2FHTMLPost_viewReplyDialog&view=jio_view&appcache=1\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_post%2FPostModule_newHTMLPost&view=jio_view&appcache=1\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F1&view=view&appcache=1\n hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F1&view=view&appcache=1\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F2&view=view&appcache=1\n hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F2&view=view&appcache=1\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F3&view=view&appcache=1\n hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F3&view=view&appcache=1\n
#hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FPost%20Module%2F2&view=view&appcache=1\n hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FPost%20Module%2F2&view=view&appcache=1\n
\n \n
gadget_erp5_field_listbox.html\n gadget_erp5_field_listbox.html\n
gadget_erp5_field_listbox.js\n gadget_erp5_field_listbox.js\n
...@@ -741,7 +742,7 @@ NETWORK:\n ...@@ -741,7 +742,7 @@ NETWORK:\n
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>975.4607.38713.16742</string> </value> <value> <string>975.6482.16884.1314</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -759,7 +760,7 @@ NETWORK:\n ...@@ -759,7 +760,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1555421020.18</float> <float>1555531972.2</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -118,10 +118,11 @@ CACHE:\n ...@@ -118,10 +118,11 @@ CACHE:\n
#discussion tool\n #discussion tool\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_officejs_jio_connector%2FHTMLPost_viewAsJio&view=jio_view&appcache=1\n hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_officejs_jio_connector%2FHTMLPost_viewAsJio&view=jio_view&appcache=1\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_officejs_jio_connector%2FHTMLPost_viewReplyDialog&view=jio_view&appcache=1\n hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_officejs_jio_connector%2FHTMLPost_viewReplyDialog&view=jio_view&appcache=1\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_post%2FPostModule_newHTMLPost&view=jio_view&appcache=1\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F1&view=view&appcache=1\n hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F1&view=view&appcache=1\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F2&view=view&appcache=1\n hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F2&view=view&appcache=1\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F3&view=view&appcache=1\n hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F3&view=view&appcache=1\n
#hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FPost%20Module%2F2&view=view&appcache=1\n hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FPost%20Module%2F2&view=view&appcache=1\n
\n \n
NETWORK:\n NETWORK:\n
* *
...@@ -267,7 +268,7 @@ NETWORK:\n ...@@ -267,7 +268,7 @@ NETWORK:\n
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>974.64630.63649.43178</string> </value> <value> <string>975.6474.59109.37017</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -285,7 +286,7 @@ NETWORK:\n ...@@ -285,7 +286,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1555418535.58</float> <float>1555531977.23</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -24,80 +24,42 @@ ...@@ -24,80 +24,42 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
child_gadget_url = 'gadget_erp5_pt_form_view_editable.html', child_gadget_url = 'gadget_erp5_pt_form_view_editable.html',
portal_type, parent_portal_type, parent_portal_type, action_code;
parent_relative_url, form_definition, action_code;
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
gadget.getUrlParameter("action"), gadget.getUrlParameter("action"),
gadget.getUrlParameter("action_type"), gadget.getUrlParameter("action_type"),
gadget.getUrlParameter("portal_type"),
gadget.getUrlParameter("parent_portal_type"), gadget.getUrlParameter("parent_portal_type"),
gadget.getUrlParameter("parent_relative_url"),
gadget.getSetting('portal_type'),
gadget.getSetting('parent_portal_type'), gadget.getSetting('parent_portal_type'),
gadget.getSetting('parent_relative_url'),
gadget.declareGadget("gadget_officejs_common_utils.html") gadget.declareGadget("gadget_officejs_common_utils.html")
]); ]);
}) })
.push(function (result) { .push(function (result) {
action_reference = result[0]; action_reference = result[0];
action_type = result[1]; action_type = result[1];
portal_type = result[2] || result[5]; parent_portal_type = result[2] || result[3];
parent_portal_type = result[3] || result[6]; gadget_utils = result[4];
parent_relative_url = result[4] || result[7]; return gadget_utils.getFormDefinition(parent_portal_type, action_reference)
gadget_utils = result[8]; .push(function (form_definition) {
// This is the custom code to handle each specific action if (action_type === "object_jio_js_script") {
if (action_reference === "new") { if (form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script")) {
options.portal_type = portal_type; action_code = form_definition.fields_raw_properties.gadget_field_action_js_script.values.renderjs_extra[0];
options.parent_relative_url = parent_relative_url; return window.eval.call(window, '(function (gadget, gadget_utils, options,\
// Temporarily hardcoded until new action in post module is fixed action_reference, parent_portal_type,\
return gadget_utils.getFormDefinition("HTML Post", "jio_view") //parent_portal_type, action_reference) form_definition, child_gadget_url, submit_code)\
.push(function (result) { {' + action_code[0] + '})')
form_definition = result; (gadget, gadget_utils, options, action_reference, parent_portal_type, form_definition, child_gadget_url, action_code[1]);
// custom code will come from configuration side (action form)
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];
eval(action_code[0]);
}
} }
return gadget_utils.createDocument(options); else {
}) throw "Field 'gadget_field_action_js_script' missing in action \
.push(function (jio_key) { form. Please check '" + action_reference + "' action configuration.";
return gadget.jio_get(jio_key)
.push(function (new_document) {
return gadget.changeState({
jio_key: jio_key,
doc: new_document,
child_gadget_url: child_gadget_url,
form_definition: form_definition,
view: action_reference,
//HARDCODED: following fields should be indicated by the configuration
editable: true,
has_more_views: false,
has_more_actions: true,
is_form_list: false
});
});
});
}
if (action_reference === "reply") {
return gadget_utils.getFormDefinition(parent_portal_type, action_reference)
.push(function (result) {
form_definition = result;
// custom code will come from configuration side (action form)
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, options, action_reference, form_definition, child_gadget_url, submit_code)\
{' + action_code[0] + '})')
(gadget, options, action_reference, form_definition, child_gadget_url, action_code[1]);
}
} }
}); } else {
} throw "Action type must be 'object_jio_js_script'. Please check \
throw "Action " + action_reference + " not implemented yet"; '" + action_reference + "' action configuration.";
}
});
}); });
}) })
...@@ -119,42 +81,10 @@ ...@@ -119,42 +81,10 @@
jio_key = options[0], jio_key = options[0],
//target_url = options[1], //target_url = options[1],
content_dict = options[2], content_dict = options[2],
property; submit_code = gadget.state.submit_code;
// This is the custom code to handle each specific action if (action_type === "object_jio_js_script") {
if (action_reference === "reply") { return window.eval.call(window, '(function (gadget, gadget_utils, jio_key, content_dict)\
if (action_type === "object_jio_js_script") { {' + submit_code + '})')(gadget, gadget_utils, jio_key, content_dict);
var submit_code = gadget.state.submit_code;
return window.eval.call(window, '(function (gadget, gadget_utils, content_dict)\
{' + submit_code + '})')(gadget, gadget_utils, content_dict);
}
}
if (action_reference === "new") {
return gadget.notifySubmitting()
.push(function () {
// this should be jio_getattachment (using target_url)
return gadget.jio_get(jio_key);
})
.push(function (document) {
var property;
for (property in content_dict) {
if (content_dict.hasOwnProperty(property)) {
document[property] = content_dict[property];
}
}
return gadget.jio_put(jio_key, document);
})
.push(function () {
return gadget.notifySubmitted({message: 'Data Updated', status: 'success'});
})
.push(function () {
return gadget.redirect({
command: 'display',
options: {
jio_key: jio_key,
editable: true
}
});
});
} }
}); });
}(document, window, rJS, RSVP)); }(document, 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.6084.56587.64580</string> </value> <value> <string>975.6480.52801.55961</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>1555507949.33</float> <float>1555531274.73</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