From af2686fee55b20d74ce1799aea84bf1910b20051 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 4 Jan 2018 10:02:48 +0100 Subject: [PATCH] [IMP] web: Kanban: cancel column quick create on ESC Record quick create can be cancelled by pressing ESC, so this rev. ensures that the same behavior applies for the column quick create, for the sake of consistency. --- .../js/views/kanban/kanban_quick_create.js | 13 +++++-- addons/web/static/tests/views/kanban_tests.js | 39 ++++++++++++++++++- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/addons/web/static/src/js/views/kanban/kanban_quick_create.js b/addons/web/static/src/js/views/kanban/kanban_quick_create.js index 216cf1bbe88..9c317552329 100644 --- a/addons/web/static/src/js/views/kanban/kanban_quick_create.js +++ b/addons/web/static/src/js/views/kanban/kanban_quick_create.js @@ -266,6 +266,15 @@ var ColumnQuickCreate = AbstractQuickCreate.extend({ // Private //-------------------------------------------------------------------------- + /** + * @override + * @private + */ + _cancel: function () { + this.folded = true; + this.$input.val(''); + this._update(); + }, /** * Triggers up an event to quick create a column with the given value * @@ -298,9 +307,7 @@ var ColumnQuickCreate = AbstractQuickCreate.extend({ if (hasFocus) { return; } - this.folded = true; - this.$input.val(''); - this._update(); + this._cancel(); }, /** * Stops the propagation of the event to prevent the quick create from diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index f003bba199c..d4054e9f7af 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -1,7 +1,6 @@ odoo.define('web.kanban_tests', function (require) { "use strict"; -var core = require('web.core'); var KanbanColumnProgressBar = require('web.KanbanColumnProgressBar'); var KanbanRenderer = require('web.KanbanRenderer'); var KanbanView = require('web.KanbanView'); @@ -9,7 +8,6 @@ var testUtils = require('web.test_utils'); var Widget = require('web.Widget'); var widgetRegistry = require('web.widget_registry'); -var createAsyncView = testUtils.createAsyncView; var createView = testUtils.createView; QUnit.module('Views', { @@ -1425,6 +1423,43 @@ QUnit.module('Views', { kanban.destroy(); }); + QUnit.test('cancel column quick create by pressing ESCAPE', function (assert) { + assert.expect(4); + + var kanban = createView({ + View: KanbanView, + model: 'partner', + data: this.data, + arch: '' + + '' + + '' + + '
' + + '
' + + '
', + groupBy: ['product_id'], + }); + + assert.strictEqual(kanban.$('.o_column_quick_create').length, 1, "should have a quick create column"); + assert.notOk(kanban.$('.o_column_quick_create input').is(':visible'), + "the input should not be visible"); + + kanban.$('.o_column_quick_create').click(); + + assert.ok(kanban.$('.o_column_quick_create input').is(':visible'), + "the input should be visible"); + + // discard the column creation by pressing ESCAPE + kanban.$('.o_column_quick_create input').trigger($.Event('keydown', { + keyCode: $.ui.keyCode.ESCAPE, + which: $.ui.keyCode.ESCAPE, + })); + + assert.notOk(kanban.$('.o_column_quick_create input').is(':visible'), + "the input should not be visible anymore"); + + kanban.destroy(); + }); + QUnit.test('if view was grouped at start, it stays grouped', function (assert) { assert.expect(1);