From: Thomas Berezansky <tsbere@mvlc.org> Date: Mon, 5 Mar 2012 21:14:43 +0000 (-0500) Subject: Add locale-aware menu sort, use it for admin menu X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a7243f4497ddcb42c39188e6c82c879020e95eff;p=evergreen%2Fmasslnc.git Add locale-aware menu sort, use it for admin menu Sort function can do recursive sorting and is menuseparator aware, sorting within blocks defined by menuseparators. Note: If a menu item has forceFirst set as an attribute it will be put in front of the current sort group. So far this is only used to keep the operator change menu item at the top of the admin menu. Signed-off-by: Thomas Berezansky <tsbere@mvlc.org> Signed-off-by: Jason Etheridge <jason@esilibrary.com> --- diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu.js b/Open-ILS/xul/staff_client/chrome/content/main/menu.js index e84ffac01e..bc1e8342c6 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/menu.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/menu.js @@ -1696,6 +1696,9 @@ main.menu.prototype = { obj.controller.view.tabs = window.document.getElementById('main_tabs'); obj.controller.view.panels = window.document.getElementById('main_panels'); obj.controller.view.tabscroller = window.document.getElementById('main_tabs_scrollbox'); + + obj.sort_menu(document.getElementById('main.menu.admin'), true); + if(params['firstURL']) { obj.new_tab(params['firstURL'],{'focus':true},null); } @@ -2465,6 +2468,45 @@ commands: return "user_false"; }, + 'sort_menu' : function(menu, recurse) { + var curgroup = new Array(); + var curstart = 1; + var curordinal = 0; + for (var itemid = 0; itemid < menu.firstChild.children.length; itemid++) { + var item = menu.firstChild.children[itemid]; + curordinal++; + if (item.getAttribute('forceFirst')) { + item.setAttribute('ordinal', curstart); + curstart++; + continue; + } + if (item.nodeName == 'menuseparator') { + this.sort_menu_items(curgroup, curstart); + item.setAttribute('ordinal', curordinal); + curstart = curordinal + 1; + curgroup = new Array(); + continue; + } + if (item.nodeName == 'menu' && recurse) { + this.sort_menu(item, recurse); + } + curgroup.push(item); + } + this.sort_menu_items(curgroup, curstart); + }, + + 'sort_menu_items' : function(itemgroup, start) { + var curpos = start; + var sorted = itemgroup.sort(function(a,b) { + var labelA = a.getAttribute('label').toUpperCase(); + var labelB = b.getAttribute('label').toUpperCase(); + return labelA.localeCompare(labelB); + }); + for(var item = 0; item < sorted.length; item++) { + sorted[item].setAttribute('ordinal', curpos++); + } + }, + 'observe' : function(subject, topic, data) { if (topic != "nsPref:changed") { return; diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul b/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul index c12c2455fc..3b37a625b9 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul +++ b/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul @@ -424,7 +424,7 @@ <menu id="main.menu.admin" label="&staff.main.menu.admin.label;" accesskey="&staff.main.menu.admin.accesskey;"> <menupopup id="main.menu.admin.popup"> <menuitem id="oc_menuitem" label="&staff.main.menu.admin.change_session.label;" label_orig="&staff.main.menu.admin.change_session.label;" - accesskey="O" command="cmd_change_session"/> + accesskey="O" command="cmd_change_session" forceFirst="true"/> <menuitem label="&staff.main.menu.admin.offline_xacts.label;" accesskey="&staff.main.menu.admin.offline_xacts.accesskey;" command="cmd_manage_offline_xacts"/> <menuitem label="&staff.main.menu.admin.download_patrons.label;" accesskey="&staff.main.menu.admin.download_patrons.accesskey;" command="cmd_download_patrons"/> <menuseparator />