diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js index 2847003f5df..c21d7a43335 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -107,6 +107,17 @@ return AbstractController.extend(FieldManagerMixin, { doIt(); } }, + /** + * Used by list and kanban views to determine whether or not to display + * the no content helper (if there is no data in the state to display) + * + * @private + * @param {Object} state + * @returns {boolean} + */ + _hasContent: function (state) { + return state.count !== 0; + }, /** * Hook method, called when record(s) has been deleted. * 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 c00cbc568d2..be288f1126d 100644 --- a/addons/web/static/src/js/views/kanban/kanban_controller.js +++ b/addons/web/static/src/js/views/kanban/kanban_controller.js @@ -104,12 +104,17 @@ var KanbanController = BasicController.extend({ this.renderer.updateRecord(this.model.get(id)); }, /** - * @todo this is dead code right now. resurrect this? + * The nocontent helper should be displayed in kanban: + * - ungrouped: if there is no records + * - grouped: if there is no groups and no column quick create * - * @returns {boolean} + * @override + * @private */ - _hasContent: function () { - return this._super.apply(this, arguments) || this.create_column_enabled; + _hasContent: function (state) { + return this._super.apply(this, arguments) || + this.create_column_enabled || + (state.groupedBy.length && state.data.length); }, /** * This method calls the server to ask for a resequence. Note that this @@ -144,7 +149,7 @@ var KanbanController = BasicController.extend({ * @returns {Deferred} */ _update: function (state) { - var hasNoContent = state.count === 0 && !this.create_column_enabled; + var hasNoContent = !this._hasContent(state); this.$el.toggleClass('o_kanban_nocontent', hasNoContent); this._toggleNoContentHelper(hasNoContent); return this._super.apply(this, arguments); diff --git a/addons/web/static/src/js/views/list/list_controller.js b/addons/web/static/src/js/views/list/list_controller.js index 2e764214459..b25b02b4513 100644 --- a/addons/web/static/src/js/views/list/list_controller.js +++ b/addons/web/static/src/js/views/list/list_controller.js @@ -200,7 +200,7 @@ var ListController = BasicController.extend({ * @returns {Deferred} */ _update: function (state) { - this._toggleNoContentHelper(state.count === 0); + this._toggleNoContentHelper(!this._hasContent(state)); this._toggleSidebar(); return this._super.apply(this, arguments); }, diff --git a/addons/web/static/test/views/kanban_tests.js b/addons/web/static/test/views/kanban_tests.js index b4d91ebdb65..7043c1690d4 100644 --- a/addons/web/static/test/views/kanban_tests.js +++ b/addons/web/static/test/views/kanban_tests.js @@ -796,6 +796,49 @@ QUnit.module('Views', { kanban.destroy(); }); + QUnit.test('no nocontent helper for grouped kanban with empty groups', function (assert) { + assert.expect(2); + + var kanban = createView({ + View: KanbanView, + model: 'partner', + data: this.data, + arch: '' + + '' + + '' + + '
' + + '
' + + '
', + groupBy: ['product_id'], + mockRPC: function (route, args) { + if (args.method === 'read_group') { + // override read_group to return empty groups, as this is + // the case for several models (e.g. project.task grouped + // by stage_id) + return this._super.apply(this, arguments).then(function (result) { + _.each(result, function (group) { + group[args.kwargs.groupby[0] + '_count'] = 0; + }); + return result; + }); + } + return this._super.apply(this, arguments); + }, + viewOptions: { + action: { + help: "No content helper", + }, + }, + }); + + assert.strictEqual(kanban.$('.o_kanban_group').length, 2, + "there should be two columns"); + assert.strictEqual(kanban.$('.o_kanban_record').length, 0, + "there should be no records"); + + kanban.destroy(); + }); + QUnit.test('buttons with modifiers', function (assert) { assert.expect(2);