Commit ca411361 authored by Roque's avatar Roque

erp5_post: refactoring on action gadgets

parent 194ce8e4
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
(function (window, rJS, RSVP) { (function (window, rJS, RSVP) {
"use strict"; "use strict";
var gadget_utils; var parent_gadget, form_view_gadget;
rJS(window) rJS(window)
...@@ -22,29 +22,32 @@ ...@@ -22,29 +22,32 @@
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("handleRender", function (gadget, gadget_utils, options, action_reference, parent_portal_type, form_definition) { .declareMethod("render", function (gadget) {
var child_gadget_url = 'gadget_erp5_pt_form_view_editable.html'; return form_view_gadget.renderGadget(gadget);
})
.declareMethod("handleRender", function (gadget, options, action_reference, form_definition) {
var child_gadget_url = 'gadget_erp5_pt_form_view_editable.html', this_gadget = this;
parent_gadget = gadget;
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
gadget.getUrlParameter('portal_type'), parent_gadget.getUrlParameter('portal_type'),
gadget.getUrlParameter('parent_relative_url'), parent_gadget.getUrlParameter('parent_relative_url'),
gadget.getSetting('portal_type'), parent_gadget.getSetting('portal_type'),
gadget.getSetting('parent_relative_url') parent_gadget.getSetting('parent_relative_url'),
parent_gadget.declareGadget("gadget_officejs_form_view.html")
]); ]);
}) })
.push(function (result) { .push(function (result) {
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]; }
return gadget_utils.getFormDefinition(parent_portal_type, action_reference) form_view_gadget = result[4];
.push(function (result) { return form_view_gadget.createDocument(options)
form_definition = result;
return gadget_utils.createDocument(options);
})
.push(function (jio_key) { .push(function (jio_key) {
return gadget.jio_get(jio_key) return parent_gadget.jio_get(jio_key)
.push(function (new_document) { .push(function (new_document) {
return gadget.changeState({ return parent_gadget.changeState({
jio_key: jio_key, jio_key: jio_key,
doc: new_document, doc: new_document,
child_gadget_url: child_gadget_url, child_gadget_url: child_gadget_url,
...@@ -60,7 +63,7 @@ ...@@ -60,7 +63,7 @@
}); });
}) })
.declareMethod("handleSubmit", function (gadget, gadget_utils, jio_key, content_dict) { .declareMethod("handleSubmit", function (gadget, jio_key, content_dict) {
return gadget.notifySubmitting() return gadget.notifySubmitting()
.push(function () { .push(function () {
return gadget.jio_get(jio_key); return gadget.jio_get(jio_key);
......
...@@ -22,27 +22,35 @@ ...@@ -22,27 +22,35 @@
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("handleRender", function (gadget, gadget_utils, options, action_reference, parent_portal_type, form_definition) { .declareMethod("render", function (gadget) {
var child_gadget_url = 'gadget_erp5_pt_form_view_editable.html'; return gadget_utils.renderGadget(gadget);
return gadget.jio_get(options.jio_key) })
.push(function (parent_document) {
var title = parent_document.title; .declareMethod("handleRender", function (gadget, options, action_reference, form_definition) {
if (!title.startsWith('Re: ')) { title = 'Re: ' + parent_document.title; } return gadget.declareGadget("gadget_officejs_form_view.html")
return gadget.changeState({ .push(function (declared_gadget) {
doc: {title: title}, gadget_utils = declared_gadget;
parent_document: parent_document, var child_gadget_url = 'gadget_erp5_pt_form_view_editable.html';
child_gadget_url: child_gadget_url, return gadget.jio_get(options.jio_key)
form_definition: form_definition, .push(function (parent_document) {
view: action_reference, var title = parent_document.title;
editable: true, if (!title.startsWith('Re: ')) { title = 'Re: ' + parent_document.title; }
has_more_views: false, return gadget.changeState({
has_more_actions: false, doc: {title: title},
is_form_list: false 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
});
}); });
}); });
}) })
.declareMethod("handleSubmit", function (gadget, gadget_utils, jio_key, content_dict) { .declareMethod("handleSubmit", function (gadget, jio_key, content_dict) {
var document = { var document = {
my_title: gadget.state.doc.title, my_title: gadget.state.doc.title,
portal_type: gadget.state.parent_document.portal_type, portal_type: gadget.state.parent_document.portal_type,
......
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