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 */
(function (window, rJS, Query, SimpleQuery, ComplexQuery) {
(function (window, rJS, Query, SimpleQuery, ComplexQuery, console) {
"use strict";
// TODO: check if there are other categories that are 'views' and find a less hardcoded way to get this
......@@ -51,7 +51,7 @@
return [form_type, child_gadget_url];
})
.declareMethod("checkMoreActions", function (portal_type, action_category) {
.declareMethod("checkViewsAndActions", function (portal_type, action_category) {
var gadget = this,
//for now, views and actions are handle together via handle_action gadget
has_more_dict = {views: {}, actions: {}},
......@@ -89,19 +89,44 @@
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) {
var gadget = this,
all_allowed_sub_types_list = [],
allowed_sub_types_list = [],
i = 0,
query,
action_type,
action_title,
form_definition,
query_type,
query_parent,
query_reference,
pair;
query_reference;
query_reference = new SimpleQuery({
key: "reference",
operator: "",
......@@ -143,20 +168,15 @@
form_definition.title = action_title;
return gadget.getSetting("app_allowed_sub_types");
})
.push(function (allowed_sub_types) {
allowed_sub_types = allowed_sub_types.replace(/\(/g, '[')
.replace(/\)/g, ']')
.replace(/,\]/g, ']')
.replace(/\'/g, '"');
all_allowed_sub_types_list = JSON.parse(allowed_sub_types);
for (i = 0; i < all_allowed_sub_types_list.length; i++) {
pair = all_allowed_sub_types_list[i].split(" | ");
if (pair[0] === portal_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 (allowed_sub_types_setting) {
return gadget.formatSettingList(allowed_sub_types_setting, portal_type);
})
.push(function (allowed_sub_types_pairs) {
var allowed_sub_types = allowed_sub_types_pairs.map(function (pair) {
return pair[1];
});
form_definition.allowed_sub_types_list = allowed_sub_types;
return gadget.checkViewsAndActions(portal_type, action_type);
})
.push(function (has_more_dict) {
//view and actions are managed by same actions-gadget-page
......@@ -166,4 +186,4 @@
});
});
}(window, rJS, Query, SimpleQuery, ComplexQuery));
}(window, rJS, Query, SimpleQuery, ComplexQuery, console));
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.29977.52189.65245</string> </value>
<value> <string>976.31037.9424.21862</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1560786832.33</float>
<float>1560850400.9</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -84,11 +84,25 @@
});
})
.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"
var gadget = this,
action_info_dict = {views: {}, actions: {}},
query = 'portal_type: "Action Information" AND parent_relative_url: "portal_types/' + portal_type + '"';
//TODO use Query to avoid strings
query = 'portal_type: "Action Information" AND parent_relative_url: "portal_types/' + portal_type + '"',
app_actions;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.declareGadget("gadget_officejs_common_utils.html"),
gadget.getSetting('default_view_reference')
]);
})
.push(function (result_list) {
return result_list[0].getAppActions(portal_type);
})
.push(function (app_actions_result) {
app_actions = app_actions_result;
return gadget.jio_allDocs({query: query})
.push(function (action_list) {
var path_for_jio_get_list = [], row;
......@@ -106,36 +120,27 @@
//there must be one "View" action. If not, use default view (like jio_view in getsettings)
if (action_document_list.hasOwnProperty(action_key)) {
action_doc = action_document_list[action_key];
page = "handle_action";
if (view_categories.includes(action_doc.action_type)) {
page = "ojs_local_controller";
}
action_settings_list.push({
page: page,
action_settings = {
page: undefined,
jio_key: options.jio_key,
title: action_doc.title,
action: action_doc.reference,
reference: action_doc.reference,
action_type: action_doc.action_type,
parent_portal_type: portal_type
});
}
}
for (key in action_settings_list) {
if (action_settings_list.hasOwnProperty(key)) {
action_settings = action_settings_list[key];
};
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;
}
}
}
if (action_info_dict.views.hasOwnProperty("view") && action_info_dict.views.hasOwnProperty("jio_view")) {
delete action_info_dict.views.view;
}
return action_info_dict;
});
});
})
.declareMethod("render", function (options) {
......@@ -150,7 +155,7 @@
return options.portal_type;
})
.push(function (portal_type) {
return gadget.getAllActions(portal_type, options);
return gadget.getAllViewsAndActions(portal_type, options);
})
.push(function (action_info_dict) {
return RSVP.all([
......
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.29913.52.4761</string> </value>
<value> <string>976.31000.44303.9591</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1560785127.88</float>
<float>1560848207.92</float>
<string>UTC</string>
</tuple>
</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