[FIX] web: grouped Kanban: don't display nocontent helper

When the kanban is grouped and its groups contain no record, the
nocontent helper shouldn't be displayed. This wasn't the case
before this rev.
This commit is contained in:
Aaron Bohy
2017-04-11 19:44:38 +02:00
parent b3015960c1
commit 6bad524bb3
4 changed files with 65 additions and 6 deletions
@@ -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.
*
@@ -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);
@@ -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);
},
@@ -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: '<kanban>' +
'<field name="product_id"/>' +
'<templates><t t-name="kanban-box">' +
'<div><field name="foo"/></div>' +
'</t></templates>' +
'</kanban>',
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);