Commit 783a5a4a authored by Roque's avatar Roque

erp5_officejs: refactoring; using new layout configuration fields

parent 4a5cd2a1
/*global window, rJS, Query, SimpleQuery, ComplexQuery */ /*global window, rJS, Query, SimpleQuery, ComplexQuery, console */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, Query, SimpleQuery, ComplexQuery) { (function (window, rJS, Query, SimpleQuery, ComplexQuery, console) {
"use strict"; "use strict";
// TODO: check if there are other categories that are 'views' and find a less hardcoded way to get this // TODO: check if there are other categories that are 'views' and find a less hardcoded way to get this
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
return [form_type, child_gadget_url]; return [form_type, child_gadget_url];
}) })
.declareMethod("checkMoreActions", function (portal_type, action_category) { .declareMethod("checkViewsAndActions", function (portal_type, action_category) {
var gadget = this, var gadget = this,
//for now, views and actions are handle together via handle_action gadget //for now, views and actions are handle together via handle_action gadget
has_more_dict = {views: {}, actions: {}}, has_more_dict = {views: {}, actions: {}},
...@@ -89,19 +89,44 @@ ...@@ -89,19 +89,44 @@
return has_more_dict; return has_more_dict;
}) })
.declareMethod("formatSettingList", function (configuration_list_string, portal_type) {
var i = 0, formatted_list = [], configuration_list, pair;
try {
configuration_list_string = configuration_list_string.replace(/\(/g, '[')
.replace(/\)/g, ']')
.replace(/,\]/g, ']')
.replace(/\'/g, '"');
configuration_list = JSON.parse(configuration_list_string);
for (i = 0; i < configuration_list.length; i += 1) {
pair = configuration_list[i].split(" | ");
if (!portal_type || pair[0] === portal_type) {
formatted_list.push(pair);
}
}
} catch (e) {
console.log("Error while parsing configuration settings. Format error maybe?");
console.log(e);
}
return formatted_list;
})
.declareMethod("getAppActions", function (portal_type) {
var gadget = this;
return gadget.getSetting('app_actions')
.push(function (app_actions_setting) {
return gadget.formatSettingList(app_actions_setting, portal_type);
});
})
.declareMethod("getFormDefinition", function (portal_type, action_reference) { .declareMethod("getFormDefinition", function (portal_type, action_reference) {
var gadget = this, var gadget = this,
all_allowed_sub_types_list = [],
allowed_sub_types_list = [],
i = 0,
query, query,
action_type, action_type,
action_title, action_title,
form_definition, form_definition,
query_type, query_type,
query_parent, query_parent,
query_reference, query_reference;
pair;
query_reference = new SimpleQuery({ query_reference = new SimpleQuery({
key: "reference", key: "reference",
operator: "", operator: "",
...@@ -143,20 +168,15 @@ ...@@ -143,20 +168,15 @@
form_definition.title = action_title; form_definition.title = action_title;
return gadget.getSetting("app_allowed_sub_types"); return gadget.getSetting("app_allowed_sub_types");
}) })
.push(function (allowed_sub_types) { .push(function (allowed_sub_types_setting) {
allowed_sub_types = allowed_sub_types.replace(/\(/g, '[') return gadget.formatSettingList(allowed_sub_types_setting, portal_type);
.replace(/\)/g, ']') })
.replace(/,\]/g, ']') .push(function (allowed_sub_types_pairs) {
.replace(/\'/g, '"'); var allowed_sub_types = allowed_sub_types_pairs.map(function (pair) {
all_allowed_sub_types_list = JSON.parse(allowed_sub_types); return pair[1];
for (i = 0; i < all_allowed_sub_types_list.length; i++) { });
pair = all_allowed_sub_types_list[i].split(" | "); form_definition.allowed_sub_types_list = allowed_sub_types;
if (pair[0] === portal_type) { return gadget.checkViewsAndActions(portal_type, action_type);
allowed_sub_types_list.push(pair[1]);
}
}
form_definition.allowed_sub_types_list = allowed_sub_types_list;
return gadget.checkMoreActions(portal_type, action_type);
}) })
.push(function (has_more_dict) { .push(function (has_more_dict) {
//view and actions are managed by same actions-gadget-page //view and actions are managed by same actions-gadget-page
...@@ -166,4 +186,4 @@ ...@@ -166,4 +186,4 @@
}); });
}); });
}(window, rJS, Query, SimpleQuery, ComplexQuery)); }(window, rJS, Query, SimpleQuery, ComplexQuery, console));
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>976.29977.52189.65245</string> </value> <value> <string>976.31037.9424.21862</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>1560786832.33</float> <float>1560850400.9</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -84,57 +84,62 @@ ...@@ -84,57 +84,62 @@
}); });
}) })
.declareMethod("getAllActions", function (portal_type, options) { .declareMethod("getAllViewsAndActions", function (portal_type, options) {
//TODO for now this takes also views. Views should be handle in another gadget like "..tab_office.js" //TODO for now this takes also views. Views should be handle in another gadget like "..tab_office.js"
var gadget = this, var gadget = this,
action_info_dict = {views: {}, actions: {}}, action_info_dict = {views: {}, actions: {}},
query = 'portal_type: "Action Information" AND parent_relative_url: "portal_types/' + portal_type + '"'; //TODO use Query to avoid strings
return gadget.jio_allDocs({query: query}) query = 'portal_type: "Action Information" AND parent_relative_url: "portal_types/' + portal_type + '"',
.push(function (action_list) { app_actions;
var path_for_jio_get_list = [], row; return RSVP.Queue()
for (row in action_list.data.rows) { .push(function () {
if (action_list.data.rows.hasOwnProperty(row)) { return RSVP.all([
path_for_jio_get_list.push(gadget.jio_get(action_list.data.rows[row].id)); gadget.declareGadget("gadget_officejs_common_utils.html"),
} gadget.getSetting('default_view_reference')
} ]);
return RSVP.all(path_for_jio_get_list); })
.push(function (result_list) {
return result_list[0].getAppActions(portal_type);
}) })
.push(function (action_document_list) { .push(function (app_actions_result) {
var action_settings_list = [], page, action_key, action_doc, key, action_settings; app_actions = app_actions_result;
for (action_key in action_document_list) { return gadget.jio_allDocs({query: query})
//TODO filter actions: discard actions that are not in getSettings("app_actions") .push(function (action_list) {
//there must be one "View" action. If not, use default view (like jio_view in getsettings) var path_for_jio_get_list = [], row;
if (action_document_list.hasOwnProperty(action_key)) { for (row in action_list.data.rows) {
action_doc = action_document_list[action_key]; if (action_list.data.rows.hasOwnProperty(row)) {
page = "handle_action"; path_for_jio_get_list.push(gadget.jio_get(action_list.data.rows[row].id));
if (view_categories.includes(action_doc.action_type)) { }
page = "ojs_local_controller";
} }
action_settings_list.push({ return RSVP.all(path_for_jio_get_list);
page: page, })
jio_key: options.jio_key, .push(function (action_document_list) {
title: action_doc.title, var action_settings_list = [], page, action_key, action_doc, key, action_settings;
action: action_doc.reference, for (action_key in action_document_list) {
reference: action_doc.reference, //TODO filter actions: discard actions that are not in getSettings("app_actions")
action_type: action_doc.action_type, //there must be one "View" action. If not, use default view (like jio_view in getsettings)
parent_portal_type: portal_type if (action_document_list.hasOwnProperty(action_key)) {
}); action_doc = action_document_list[action_key];
} action_settings = {
} page: undefined,
for (key in action_settings_list) { jio_key: options.jio_key,
if (action_settings_list.hasOwnProperty(key)) { title: action_doc.title,
action_settings = action_settings_list[key]; action: action_doc.reference,
if (view_categories.includes(action_settings.action_type)) { reference: action_doc.reference,
action_info_dict.views[action_settings.action] = action_settings; action_type: action_doc.action_type,
} else { parent_portal_type: portal_type
action_info_dict.actions[action_settings.action] = action_settings; };
if (view_categories.includes(action_settings.action_type)) {
action_settings.page = "ojs_local_controller";
action_info_dict.views[action_settings.action] = action_settings;
} else {
action_settings.page = "handle_action";
action_info_dict.actions[action_settings.action] = action_settings;
}
}
} }
} return action_info_dict;
} });
if (action_info_dict.views.hasOwnProperty("view") && action_info_dict.views.hasOwnProperty("jio_view")) {
delete action_info_dict.views.view;
}
return action_info_dict;
}); });
}) })
...@@ -150,7 +155,7 @@ ...@@ -150,7 +155,7 @@
return options.portal_type; return options.portal_type;
}) })
.push(function (portal_type) { .push(function (portal_type) {
return gadget.getAllActions(portal_type, options); return gadget.getAllViewsAndActions(portal_type, options);
}) })
.push(function (action_info_dict) { .push(function (action_info_dict) {
return RSVP.all([ return RSVP.all([
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>976.29913.52.4761</string> </value> <value> <string>976.31000.44303.9591</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>1560785127.88</float> <float>1560848207.92</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