Commit d89f4164 authored by Roque's avatar Roque

erp5_officejs: handle action uses custom code from configuration side (WIP)

parent 4f6fb29e
/*global window, rJS, RSVP */ /*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
/*jslint evil: true */
(function (document, window, rJS, RSVP) { (function (document, window, rJS, RSVP) {
"use strict"; "use strict";
var gadget_utils, action_reference; var gadget_utils, action_reference, action_type;
rJS(window) rJS(window)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -26,8 +25,7 @@ ...@@ -26,8 +25,7 @@
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, portal_type, parent_portal_type,
parent_relative_url, form_definition, parent_relative_url, form_definition, custom_code;
action_type, custom_code;
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
...@@ -51,9 +49,8 @@ ...@@ -51,9 +49,8 @@
gadget_utils = result[8]; gadget_utils = result[8];
// This is the custom code to handle each specific action // This is the custom code to handle each specific action
if (action_reference === "new") { if (action_reference === "new") {
var doc_options = {}; options.portal_type = portal_type;
doc_options.portal_type = portal_type; options.parent_relative_url = parent_relative_url;
doc_options.parent_relative_url = parent_relative_url;
// Temporarily hardcoded until new action in post module is fixed // Temporarily hardcoded until new action in post module is fixed
return gadget_utils.getFormDefinition("HTML Post", "jio_view") //parent_portal_type, action_reference) return gadget_utils.getFormDefinition("HTML Post", "jio_view") //parent_portal_type, action_reference)
.push(function (result) { .push(function (result) {
...@@ -65,7 +62,7 @@ ...@@ -65,7 +62,7 @@
eval(custom_code[0]); eval(custom_code[0]);
} }
} }
return gadget_utils.createDocument(doc_options); return gadget_utils.createDocument(options);
}) })
.push(function (jio_key) { .push(function (jio_key) {
return gadget.jio_get(jio_key) return gadget.jio_get(jio_key)
...@@ -93,34 +90,30 @@ ...@@ -93,34 +90,30 @@
if (action_type === "object_jio_js_script") { if (action_type === "object_jio_js_script") {
if (form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script")) { if (form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script")) {
custom_code = form_definition.fields_raw_properties.gadget_field_action_js_script.values.renderjs_extra[0]; custom_code = form_definition.fields_raw_properties.gadget_field_action_js_script.values.renderjs_extra[0];
eval(custom_code[0]); // move this to form configuration
custom_code = ["return gadget.jio_get(options.jio_key)\
.push(function (result) {\
parent_document = result;\
var title = parent_document.title;\
if (!title.startsWith('Re: ')) { title = 'Re: ' + parent_document.title; }\
console.log(title);\
return gadget.changeState({\
doc: {title: title},\
submit_code: submit_code,\
parent_document: parent_document,\
child_gadget_url: child_gadget_url,\
form_definition: form_definition,\
view: action_reference,\
editable: true,\
has_more_views: false,\
has_more_actions: false,\
is_form_list: false\
}); });" , "console.log('some submit code')"];
return window.eval.call(window, '(function (gadget, options, action_reference, form_definition, child_gadget_url, submit_code)\
{' + custom_code[0] + '})')
(gadget, options, action_reference, form_definition, child_gadget_url, custom_code[1]);
} }
} }
var parent_document, child_document, child_jio_key;
return gadget.jio_get(options.jio_key)
.push(function (result) {
parent_document = result;
return gadget_utils.getFormDefinition(parent_document.portal_type, action_reference);
})
.push(function (result) {
var title = parent_document.title;
form_definition = result;
if (!title.startsWith("Re: ")) {
title = "Re: " + parent_document.title;
}
return gadget.changeState({
doc: {title: title},
parent_document: parent_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: false,
is_form_list: false
});
});
}); });
} }
throw "Action " + action_reference + " not implemented yet"; throw "Action " + action_reference + " not implemented yet";
...@@ -148,34 +141,40 @@ ...@@ -148,34 +141,40 @@
property; property;
// This is the custom code to handle each specific action // This is the custom code to handle each specific action
if (action_reference === "reply") { if (action_reference === "reply") {
var document = { if (action_type === "object_jio_js_script") {
my_title: gadget.state.doc.title, var submit_code = gadget.state.submit_code;
portal_type: gadget.state.parent_document.portal_type, // move this to form configuration
parent_relative_url: gadget.state.parent_document.parent_relative_url, submit_code = "var document = {\
my_source_reference: gadget.state.parent_document.source_reference my_title: gadget.state.doc.title,\
}; portal_type: gadget.state.parent_document.portal_type,\
for (property in content_dict) { parent_relative_url: gadget.state.parent_document.parent_relative_url,\
if (content_dict.hasOwnProperty(property)) { my_source_reference: gadget.state.parent_document.source_reference\
document["my_" + property] = content_dict[property]; }, property;\
} for (property in content_dict) {\
} if (content_dict.hasOwnProperty(property)) {\
return gadget_utils.createDocument(document) document['my_' + property] = content_dict[property];\
.push(function (id) { }\
jio_key = id; }\
return gadget.notifySubmitting(); return gadget_utils.createDocument(document)\
}) .push(function (id) {\
.push(function () { jio_key = id;\
return gadget.notifySubmitted({message: 'Data Updated', status: 'success'}); return gadget.notifySubmitting();\
}) })\
.push(function () { .push(function () {\
return gadget.redirect({ return gadget.notifySubmitted({message: 'Data Updated', status: 'success'});\
command: 'display', })\
options: { .push(function () {\
jio_key: jio_key, return gadget.redirect({\
editable: true command: 'display',\
options: {\
jio_key: jio_key,\
editable: true\
}\
});\
});";
return window.eval.call(window, '(function (gadget, gadget_utils, content_dict)\
{' + submit_code + '})')(gadget, gadget_utils, content_dict);
} }
});
});
} }
if (action_reference === "new") { if (action_reference === "new") {
return gadget.notifySubmitting() return gadget.notifySubmitting()
......
...@@ -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.4704.7332.52360</string> </value> <value> <string>975.5092.42049.34269</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>1555424781.77</float> <float>1555447984.11</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