From dad3e9e9283a693836c776552e8a4b47b1450b8f Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 4 Jul 2016 15:25:31 +0200 Subject: [PATCH] [FIX] web_kanban: 'create' button This commit fixes two bugs: - 'quick_create' is a special value for the on_create option, it is not an action xmlid. So when this option is set either in a ungrouped or in an empty grouped Kanban view, we should try to execute 'quick_create'. - the 'create' button is muted (btn-default instead of btn-primary) in grouped Kanban with no column. This status should be updated at each do_search, and each time a column is added/deleted. --- .../web_kanban/static/src/js/kanban_view.js | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/addons/web_kanban/static/src/js/kanban_view.js b/addons/web_kanban/static/src/js/kanban_view.js index 48cb39ad4cc..7173ffa7f1e 100644 --- a/addons/web_kanban/static/src/js/kanban_view.js +++ b/addons/web_kanban/static/src/js/kanban_view.js @@ -147,6 +147,7 @@ var KanbanView = View.extend({ self.data = data; }) .then(this.proxy('render')) + .then(this.proxy('update_buttons')) .then(this.proxy('update_pager')); }, @@ -326,7 +327,7 @@ var KanbanView = View.extend({ if (self.grouped && self.widgets.length && self.on_create === 'quick_create') { // Activate the quick create in the first column self.widgets[0].add_quick_create(); - } else if (self.on_create) { + } else if (self.on_create && self.on_create !== 'quick_create') { // Execute the given action self.do_action(self.on_create, { on_close: self.do_reload.bind(self), @@ -336,18 +337,19 @@ var KanbanView = View.extend({ self.add_record(); } }); - - // Set 'Create' button as btn-default if there is no column - if (this.grouped && this.widgets.length === 0) { - var $button_new = this.$buttons.find('.o-kanban-button-new'); - $button_new.removeClass('btn-primary').addClass('btn-default'); - this.once('new_column_added', this, function () { - $button_new.removeClass('btn-default').addClass('btn-primary'); - }); - } + this.update_buttons(); this.$buttons.appendTo($node); } }, + update_buttons: function() { + if (this.$buttons) { + // In grouped mode, set 'Create' button as btn-default if there is no column + var create_muted = !!this.grouped && this.widgets.length === 0; + this.$buttons.find('.o-kanban-button-new') + .toggleClass('btn-primary', !create_muted) + .toggleClass('btn-default', create_muted); + } + }, render_pager: function($node, options) { var self = this; @@ -639,6 +641,7 @@ var KanbanView = View.extend({ var index = self.widgets.indexOf(column); self.widgets.splice(index,1); column.destroy(); + self.update_buttons(); } else { self.do_reload(); } @@ -753,7 +756,7 @@ var KanbanView = View.extend({ var column = new KanbanColumn(self, group_data, options, record_options); column.insertBefore(self.$('.o_column_quick_create')); self.widgets.push(column); - self.trigger('new_column_added', column); + self.update_buttons(); self.trigger_up('scrollTo', {selector: '.o_column_quick_create'}); }); },