[FIX] web: always quickcreate in the first kanban column

KanbanColumn instances are saved in an array in the renderer. The quick
create widget is always put in the first column found in this array.
Unfortunately, the array elements' order was broken after some
operations where column(s) are rerendered (like moving records).
This commit is contained in:
qsm-odoo
2017-09-15 14:32:26 +02:00
parent 74c27d81ed
commit ae7f4c0485
2 changed files with 42 additions and 3 deletions
@@ -138,10 +138,10 @@ var KanbanRenderer = BasicRenderer.extend({
* @returns {Deferred}
*/
updateColumn: function (localID, columnState) {
var column = _.findWhere(this.widgets, {db_id: localID});
this.widgets.splice(_.indexOf(this.widgets, column), 1); // remove column from widgets' list
var newColumn = new KanbanColumn(this, columnState, this.columnOptions, this.recordOptions);
this.widgets.push(newColumn);
var index = _.findIndex(this.widgets, {db_id: localID});
var column = this.widgets[index];
this.widgets[index] = newColumn;
return newColumn.insertAfter(column.$el).then(column.destroy.bind(column));
},
/**
@@ -1824,6 +1824,45 @@ QUnit.module('Views', {
"the add button should still be visible");
kanban.destroy();
});
QUnit.test('keep adding quickcreate in first column after a record from this column was moved', function (assert) {
assert.expect(2);
var kanban = createView({
View: KanbanView,
model: 'partner',
data: this.data,
arch:
'<kanban on_create="quick_create">' +
'<field name="int_field"/>' +
'<templates><t t-name="kanban-box">' +
'<div><field name="foo"/></div>' +
'</t></templates>' +
'</kanban>',
groupBy: ['int_field'],
mockRPC: function (route, args) {
if (route === '/web/dataset/resequence') {
return $.when(true);
}
return this._super(route, args);
},
});
var $quickCreateGroup;
var $groups;
_quickCreateAndTest();
testUtils.dragAndDrop($groups.first().find('.o_kanban_record:first'), $groups.eq(1));
_quickCreateAndTest();
kanban.destroy();
function _quickCreateAndTest() {
kanban.$buttons.find('.o-kanban-button-new').click();
$quickCreateGroup = kanban.$('.o_kanban_quick_create').closest('.o_kanban_group');
$groups = kanban.$('.o_kanban_group');
assert.strictEqual($quickCreateGroup[0], $groups[0],
"quick create should have been added in the first column");
}
});
});
});