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
#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_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%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%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
gadget_erp5_field_listbox.html\n
gadget_erp5_field_listbox.js\n
......@@ -741,7 +742,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.4607.38713.16742</string> </value>
<value> <string>975.6482.16884.1314</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -759,7 +760,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1555421020.18</float>
<float>1555531972.2</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -118,10 +118,11 @@ CACHE:\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_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%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%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
NETWORK:\n
*
......@@ -267,7 +268,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.64630.63649.43178</string> </value>
<value> <string>975.6474.59109.37017</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -285,7 +286,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1555418535.58</float>
<float>1555531977.23</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -24,80 +24,42 @@
.declareMethod("render", function (options) {
var gadget = this,
child_gadget_url = 'gadget_erp5_pt_form_view_editable.html',
portal_type, parent_portal_type,
parent_relative_url, form_definition, action_code;
parent_portal_type, action_code;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getUrlParameter("action"),
gadget.getUrlParameter("action_type"),
gadget.getUrlParameter("portal_type"),
gadget.getUrlParameter("parent_portal_type"),
gadget.getUrlParameter("parent_relative_url"),
gadget.getSetting('portal_type'),
gadget.getSetting('parent_portal_type'),
gadget.getSetting('parent_relative_url'),
gadget.declareGadget("gadget_officejs_common_utils.html")
]);
})
.push(function (result) {
action_reference = result[0];
action_type = result[1];
portal_type = result[2] || result[5];
parent_portal_type = result[3] || result[6];
parent_relative_url = result[4] || result[7];
gadget_utils = result[8];
// This is the custom code to handle each specific action
if (action_reference === "new") {
options.portal_type = portal_type;
options.parent_relative_url = parent_relative_url;
// Temporarily hardcoded until new action in post module is fixed
return gadget_utils.getFormDefinition("HTML Post", "jio_view") //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];
eval(action_code[0]);
}
}
return gadget_utils.createDocument(options);
})
.push(function (jio_key) {
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") {
parent_portal_type = result[2] || result[3];
gadget_utils = result[4];
return gadget_utils.getFormDefinition(parent_portal_type, action_reference)
.push(function (result) {
form_definition = result;
// custom code will come from configuration side (action form)
.push(function (form_definition) {
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)\
return window.eval.call(window, '(function (gadget, gadget_utils, options,\
action_reference, parent_portal_type,\
form_definition, child_gadget_url, submit_code)\
{' + action_code[0] + '})')
(gadget, options, action_reference, form_definition, child_gadget_url, action_code[1]);
(gadget, gadget_utils, options, action_reference, parent_portal_type, form_definition, child_gadget_url, 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 " + action_reference + " not implemented yet";
});
});
})
......@@ -119,42 +81,10 @@
jio_key = options[0],
//target_url = options[1],
content_dict = options[2],
property;
// This is the custom code to handle each specific action
if (action_reference === "reply") {
submit_code = gadget.state.submit_code;
if (action_type === "object_jio_js_script") {
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
}
});
});
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));
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.6084.56587.64580</string> </value>
<value> <string>975.6480.52801.55961</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1555507949.33</float>
<float>1555531274.73</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