Commit 3f82e201 authored by Roque's avatar Roque

erp5_post: refactoring on action gadgets

parent c7a632f1
...@@ -14,44 +14,27 @@ ...@@ -14,44 +14,27 @@
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("createDocument", function (options) {
var gadget = this,
doc = {
title: "Untitled Post",
portal_type: options.portal_type,
parent_relative_url: options.parent_relative_url
},
key,
doc_key;
for (key in options) {
if (options.hasOwnProperty(key)) {
if (key.startsWith("my_")) {
doc_key = key.replace("my_", "");
doc[doc_key] = options[key];
}
}
}
return gadget.jio_post(doc);
})
.declareMethod("preRenderDocument", function (parent_options) { .declareMethod("preRenderDocument", function (parent_options) {
return {title: "Untitled Post"}; return {title: "Untitled Post"};
}) })
.declareMethod('handleSubmit', function (content_dict, parent_options) { .declareMethod('handleSubmit', function (content_dict, parent_options) {
var document = { var gadget = this,
my_title: parent_options.doc.title, document = {
portal_type: parent_options.parent_options.portal_type, title: parent_options.doc.title,
parent_relative_url: parent_options.parent_options.parent_relative_url //hardcoded portal_type and relative url (because this action is 'new HTML Post' on 'post_module')
}, property; //or, we can get those values from parent_options.form_definition if needed
portal_type: "HTML Post",
parent_relative_url: "post_module"
}, property;
delete content_dict.dialog_method; 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[property] = content_dict[property];
} }
} }
document.my_source_reference = parent_options.parent_options.my_source_reference; document.source_reference = parent_options.action_options.source_reference;
return this.createDocument(document); return gadget.jio_post(document);
}); });
}(window, rJS, RSVP)); }(window, rJS, RSVP));
\ No newline at end of file
...@@ -15,51 +15,32 @@ ...@@ -15,51 +15,32 @@
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("createDocument", function (options) {
var gadget = this,
doc = {
title: "Untitled Post",
portal_type: options.portal_type,
parent_relative_url: options.parent_relative_url
},
key,
doc_key;
for (key in options) {
if (options.hasOwnProperty(key)) {
if (key.startsWith("my_")) {
doc_key = key.replace("my_", "");
doc[doc_key] = options[key];
}
}
}
return gadget.jio_post(doc);
})
.declareMethod("preRenderDocument", function (parent_options) { .declareMethod("preRenderDocument", function (parent_options) {
var gadget = this; var gadget = this;
return gadget.jio_get(parent_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 {title: title, return {
source_reference: parent_document.source_reference}; title: title,
parent_relative_url: parent_document.parent_relative_url,
portal_type: parent_document.portal_type,
source_reference: parent_document.source_reference
};
}); });
}) })
.declareMethod('handleSubmit', function (content_dict, parent_options) { .declareMethod('handleSubmit', function (content_dict, parent_options) {
var document = { var gadget = this,
my_title: parent_options.doc.title, document = parent_options.doc,
portal_type: parent_options.parent_options.portal_type, property;
parent_relative_url: parent_options.parent_options.parent_relative_url
}, property;
delete content_dict.dialog_method; 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[property] = content_dict[property];
} }
} }
document.my_source_reference = parent_options.doc.source_reference; return gadget.jio_post(document);
return this.createDocument(document);
}); });
}(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