Skip to content
Snippets Groups Projects
Commit 2a43803d authored by Xavier Morel's avatar Xavier Morel
Browse files

[FIX] web_kanban: column & item quick-creation

In all browsers the ``focus/blur`` event is triggered before a button's
``click`` (it's actually triggered by mousedown).

Column and record quick-creates discard the form on blur but still want
to create the column/record when the "Add" button is clicked. This was
implementing with a fixed debounce/time-delay on the blur handler,
however the exact delay between blur and click dispatch are browser,
environment and possibly load-dependent (on my system unloaded, 10ms is
sufficient in webkit but firefox requires at least 50, a user keeping
the mouse button pressed for some time would increase that delay).

The proper way to handle this is to suppress the ``focus/blur`` event
from the relevant button entirely by preventing the browser's default
mousedown handler.

Do that for both column and record quick-creates, and remove
time-delay/debounces.

Also remove manual proxying of ``click`` in kanban column (move to
``events`` object)
parent 9882c882
Branches
Tags
No related merge requests found
......@@ -240,12 +240,10 @@ var KanbanColumn = Widget.extend({
this.quick_create_widget = new RecordQuickCreate(this, width);
this.quick_create_widget.insertAfter(this.$header);
this.quick_create_widget.$el.focusout(function () {
setTimeout(function() {
var hasFocus = !! (self.quick_create_widget.$(':focus').length > 0);
if (! hasFocus && self.quick_create_widget) {
self.cancel_quick_create();
}
}, 10);
var hasFocus = (self.quick_create_widget.$(':focus').length > 0);
if (! hasFocus && self.quick_create_widget) {
self.cancel_quick_create();
}
});
},
......
......@@ -7,8 +7,12 @@ var RecordQuickCreate = Widget.extend({
template: "KanbanView.QuickCreate",
events: {
'click .o_kanban_cancel': 'cancel',
'click .o_kanban_add': 'add_record',
'click .o_kanban_cancel': function (event) {
this.cancel();
},
'click .o_kanban_add': function (event) {
this.add_record();
},
'keypress input': function (event) {
if (event.keyCode === 13) {
this.add_record();
......@@ -16,9 +20,11 @@ var RecordQuickCreate = Widget.extend({
},
'keydown': function (event) {
if (event.keyCode === 27) {
this.trigger_up('cancel_quick_create');
this.cancel();
}
},
'mousedown .o_kanban_add': 'suppress',
'mousedown .o_kanban_cancel': 'suppress',
},
init: function (parent, width) {
......@@ -43,16 +49,24 @@ var RecordQuickCreate = Widget.extend({
this.trigger_up('quick_create_add_record', {value: value});
this.$input.focus();
},
suppress: function (e) {
e.preventDefault();
},
});
var ColumnQuickCreate = Widget.extend({
template: 'KanbanView.ColumnQuickCreate',
events: {
'click': 'toggle',
'click .o_kanban_add': function (event) {
event.stopPropagation();
this.add_column();
},
'click .o_kanban_cancel': function (event) {
this.folded = true;
this.update();
},
'click .o_kanban_quick_create': function (event) {
event.stopPropagation();
},
......@@ -61,16 +75,22 @@ var ColumnQuickCreate = Widget.extend({
this.add_column();
}
},
'click .o_kanban_cancel': function (event) {
this.folded = true;
this.update();
},
'keydown': function (event) {
if (event.keyCode === 27) {
this.folded = true;
this.update();
}
},
'focusout': function () {
var hasFocus = this.$(':focus').length > 0;
if (hasFocus) { return; }
this.folded = true;
this.$input.val('');
this.update();
},
'mousedown .o_kanban_add': 'suppress',
'mousedown .o_kanban_cancel': 'suppress',
},
init: function (parent) {
......@@ -82,17 +102,6 @@ var ColumnQuickCreate = Widget.extend({
this.$header = this.$('.o_column_header');
this.$quick_create = this.$('.o_kanban_quick_create');
this.$input = this.$('input');
this.$el.click(this.proxy('toggle'));
var self = this;
this.$el.focusout(function () {
setTimeout(function() {
var hasFocus = !! (self.$(':focus').length > 0);
if (! hasFocus) {
self.folded = true;
self.update();
}
}, 10);
});
},
toggle: function () {
......@@ -115,7 +124,10 @@ var ColumnQuickCreate = Widget.extend({
if (/^\s*$/.test(name)) { return; }
this.trigger_up('quick_create_add_column', {value: name});
this.$input.focus();
}
},
suppress: function (e) {
e.preventDefault();
},
});
return {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment