diff --git a/CHANGELOG b/CHANGELOG index 54058eac51..2ac0e89986 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Update states of both toolbar and menu +* Improve toolbar order * Use login details in title Version 4.4.0 - 2017-05-01 diff --git a/src/tab.js b/src/tab.js index 19b153b116..45acf27b35 100644 --- a/src/tab.js +++ b/src/tab.js @@ -7,10 +7,101 @@ init: function() { Sao.Tab.tabs.push(this); this.buttons = {}; + this.menu_buttons = {}; this.id = 'tab-' + Sao.Tab.counter++; this.name = ''; this.name_el = jQuery(''); }, + menu_def: function() { + return [ + { + id: 'switch_', + icon: 'glyphicon-list-alt', + label: Sao.i18n.gettext('Switch'), + tooltip: Sao.i18n.gettext('Switch view'), + }, { + id: 'previous', + icon: 'glyphicon-chevron-left', + label: Sao.i18n.gettext('Previous'), + tooltip: Sao.i18n.gettext('Previous Record') + }, { + id: 'next', + icon: 'glyphicon-chevron-right', + label: Sao.i18n.gettext('Next'), + tooltip: Sao.i18n.gettext('Next Record'), + }, { + id: 'search', + icon: 'glyphicon-search', + label: Sao.i18n.gettext('Search'), + }, null, { + id: 'new_', + icon: 'glyphicon-edit', + label: Sao.i18n.gettext('New'), + tooltip: Sao.i18n.gettext('Create a new record'), + }, { + id: 'save', + icon: 'glyphicon-save', + label: Sao.i18n.gettext('Save'), + tooltip: Sao.i18n.gettext('Save this record'), + }, { + id: 'reload', + icon: 'glyphicon-refresh', + label: Sao.i18n.gettext('Reload/Undo'), + tooltip: Sao.i18n.gettext('Reload'), + }, { + id: 'copy', + icon: 'glyphicon-duplicate', + label: Sao.i18n.gettext('Duplicate'), + }, { + id: 'delete_', + icon: 'glyphicon-trash', + label: Sao.i18n.gettext('Delete'), + }, null, { + id: 'logs', + icon: 'glyphicon-time', + label: Sao.i18n.gettext('View Logs...'), + }, { + id: Sao.common.MODELHISTORY.contains(this.screen.model_name) ? + 'revision': null, + icon: 'glyphicon-time', + label: Sao.i18n.gettext('Show revisions...'), + }, null, { + id: 'attach', + icon: 'glyphicon-paperclip', + label: Sao.i18n.gettext('Attachment'), + tooltip: Sao.i18n.gettext('Add an attachment to the record'), + }, { + id: 'note', + icon: 'glyphicon-comment', + label: Sao.i18n.gettext('Note'), + tooltip: Sao.i18n.gettext('Add a note to the record'), + }, { + id: 'action', + icon: 'glyphicon-cog', + label: Sao.i18n.gettext('Action'), + }, null, { + id: 'relate', + icon: 'glyphicon-share-alt', + label: Sao.i18n.gettext('Relate'), + }, { + id: 'print', + icon: 'glyphicon-print', + label: Sao.i18n.gettext('Print'), + }, null, { + id: 'export', + icon: 'glyphicon-export', + label: Sao.i18n.gettext('Export'), + }, { + id: 'import', + icon: 'glyphicon-import', + label: Sao.i18n.gettext('Import'), + }, null, { + id: 'close', + icon: 'glyphicon-remove', + label: Sao.i18n.gettext('Close Tab'), + }, + ]; + }, create_tabcontent: function() { this.el = jQuery('
', { 'class': this.class_ @@ -26,28 +117,38 @@ } }, set_menu: function(menu) { - this.menu_def().forEach(function(definition) { - var icon = definition[0]; - var name = definition[1]; - var func = definition[2]; - var item = jQuery('
  • ', { - 'role': 'presentation' - }).appendTo(menu); - var link = jQuery('', { - 'role': 'menuitem', - 'href': '#', - 'tabindex': -1 - }).append(jQuery('', { - 'class': 'glyphicon ' + icon, - 'aria-hidden': 'true' - })).append(' ' + name).appendTo(item); - if (func) { + var previous; + this.menu_def().forEach(function(item) { + var menuitem; + if (item) { + if (!this[item.id]) { + return; + } + menuitem = jQuery('
  • ', { + 'role': 'presentation' + }); + var link = jQuery('', { + 'role': 'menuitem', + 'href': '#', + 'tabindex': -1 + }).append(jQuery('', { + 'class': 'glyphicon ' + item.icon, + 'aria-hidden': 'true' + })).append(' ' + item.label).appendTo(menuitem); + this.menu_buttons[item.id] = menuitem; link.click(function() { - this[func](); + this[item.id](); }.bind(this)); + } else if (!item && previous) { + menuitem = jQuery('
  • ', { + 'role': 'separator', + 'class': 'divider', + }); } else { - item.addClass('disabled'); + return; } + previous = menuitem; + menuitem.appendTo(menu); }.bind(this)); }, create_toolbar: function() { @@ -90,38 +191,37 @@ this.set_menu(toolbar.find('ul[role*="menu"]')); var group; - var add_button = function(tool) { - if (!tool) { + var add_button = function(item) { + if (!item || !item.tooltip) { group = null; return; } + if (!item.id) { + return; + } if (!group) { group = jQuery('
    ', { 'class': 'btn-group', 'role': 'group' }).appendTo(toolbar.find('.btn-toolbar')); } - this.buttons[tool[0]] = jQuery('