Commit c79b75a2 authored by Jérome Perrin's avatar Jérome Perrin

GUI: sort actions by priority

parent 0ba9af7d
......@@ -33,7 +33,6 @@
/////////////////////////////////////////////////////////////////
// Minimalistic ERP5's like portal type configuration
/////////////////////////////////////////////////////////////////
// XXX we should use lists instead to keep ordering
var portal_types = {
"Input Module": {
"view": {
......@@ -154,22 +153,45 @@
return new RSVP.Queue()
.push(function () {
var url_list = [],
action_item_list = [],
i,
key2;
for (key2 in portal_types[portal_type]) {
if (portal_types[portal_type].hasOwnProperty(key2)) {
action = portal_types[portal_type][key2];
if (action.type === "object_view") {
if ((action.condition === undefined) ||
(action.condition(gadget))) {
url_list.push(
calculateTabHTML(gadget, options, key2, action.title,
(key2 === options.action))
);
action_item_list.push([key2, action]);
}
}
}
}
/*
* Sort actions so that higher priorities are displayed first.
* If no priority is defined, sort by action id to have stable order.
*/
action_item_list.sort(function(a, b) {
var key_a = a[0], value_a = a[1],
key_b = b[0], value_b = b[1];
if (!isNaN(value_a.priority)) {
if (!isNaN(value_b.priority)) {
return value_b.priority - value_a.priority;
}
return -1;
}
if (!isNaN(value_b.priority)) {
return 1;
}
return key_a < key_b ? -1 : (key_a > key_b ? 1 : 0);
});
for (i=0; i<action_item_list.length; i+=1) {
url_list.push(
calculateTabHTML(gadget, options, action_item_list[i][0], action_item_list[i][1].title,
(action_item_list[i][0] === options.action))
);
}
return RSVP.all(url_list);
})
.push(function (entry_list) {
......
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