[FIX] web: Kanban: quick create several records in a row
Before this rev., when quick creating a record in a grouped kanban
view, the quick create widget wasn't automatically re-opened, which
didn't allow the user to quickly create several records in a row
(without clicking each time on the '+').
This desired behavior had been broken by rev. 1d34e26, which aimed
to properly reload the kanban column when a record was created
(e.g. column counter, progress bar...).
This commit is contained in:
@@ -355,11 +355,13 @@ var KanbanController = BasicController.extend({
|
||||
self._updateEnv();
|
||||
|
||||
var columnState = self.model.getColumn(db_id);
|
||||
return self.renderer.updateColumn(columnState.id, columnState).then(function () {
|
||||
if (event.data.openRecord) {
|
||||
self.trigger_up('open_record', {id: db_id, mode: 'edit'});
|
||||
}
|
||||
});
|
||||
return self.renderer
|
||||
.updateColumn(columnState.id, columnState, {openQuickCreate: true})
|
||||
.then(function () {
|
||||
if (event.data.openRecord) {
|
||||
self.trigger_up('open_record', {id: db_id, mode: 'edit'});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@@ -141,15 +141,23 @@ var KanbanRenderer = BasicRenderer.extend({
|
||||
*
|
||||
* @param {string} localID the column id
|
||||
* @param {Object} columnState
|
||||
* @param {Object} [options]
|
||||
* @param {boolean} [options.openQuickCreate] if true, directly opens the
|
||||
* QuickCreate widget in the updated column
|
||||
*
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
updateColumn: function (localID, columnState) {
|
||||
updateColumn: function (localID, columnState, options) {
|
||||
var newColumn = new KanbanColumn(this, columnState, this.columnOptions, this.recordOptions);
|
||||
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));
|
||||
return newColumn.insertAfter(column.$el).then(function () {
|
||||
if (options && options.openQuickCreate) {
|
||||
newColumn.addQuickCreate();
|
||||
}
|
||||
column.destroy();
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Updates a given record with its new state.
|
||||
|
||||
@@ -493,6 +493,58 @@ QUnit.module('Views', {
|
||||
kanban.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('quick create several records in a row', function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
var kanban = createView({
|
||||
View: KanbanView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<kanban class="o_kanban_test" on_create="quick_create">' +
|
||||
'<field name="bar"/>' +
|
||||
'<templates><t t-name="kanban-box">' +
|
||||
'<div><field name="foo"/></div>' +
|
||||
'</t></templates></kanban>',
|
||||
groupBy: ['bar'],
|
||||
});
|
||||
|
||||
assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1,
|
||||
"first column should contain one record");
|
||||
|
||||
// click to add an element, fill the input and press ENTER
|
||||
kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click();
|
||||
|
||||
assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1,
|
||||
"the quick create should be open");
|
||||
|
||||
kanban.$('.o_kanban_quick_create input')
|
||||
.val('new partner 1')
|
||||
.trigger($.Event('keypress', {
|
||||
which: $.ui.keyCode.ENTER,
|
||||
keyCode: $.ui.keyCode.ENTER,
|
||||
}));
|
||||
|
||||
assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2,
|
||||
"first column should now contain two records");
|
||||
assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1,
|
||||
"the quick create should still be open");
|
||||
|
||||
// create a second element in a row
|
||||
kanban.$('.o_kanban_quick_create input')
|
||||
.val('new partner 2')
|
||||
.trigger($.Event('keypress', {
|
||||
which: $.ui.keyCode.ENTER,
|
||||
keyCode: $.ui.keyCode.ENTER,
|
||||
}));
|
||||
|
||||
assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 3,
|
||||
"first column should now contain three records");
|
||||
assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1,
|
||||
"the quick create should still be open");
|
||||
|
||||
kanban.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('quick create fail in grouped', function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user