Commit b6b986a0 authored by Roque's avatar Roque

erp5_officejs: refactoring in action pages

parent ee2cfb59
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("createDocument", function (options) { .declareMethod("createDocument", function (options) {
var gadget = this, var gadget = this,
doc = { doc = {
...@@ -113,8 +114,8 @@ ...@@ -113,8 +114,8 @@
form_definition._links.action_object_new_content_action = { form_definition._links.action_object_new_content_action = {
page: "handle_action", page: "handle_action",
title: "New Post", title: "New Post",
action: "new", action: "new_html_post",
reference: "new", reference: "new_html_post",
action_type: "object_jio_js_script", action_type: "object_jio_js_script",
parent_portal_type: "Post Module", parent_portal_type: "Post Module",
portal_type: "HTML Post", portal_type: "HTML Post",
......
...@@ -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.39168.2243.39099</string> </value> <value> <string>975.39669.47531.23961</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>1557426063.79</float> <float>1557436424.93</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -55,30 +55,32 @@ ...@@ -55,30 +55,32 @@
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("getActionSettings", function (action_doc, portal_type) { .declareMethod("getHTMLElements", function (element_list) {
var gadget = this, page = "handle_action", action_settings = {}; var gadget = this,
if (view_categories.includes(action_doc.action_type)) { i = 0,
page = "ojs_controller"; element_info_list = [],
url_for_parameter_list = [],
element_info;
for (var key in element_list) {
if (element_list.hasOwnProperty(key)) {
element_info = element_list[key];
url_for_parameter_list.push({ command: 'change', options: element_info });
element_info_list[i] = { reference: element_info.reference, title: element_info.title};
i += 1;
}
} }
action_settings = { return gadget.getUrlForList(url_for_parameter_list)
page: page, .push(function (url_list) {
title: action_doc.title, var html_element_list = [], i, element;
action: action_doc.reference, for (i = 0; i < url_list.length; i += 1) {
reference: action_doc.reference, element = { href: url_list[i],
action_type: action_doc.action_type, icon: null,
parent_portal_type: portal_type, name: element_info_list[i].reference,
portal_type: portal_type title: element_info_list[i].title };
}; html_element_list.push(element);
//TODO find a better way to handle "add" actions (how to get child portal type?) }
//'parent' and 'child' portal_types will be in the custom code of action gadgets return html_element_list;
if (action_doc.reference === "new") {
return gadget.getSetting('portal_type')
.push(function (child_portal_type) {
action_settings.portal_type = child_portal_type;
return action_settings;
}); });
}
return action_settings;
}) })
.declareMethod("getAllActions", function (portal_type, action_category) { .declareMethod("getAllActions", function (portal_type, action_category) {
...@@ -96,15 +98,31 @@ ...@@ -96,15 +98,31 @@
return RSVP.all(path_for_jio_get_list); return RSVP.all(path_for_jio_get_list);
}) })
.push(function (action_document_list) { .push(function (action_document_list) {
var get_action_settings_list = [], page, action_key, action_doc; var action_settings_list = [], page, action_key, action_doc;
for (action_key in action_document_list) { for (action_key in action_document_list) {
if (action_document_list.hasOwnProperty(action_key)) { if (action_document_list.hasOwnProperty(action_key)) {
get_action_settings_list.push(gadget.getActionSettings(action_document_list[action_key], portal_type)); action_doc = action_document_list[action_key];
page = "handle_action";
if (view_categories.includes(action_doc.action_type)) {
page = "ojs_controller";
}
//TODO (how to get child portal type?)
//'parent' and 'child' portal_types will be in the custom code of action gadgets
var child_portal_type = portal_type;
if (action_doc.reference === "new_html_post") {
child_portal_type = "HTML Post";
}
action_settings_list.push({
page: page,
title: action_doc.title,
action: action_doc.reference,
reference: action_doc.reference,
action_type: action_doc.action_type,
parent_portal_type: portal_type,
portal_type: child_portal_type
});
} }
} }
return RSVP.all(get_action_settings_list);
})
.push(function (action_settings_list) {
for (var key in action_settings_list) { for (var key in action_settings_list) {
if (action_settings_list.hasOwnProperty(key)) { if (action_settings_list.hasOwnProperty(key)) {
var action_settings = action_settings_list[key]; var action_settings = action_settings_list[key];
...@@ -127,57 +145,29 @@ ...@@ -127,57 +145,29 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
url_for_parameter_list = [],
action_info_list = [],
action_info_dict = {},
document_title; document_title;
return gadget.jio_get(options.jio_key) return gadget.jio_get(options.jio_key)
.push(function (document) { .push(function (document) {
document_title = document.title; document_title = document.title;
return gadget.getAllActions(document.portal_type, view_categories[0]); return document.portal_type;
}, function (error) { }, function (error) {
document_title = options.portal_type; document_title = options.portal_type;
return gadget.getAllActions(options.portal_type, view_categories[0]); return options.portal_type;
}) })
.push(function (all_actions) { .push(function (portal_type) {
var action_info, i = 0; return gadget.getAllActions(portal_type, view_categories[0]);
action_info_dict = all_actions; })
//TODO refactor this (actions and views) .push(function (action_info_dict) {
for (var action_key in action_info_dict.actions) { return RSVP.all([
if (action_info_dict.actions.hasOwnProperty(action_key)) { gadget.getHTMLElements(action_info_dict.views),
action_info = action_info_dict.actions[action_key]; gadget.getHTMLElements(action_info_dict.actions)
url_for_parameter_list.push({ command: 'change', options: action_info }); ]);
action_info_list[i] = { reference: action_info.reference, title: action_info.title};
i += 1;
}
}
for (var view_key in action_info_dict.views) {
if (action_info_dict.views.hasOwnProperty(view_key)) {
action_info = action_info_dict.views[view_key];
url_for_parameter_list.push({ command: 'change', options: action_info });
action_info_list[i] = { reference: action_info.reference, title: action_info.title};
i += 1;
}
}
return gadget.getUrlForList(url_for_parameter_list);
}) })
.push(function (url_list) {
var action_list = [], view_list = [], i, element;
for (i = 0; i < url_list.length; i += 1) {
element = { href: url_list[i],
icon: null,
name: action_info_list[i].reference,
title: action_info_list[i].title };
if (action_info_dict.views.hasOwnProperty(element.name)) {
view_list.push(element);
} else {
action_list.push(element);
}
}
// TODO: check other lists like clone or delete? // TODO: check other lists like clone or delete?
.push(function (all_html_elements) {
return RSVP.all([ return RSVP.all([
renderLinkList(gadget, "Views", "eye", view_list), renderLinkList(gadget, "Views", "eye", all_html_elements[0]),
renderLinkList(gadget, "Actions", "gear", action_list) renderLinkList(gadget, "Actions", "gear", all_html_elements[1])
]); ]);
}) })
.push(function (translated_html_link_list) { .push(function (translated_html_link_list) {
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>975.38143.43945.1706</string> </value> <value> <string>975.39646.60719.8601</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1557344637.28</float> <float>1557436194.5</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
}) })
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, action_reference, valid_action; var gadget = this, action_reference;
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
...@@ -78,14 +78,24 @@ ...@@ -78,14 +78,24 @@
return gadget.getActionFormDefinition(action_reference); return gadget.getActionFormDefinition(action_reference);
}) })
.push(function (form_definition) { .push(function (form_definition) {
valid_action = form_definition.action_type === "object_jio_js_script" &&
form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script");
var fragment = document.createElement('div'), var fragment = document.createElement('div'),
action_gadget_url = form_definition.fields_raw_properties.gadget_field_action_js_script.values.gadget_url, action_gadget_url,
form_info = getFormInfo(form_definition), form_info = getFormInfo(form_definition),
form_type = form_info[0], form_type = form_info[0],
child_gadget_url = form_info[1]; child_gadget_url = form_info[1],
valid_action = form_definition.action_type === "object_jio_js_script" &&
form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script"),
state_options = {
doc: {},
parent_options: options,
child_gadget_url: child_gadget_url,
form_type: form_type,
form_definition: form_definition,
view: action_reference,
valid_action: valid_action
};
if (valid_action) { if (valid_action) {
action_gadget_url = form_definition.fields_raw_properties.gadget_field_action_js_script.values.gadget_url;
gadget.element.appendChild(fragment); gadget.element.appendChild(fragment);
return gadget.declareGadget(action_gadget_url, { return gadget.declareGadget(action_gadget_url, {
scope: "action_field", scope: "action_field",
...@@ -95,27 +105,11 @@ ...@@ -95,27 +105,11 @@
return action_gadget.preRenderDocument(options); return action_gadget.preRenderDocument(options);
}) })
.push(function (doc) { .push(function (doc) {
return gadget.changeState({ state_options.doc = doc;
doc: doc, return gadget.changeState(state_options);
parent_options: options,
child_gadget_url: child_gadget_url,
form_type: form_type,
form_definition: form_definition,
view: action_reference,
valid_action: valid_action
});
}); });
} else { } else {
//TODO refactor this to avoid 2 calls almost identical return gadget.changeState(state_options);
return gadget.changeState({
doc: {},
parent_options: options,
child_gadget_url: child_gadget_url,
form_type: form_type,
form_definition: form_definition,
view: action_reference,
valid_action: valid_action
});
} }
}); });
}) })
......
...@@ -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.39483.32712.34679</string> </value> <value> <string>975.39668.29926.39628</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>1557425011.91</float> <float>1557436203.22</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