From 97ecc4bc93b7a79ded10bb2ab1d2e25242997af0 Mon Sep 17 00:00:00 2001 From: "Parth N. Patel" Date: Thu, 1 Jun 2017 12:52:51 +0530 Subject: [PATCH] [IMP] web: kanban: do not remove quick create if dirty In this commit, we improve the behaviour of quick creation in grouped kanban views. The issue was that the quick create widget was removed when the user click somewhere else, even if the user added some text. For example, the problem could be seen in the kanban view for the tasks. In this commit, we simply keep it around if there is a non empty text. --- .../static/src/js/views/kanban/kanban_column.js | 10 ++++------ addons/web/static/tests/views/kanban_tests.js | 14 +++++++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/addons/web/static/src/js/views/kanban/kanban_column.js b/addons/web/static/src/js/views/kanban/kanban_column.js index e17b77aa44f..80d48a78774 100644 --- a/addons/web/static/src/js/views/kanban/kanban_column.js +++ b/addons/web/static/src/js/views/kanban/kanban_column.js @@ -141,14 +141,12 @@ var KanbanColumn = Widget.extend({ return; } var self = this; - this.quickCreateWidget = new RecordQuickCreate(this, { - width: this.records.length ? this.records[0].$el.innerWidth() : this.$el.width() - 8, - defaultName: this.data.getContext().default_name, - }); + var width = this.records.length ? this.records[0].$el.innerWidth() : this.$el.width() - 8; + this.quickCreateWidget = new RecordQuickCreate(this, width); this.quickCreateWidget.insertAfter(this.$header); this.quickCreateWidget.$el.focusout(function () { - var hasFocus = (self.quickCreateWidget.$(':focus').length > 0); - if (! hasFocus && self.quickCreateWidget) { + var taskName = self.quickCreateWidget.$('[type=text]')[0].value; + if (!taskName && self.quickCreateWidget) { self._cancelQuickCreate(); } }); diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index b2b84ff00d5..8fa1fc6d2d5 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -323,7 +323,7 @@ QUnit.module('Views', { }); QUnit.test('quick create in grouped mode', function (assert) { - assert.expect(6); + assert.expect(8); var nbRecords = 4; var kanban = createView({ @@ -354,10 +354,22 @@ QUnit.module('Views', { assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 0, "should have destroyed the quick create element"); + //click to add and element and focus out the blank input, should cancel the quick creation + kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); + $quickCreate = kanban.$('.o_kanban_quick_create'); + $quickCreate.find('input').blur(); + assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 0, + "Blur should have destroyed the quick create element"); + // click to really add an element kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); $quickCreate = kanban.$('.o_kanban_quick_create'); $quickCreate.find('input').val('new partner'); + $quickCreate.find('input').blur(); + + // When focus out the input containing value, should not delete the Quick Creation + assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + "Blur should not have destroyed the quick create element"); nbRecords = 5; $quickCreate.find('button.o_kanban_add').click();