Commit 51333e0a authored by Roque's avatar Roque

erp5_officejs: getting views and actions methods are moved to utils

parent 57f15fc6
/*global window, rJS, Query, SimpleQuery, ComplexQuery, console */
/*global window, rJS, RSVP, Query, SimpleQuery, ComplexQuery, console */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, Query, SimpleQuery, ComplexQuery, console) {
(function (window, rJS, RSVP, 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
var view_categories = ["object_view", "object_jio_view", "object_web_view", "object_list"];
function filterViews(views_dict, app_view, default_view) {
// there must be only one "View" action (title = "View")
// this is for scenarios were the portal type has several "View" (like view, jio_view, custom_view)
// priority: app_view ; default_view ; other
var only_view, key,
view_list = Object.keys(views_dict).map(function (key) {
if (views_dict[key].title === "View") { return key; }
});
if (view_list.includes(app_view)) {
only_view = app_view;
} else if (view_list.includes(default_view)) {
only_view = default_view;
} else {
only_view = view_list[0];
}
for (key in view_list) {
if (view_list[key] !== only_view) {
delete views_dict[view_list[key]];
}
}
return views_dict;
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
......@@ -27,6 +50,71 @@
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("getAllViewsAndActions", function (portal_type, jio_key) {
var gadget = this,
action_info_dict = {views: {}, actions: {}},
//TODO use Query to avoid strings
query = 'portal_type: "Action Information" AND parent_relative_url: "portal_types/' + portal_type + '"',
app_actions,
app_view,
default_view;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting('app_view_reference'),
gadget.getSetting('default_view_reference')
]);
})
.push(function (result_list) {
app_view = result_list[0];
default_view = result_list[1];
return gadget.getAppActions(portal_type);
})
.push(function (app_actions_result) {
app_actions = app_actions_result.map(function (pair) {
return pair[1];
});
return gadget.jio_allDocs({query: query})
.push(function (action_list) {
var path_for_jio_get_list = [], row;
for (row in action_list.data.rows) {
if (action_list.data.rows.hasOwnProperty(row)) {
path_for_jio_get_list.push(gadget.jio_get(action_list.data.rows[row].id));
}
}
return RSVP.all(path_for_jio_get_list);
})
.push(function (action_document_list) {
var page, action_key, action_doc, key, action_settings;
for (action_key in action_document_list) {
if (action_document_list.hasOwnProperty(action_key)) {
action_doc = action_document_list[action_key];
if (app_actions.includes(action_doc.reference)) {
action_settings = {
page: undefined,
jio_key: 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
};
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;
}
}
}
}
action_info_dict.views = filterViews(action_info_dict.views, app_view, default_view);
return action_info_dict;
});
});
})
.declareMethod("getFormInfo", function (form_definition) {
var child_gadget_url,
form_type,
......@@ -176,6 +264,7 @@
return pair[1];
});
form_definition.allowed_sub_types_list = allowed_sub_types;
//TODO get rid of checkViewsAndActions and use getAllViewsAndActions result instead
return gadget.checkViewsAndActions(portal_type, action_type);
})
.push(function (has_more_dict) {
......@@ -186,4 +275,4 @@
});
});
}(window, rJS, Query, SimpleQuery, ComplexQuery, console));
}(window, rJS, RSVP, Query, SimpleQuery, ComplexQuery, console));
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.31037.9424.21862</string> </value>
<value> <string>976.32545.23324.47257</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1560850400.9</float>
<float>1560944910.22</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -38,29 +38,6 @@
);
}
function filterViews(views_dict, app_view, default_view) {
// there must be only one "View" action (title = "View")
// this is for scenarios were the portal type has several "View" (like view, jio_view, custom_view)
// priority: app_view ; default_view ; other
var only_view, key,
view_list = Object.keys(views_dict).map(function (key) {
if (views_dict[key].title === "View") { return key; }
});
if (view_list.includes(app_view)) {
only_view = app_view;
} else if (view_list.includes(default_view)) {
only_view = default_view;
} else {
only_view = view_list[0];
}
for (key in view_list) {
if (view_list[key] !== only_view) {
delete views_dict[view_list[key]];
}
}
return views_dict;
}
gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
......@@ -107,76 +84,9 @@
});
})
.declareMethod("getAllViewsAndActions", function (portal_type, options) {
// TODO views are also listed here
// should views be handled in another gadget like "..tab_office.js" ?
var gadget = this,
action_info_dict = {views: {}, actions: {}},
//TODO use Query to avoid strings
query = 'portal_type: "Action Information" AND parent_relative_url: "portal_types/' + portal_type + '"',
app_actions,
app_view,
default_view;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.declareGadget("gadget_officejs_common_utils.html"),
gadget.getSetting('app_view_reference'),
gadget.getSetting('default_view_reference')
]);
})
.push(function (result_list) {
app_view = result_list[1];
default_view = result_list[2];
return result_list[0].getAppActions(portal_type);
})
.push(function (app_actions_result) {
app_actions = app_actions_result.map(function (pair) {
return pair[1];
});
return gadget.jio_allDocs({query: query})
.push(function (action_list) {
var path_for_jio_get_list = [], row;
for (row in action_list.data.rows) {
if (action_list.data.rows.hasOwnProperty(row)) {
path_for_jio_get_list.push(gadget.jio_get(action_list.data.rows[row].id));
}
}
return RSVP.all(path_for_jio_get_list);
})
.push(function (action_document_list) {
var page, action_key, action_doc, key, action_settings;
for (action_key in action_document_list) {
if (action_document_list.hasOwnProperty(action_key)) {
action_doc = action_document_list[action_key];
if (app_actions.includes(action_doc.reference)) {
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
};
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;
}
}
}
}
action_info_dict.views = filterViews(action_info_dict.views, app_view, default_view);
return action_info_dict;
});
});
})
.declareMethod("render", function (options) {
var gadget = this,
portal_type,
document_title;
return gadget.jio_get(options.jio_key)
.push(function (document) {
......@@ -186,8 +96,14 @@
document_title = options.portal_type;
return options.portal_type;
})
.push(function (portal_type) {
return gadget.getAllViewsAndActions(portal_type, options);
.push(function (result) {
portal_type = result;
return gadget.declareGadget("gadget_officejs_common_utils.html");
})
.push(function (gadget_utils) {
// TODO views are also listed here
// should views be handled in another gadget like "..tab_office.js" ?
return gadget_utils.getAllViewsAndActions(portal_type, options.jio_key);
})
.push(function (action_info_dict) {
return RSVP.all([
......
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.32499.44430.52411</string> </value>
<value> <string>976.32543.31646.51592</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1560938148.99</float>
<float>1560940816.44</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