diff options
| author | Martin Geubelle <mge@odoo.com> | 2017-04-28 11:48:09 +0200 |
|---|---|---|
| committer | Martin Geubelle <mge@odoo.com> | 2017-05-04 11:58:26 +0200 |
| commit | b84137c67f181b6324bf1b90fd828ef4b40a41ea (patch) | |
| tree | d3e9d00d060229f06e4c1e28f668b573535613a6 /addons/web/static/src | |
| parent | 0bc70b64a9dda8aa22aabebf1cb9859f7d8d1de3 (diff) | |
[FIX] web: Kanban: deal with `group_create` attribute
This attribute is used to determine one can create a new column in
the kanban view.
Before this commit, it was always true and not specified in the
controller `activeActions` (which was causing a bug where the
no content helper was displayed instead of the column quick create).
The controller was also always initiated with false so the column was
only available after an update.
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/views/kanban/kanban_controller.js | 32 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/kanban/kanban_view.js | 3 |
2 files changed, 24 insertions, 11 deletions
diff --git a/addons/web/static/src/js/views/kanban/kanban_controller.js b/addons/web/static/src/js/views/kanban/kanban_controller.js index 9bb728011e8..cbe31e5938f 100644 --- a/addons/web/static/src/js/views/kanban/kanban_controller.js +++ b/addons/web/static/src/js/views/kanban/kanban_controller.js @@ -40,8 +40,7 @@ var KanbanController = BasicController.extend({ this.on_create = params.on_create; this.hasButtons = params.hasButtons; - // true iff grouped by an m2o field and group_create action enabled - this.create_column_enabled = false; + this.createColumnEnabled = this._isCreateColumnEnabled(); }, //-------------------------------------------------------------------------- @@ -60,16 +59,12 @@ var KanbanController = BasicController.extend({ } }, /** - * Override update method to recompute create_column_enabled. + * Override update method to recompute createColumnEnabled. * * @returns {Deferred} */ update: function () { - var state = this.model.get(this.handle, {raw: true}); - var group_by_field = state.fields[state.groupedBy[0]]; - var grouped_by_m2o = group_by_field && (group_by_field.type === 'many2one'); - var groupCreate = this.is_action_enabled('group_create'); - this.create_column_enabled = grouped_by_m2o && groupCreate; + this.createColumnEnabled = this._isCreateColumnEnabled(); return this._super.apply(this, arguments); }, @@ -95,10 +90,27 @@ var KanbanController = BasicController.extend({ */ _hasContent: function (state) { return this._super.apply(this, arguments) || - this.create_column_enabled || + this.createColumnEnabled || (state.groupedBy.length && state.data.length); }, /** + * The column quick create should be displayed in kanban iff grouped by an + * m2o field and group_create action enabled. + * + * @returns {Boolean} + */ + _isCreateColumnEnabled: function () { + 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; + }, + /** * This method calls the server to ask for a resequence. Note that this * does not rerender the user interface, because in most case, the * resequencing operation has already been displayed by the renderer. @@ -119,7 +131,7 @@ var KanbanController = BasicController.extend({ _updateButtons: function () { if (this.$buttons) { var data = this.model.get(this.handle, {raw: true}); - var create_muted = data.count === 0 && this.create_column_enabled; + var create_muted = data.count === 0 && this.createColumnEnabled; this.$buttons.find('.o-kanban-button-new') .toggleClass('btn-primary', !create_muted) .toggleClass('btn-default', create_muted); diff --git a/addons/web/static/src/js/views/kanban/kanban_view.js b/addons/web/static/src/js/views/kanban/kanban_view.js index 190647037d5..55a90e83242 100644 --- a/addons/web/static/src/js/views/kanban/kanban_view.js +++ b/addons/web/static/src/js/views/kanban/kanban_view.js @@ -34,6 +34,7 @@ var KanbanView = BasicView.extend({ var activeActions = this.controllerParams.activeActions; activeActions = _.extend(activeActions, { + group_create: arch.attrs.group_create ? JSON.parse(arch.attrs.group_create) : true, group_edit: arch.attrs.group_edit ? JSON.parse(arch.attrs.group_edit) : true, group_delete: arch.attrs.group_delete ? JSON.parse(arch.attrs.group_delete) : true, }); @@ -41,7 +42,7 @@ var KanbanView = BasicView.extend({ this.rendererParams.column_options = { editable: activeActions.group_edit, deletable: activeActions.group_delete, - group_creatable: true, + group_creatable: activeActions.group_create, quick_create: params.isQuickCreateEnabled || this._isQuickCreateEnabled(viewInfo), }; this.rendererParams.record_options = { |
