[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.
This commit is contained in:
Parth N. Patel
2017-06-01 09:22:51 +02:00
committed by ged-odoo
parent f0a6bb6ce3
commit 97ecc4bc93
2 changed files with 17 additions and 7 deletions
@@ -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();
}
});
+13 -1
View File
@@ -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();