Commit f2155f45 authored by Roque's avatar Roque

erp5_post: simplifying action gadget fields

parent 7f22d255
...@@ -8,12 +8,7 @@ ...@@ -8,12 +8,7 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Acquired methods // Acquired methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_post", "jio_post") .declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("redirect", "redirect")
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declared methods // declared methods
...@@ -22,7 +17,7 @@ ...@@ -22,7 +17,7 @@
.declareMethod("createDocument", function (options) { .declareMethod("createDocument", function (options) {
var gadget = this, var gadget = this,
doc = { doc = {
title: "Untitled Document", title: "Untitled Post",
portal_type: options.portal_type, portal_type: options.portal_type,
parent_relative_url: options.parent_relative_url parent_relative_url: options.parent_relative_url
}, },
...@@ -39,45 +34,15 @@ ...@@ -39,45 +34,15 @@
return gadget.jio_post(doc); return gadget.jio_post(doc);
}) })
.declareMethod("render", function (parent_options, action_reference, form_definition) { .declareMethod("preRenderDocument", function (parent_options) {
var gadget = this; return {title: "Untitled Post"};
return gadget.changeState({
doc: {title: "Untitled Document"},
parent_options: parent_options,
child_gadget_url: 'gadget_erp5_pt_form_dialog.html',
form_type: 'dialog',
form_definition: form_definition,
view: action_reference,
editable: true,
has_more_views: false,
has_more_actions: true
});
}) })
.onStateChange(function () { .declareMethod('handleSubmit', function (content_dict, parent_options) {
var gadget = this; var document = {
return gadget.declareGadget("gadget_officejs_form_view.html") my_title: parent_options.doc.title,
.push(function (form_view_gadget) { portal_type: parent_options.parent_options.portal_type,
return form_view_gadget.renderGadget(gadget); parent_relative_url: parent_options.parent_options.parent_relative_url
});
})
.declareMethod('triggerSubmit', function () {
return this.getDeclaredGadget('fg')
.push(function (gadget) {
return gadget.triggerSubmit();
});
})
.allowPublicAcquisition('submitContent', function (options) {
var gadget = this,
jio_key = options[0],
//target_url = options[1],
content_dict = options[2],
document = {
portal_type: gadget.state.parent_options.portal_type,
parent_relative_url: gadget.state.parent_options.parent_relative_url,
my_source_reference: gadget.state.parent_options.my_source_reference
}, property; }, property;
delete content_dict.dialog_method; delete content_dict.dialog_method;
for (property in content_dict) { for (property in content_dict) {
...@@ -85,23 +50,8 @@ ...@@ -85,23 +50,8 @@
document['my_' + property] = content_dict[property]; document['my_' + property] = content_dict[property];
} }
} }
return this.createDocument(document) document.my_source_reference = parent_options.parent_options.my_source_reference;
.push(function (id) { return this.createDocument(document);
jio_key = id;
return gadget.notifySubmitting();
})
.push(function () {
return gadget.notifySubmitted({message: 'Data Updated', status: 'success'});
})
.push(function () {
return gadget.redirect({
command: 'display',
options: {
jio_key: jio_key,
editable: true
}
});
});
}); });
}(window, rJS, RSVP)); }(window, rJS, RSVP));
\ No newline at end of file
...@@ -10,9 +10,6 @@ ...@@ -10,9 +10,6 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_post", "jio_post") .declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("redirect", "redirect")
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declared methods // declared methods
...@@ -21,7 +18,7 @@ ...@@ -21,7 +18,7 @@
.declareMethod("createDocument", function (options) { .declareMethod("createDocument", function (options) {
var gadget = this, var gadget = this,
doc = { doc = {
title: "Untitled Document", title: "Untitled Post",
portal_type: options.portal_type, portal_type: options.portal_type,
parent_relative_url: options.parent_relative_url parent_relative_url: options.parent_relative_url
}, },
...@@ -38,74 +35,31 @@ ...@@ -38,74 +35,31 @@
return gadget.jio_post(doc); return gadget.jio_post(doc);
}) })
.declareMethod("render", function (options, action_reference, form_definition) { .declareMethod("preRenderDocument", function (parent_options) {
var gadget = this; var gadget = this;
return gadget.jio_get(options.jio_key) return gadget.jio_get(parent_options.jio_key)
.push(function (parent_document) { .push(function (parent_document) {
var title = parent_document.title; var title = parent_document.title;
if (!title.startsWith('Re: ')) { title = 'Re: ' + parent_document.title; } if (!title.startsWith('Re: ')) { title = 'Re: ' + parent_document.title; }
return gadget.changeState({ return {title: title,
doc: {title: title}, source_reference: parent_document.source_reference};
parent_document: parent_document,
child_gadget_url: 'gadget_erp5_pt_form_dialog.html',
form_type: 'dialog',
form_definition: form_definition,
view: action_reference,
editable: true,
has_more_views: false,
has_more_actions: false
});
}); });
}) })
.onStateChange(function () { .declareMethod('handleSubmit', function (content_dict, parent_options) {
var gadget = this; var document = {
return gadget.declareGadget("gadget_officejs_form_view.html") my_title: parent_options.doc.title,
.push(function (form_view_gadget) { portal_type: parent_options.parent_options.portal_type,
return form_view_gadget.renderGadget(gadget); parent_relative_url: parent_options.parent_options.parent_relative_url
});
})
.declareMethod('triggerSubmit', function () {
return this.getDeclaredGadget('fg')
.push(function (gadget) {
return gadget.triggerSubmit();
});
})
.allowPublicAcquisition('submitContent', function (options) {
var gadget = this,
jio_key = options[0],
//target_url = options[1],
content_dict = options[2],
document = {
my_title: gadget.state.doc.title,
portal_type: gadget.state.parent_document.portal_type,
parent_relative_url: gadget.state.parent_document.parent_relative_url,
my_source_reference: gadget.state.parent_document.source_reference
}, property; }, property;
delete content_dict.dialog_method;
for (property in content_dict) { for (property in content_dict) {
if (content_dict.hasOwnProperty(property)) { if (content_dict.hasOwnProperty(property)) {
document['my_' + property] = content_dict[property]; document['my_' + property] = content_dict[property];
} }
} }
return this.createDocument(document) document.my_source_reference = parent_options.doc.source_reference;
.push(function (id) { return this.createDocument(document);
jio_key = id;
return gadget.notifySubmitting();
})
.push(function () {
return gadget.notifySubmitted({message: 'Data Updated', status: 'success'});
})
.push(function () {
return gadget.redirect({
command: 'display',
options: {
jio_key: jio_key,
editable: true
}
});
});
}); });
}(window, rJS, RSVP)); }(window, rJS, RSVP));
\ No newline at end of file
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