Skip to content

Commit

Permalink
[FIX] web: Kanban: quick create several records in a row
Browse files Browse the repository at this point in the history
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...).
  • Loading branch information
aab-odoo committed Jan 12, 2018
1 parent b7b38ed commit 25b101f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
12 changes: 7 additions & 5 deletions addons/web/static/src/js/views/kanban/kanban_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
}
});
});
}
},
Expand Down
12 changes: 10 additions & 2 deletions addons/web/static/src/js/views/kanban/kanban_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
52 changes: 52 additions & 0 deletions addons/web/static/tests/views/kanban_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 25b101f

Please sign in to comment.