[IMP] web: Kanban: hide Create button if no column yet

Onboarding process: the user has to create a column first.

Part of task #38740
This commit is contained in:
Aaron Bohy
2018-01-26 19:26:03 +01:00
parent 6ea347a490
commit 563c31fe49
2 changed files with 20 additions and 24 deletions
@@ -39,8 +39,6 @@ var KanbanController = BasicController.extend({
this.on_create = params.on_create;
this.hasButtons = params.hasButtons;
this.createColumnEnabled = this._isCreateColumnEnabled();
},
//--------------------------------------------------------------------------
@@ -58,15 +56,6 @@ var KanbanController = BasicController.extend({
this.$buttons.appendTo($node);
}
},
/**
* Override update method to recompute createColumnEnabled.
*
* @returns {Deferred}
*/
update: function () {
this.createColumnEnabled = this._isCreateColumnEnabled();
return this._super.apply(this, arguments);
},
//--------------------------------------------------------------------------
// Private
@@ -92,18 +81,18 @@ var KanbanController = BasicController.extend({
* m2o field and group_create action enabled.
*
* @private
* @param {Object} state the current state
* @returns {boolean}
*/
_isCreateColumnEnabled: function () {
_isCreateColumnEnabled: function (state) {
var groupCreate = this.is_action_enabled('group_create');
if (!groupCreate) {
// pre-return to avoid a lot of the following processing
return false;
}
var state = this.model.get(this.handle, {raw: true});
var groupByField = state.fields[state.groupedBy[0]];
var groupedByM2o = groupByField && (groupByField.type === 'many2one');
return groupedByM2o;
return !!groupedByM2o;
},
/**
* This method calls the server to ask for a resequence. Note that this
@@ -121,6 +110,16 @@ var KanbanController = BasicController.extend({
self._updateEnv();
});
},
/**
* Overrides to update the control panel buttons when the state is updated.
*
* @override
* @private
*/
_update: function () {
this._updateButtons();
return this._super.apply(this, arguments);
},
/**
* In grouped mode, set 'Create' button as btn-default if there is no column
* (except if we can't create new columns)
@@ -130,12 +129,9 @@ var KanbanController = BasicController.extend({
*/
_updateButtons: function () {
if (this.$buttons) {
var data = this.model.get(this.handle, {raw: true});
var grouped = data.groupedBy.length;
var createMuted = grouped && data.data.length === 0 && this.createColumnEnabled;
this.$buttons.find('.o-kanban-button-new')
.toggleClass('btn-primary', !createMuted)
.toggleClass('btn-default', createMuted);
var state = this.model.get(this.handle, {raw: true});
var createHidden = state.data.length === 0 && this._isCreateColumnEnabled(state);
this.$buttons.find('.o-kanban-button-new').toggleClass('o_hidden', createHidden);
}
},
@@ -2545,15 +2545,15 @@ QUnit.module('Views', {
groupBy: ['product_id'],
});
assert.ok(kanban.$buttons.find('.o-kanban-button-new').hasClass('btn-default'),
"Create button shouldn't be highlighted");
assert.ok(kanban.$buttons.find('.o-kanban-button-new').hasClass('o_hidden'),
"Create button should be hidden");
kanban.$('.o_column_quick_create').click();
kanban.$('.o_column_quick_create input').val('new column');
kanban.$('.o_column_quick_create button.o_kanban_add').click();
assert.ok(kanban.$buttons.find('.o-kanban-button-new').hasClass('btn-primary'),
"Create button should now be highlighted");
assert.notOk(kanban.$buttons.find('.o-kanban-button-new').hasClass('o_hidden'),
"Create button should now be visible");
kanban.destroy();
});