From d6152f8b82ae1a707f2fff7846d12cb9ce901f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 22 Oct 2015 11:41:16 +0200 Subject: [PATCH] Add toolbar with reload to board review15781002 --- src/board.js | 5 +++++ src/tab.js | 56 ++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/board.js b/src/board.js index 7d33102c2c..78ee68e5ca 100644 --- a/src/board.js +++ b/src/board.js @@ -166,6 +166,11 @@ action = new Sao.View.Board.Action(attributes, this.context); this.actions.push(action); container.add(attributes, action); + }, + reload: function() { + for (var i = 0; i < this.actions.length; i++) { + this.actions[i].display(); + } } }); diff --git a/src/tab.js b/src/tab.js index b5b07c2d09..863596914f 100644 --- a/src/tab.js +++ b/src/tab.js @@ -28,23 +28,24 @@ var icon = definition[0]; var name = definition[1]; var func = definition[2]; - if (!func) { - return; - } var item = jQuery('
  • ', { 'role': 'presentation' - }).append(jQuery('', { + }).appendTo(menu); + var link = jQuery('', { 'role': 'menuitem', 'href': '#', 'tabindex': -1 }).append(jQuery('', { 'class': 'glyphicon ' + icon, 'aria-hidden': 'true' - })).append(' ' + name)); - menu.append(item); - item.click(function() { - this[func](); - }.bind(this)); + })).append(' ' + name).appendTo(item); + if (func) { + link.click(function() { + this[func](); + }.bind(this)); + } else { + item.addClass('disabled'); + } }.bind(this)); }, create_toolbar: function() { @@ -87,6 +88,9 @@ this.set_menu(toolbar.find('ul[role*="menu"]')); var add_button = function(tool) { + var item = jQuery('
  • ', { + 'role': 'presentation' + }).appendTo(toolbar.find('.navbar-collapse > ul')); this.buttons[tool[0]] = jQuery('', { 'role': 'menuitem', 'href': '#', @@ -99,10 +103,12 @@ .append(jQuery('', { 'class': 'hidden-sm' }).append(' ' + tool[2])) - .click(this[tool[4]].bind(this)) - .appendTo(jQuery('
  • ', { - 'role': 'presentation' - }).appendTo(toolbar.find('.navbar-collapse > ul'))); + .appendTo(item); + if (tool[4]) { + this.buttons[tool[0]].click(this[tool[4]].bind(this)); + } else { + item.addClass('disabled'); + } // TODO tooltip }; this.toolbar_def.forEach(add_button.bind(this)); @@ -736,8 +742,28 @@ this.set_name(this.name); this.title.html(this.name_el.text()); }, - create_toolbar: function() { - return jQuery(''); + toolbar_def: [ + ['new', 'glyphicon-edit', + Sao.i18n.gettext('New'), + Sao.i18n.gettext('Create a new record'), null], + ['save', 'glyphicon-save', + Sao.i18n.gettext('Save'), + Sao.i18n.gettext('Save this record'), null], + ['switch', 'glyphicon-list-alt', + Sao.i18n.gettext('Switch'), + Sao.i18n.gettext('Switch view'), null], + ['reload', 'glyphicon-refresh', + Sao.i18n.gettext('Reload'), + Sao.i18n.gettext('Reload'), 'reload'] + ], + menu_def: [ + ['glyphicon-edit', Sao.i18n.gettext('New'), null], + ['glyphicon-save', Sao.i18n.gettext('Save'), null], + ['glyphicon-list-alt', Sao.i18n.gettext('Switch'), null], + ['glyphicon-refresh', Sao.i18n.gettext('Reload/Undo'), 'reload'] + ], + reload: function() { + this.board.reload(); }, record_message: function() { var i, len;