[FIX] web: kanban card do correct action on ENTER key

When the focus is on a kanban card that do not have
oe_kanban_global_click or oe_kanban_global_click_edit when hitting the
ENTER key,
before this fix, the default action was to open the record of the card
after this fix, the action executed will be the action of the first
button or link of the card

if the card has the oe_kanban_global_click or
oe_kanban_global_click_edit class, the record still opens with ENTER key
This commit is contained in:
Vincent Schippefilt
2018-05-02 14:49:23 +02:00
parent 3628014abd
commit 7cf68c838b
2 changed files with 55 additions and 3 deletions
@@ -23,7 +23,6 @@ var KanbanRecord = Widget.extend({
events: {
'click .oe_kanban_action': '_onKanbanActionClicked',
'click .o_kanban_manage_toggle_button': '_onManageTogglerClicked',
'keydown' : '_onKanbanKeyDown',
},
/**
* @override
@@ -289,6 +288,9 @@ var KanbanRecord = Widget.extend({
if (this.$el.hasClass('oe_kanban_global_click') ||
this.$el.hasClass('oe_kanban_global_click_edit')) {
this.$el.on('click', this._onGlobalClick.bind(this));
this.$el.on('keydown', this._onKeyDownCard.bind(this));
} else {
this.$el.on('keydown', this._onKeyDownOpenFirstLink.bind(this));
}
this._processFields();
this._processWidgets();
@@ -505,11 +507,33 @@ var KanbanRecord = Widget.extend({
this.do_warn("Kanban: no action for type : " + type);
}
},
_onKanbanKeyDown: function (event) {
/**
* This event is linked to the kanban card when there is a global_click
* class on this card
*
* @private
* @param {KeyDownEvent} event
*/
_onKeyDownCard: function (event) {
switch (event.keyCode) {
case $.ui.keyCode.ENTER:
event.preventDefault();
this._openRecord();
this._onGlobalClick(event);
break;
}
},
/**
* This event is linked ot the kanban card when there is no global_click
* class on the card
*
* @private
* @param {KeyDownEvent} event
*/
_onKeyDownOpenFirstLink: function (event) {
switch (event.keyCode) {
case $.ui.keyCode.ENTER:
event.preventDefault();
$(event.target).find('a, button').first().click();
break;
}
},
@@ -3587,6 +3587,34 @@ QUnit.module('Views', {
kanban.destroy();
});
QUnit.test('keyboard navigation on kanban when the focus is on a link that' +
'has an action and the kanban has no oe_kanban_global_... class', function(assert){
assert.expect(1)
var kanban = createView({
View: KanbanView,
model: 'partner',
data: this.data,
arch: '<kanban class="o_kanban_test"><templates><t t-name="kanban-box">' +
'<div><a type="edit">Edit</a></div>' +
'</t></templates></kanban>',
});
testUtils.intercept(kanban, 'switch_view', function (event) {
assert.deepEqual(event.data, {
view_type: 'form',
res_id: 1,
mode: 'edit',
model: 'partner',
},'When selecting focusing a card and hitting ENTER, the first link or button is clicked');
});
kanban.$('.o_kanban_record').first().focus().trigger($.Event('keydown', {
keyCode: $.ui.keyCode.ENTER,
which: $.ui.keyCode.ENTER,
}));
kanban.destroy();
});
});
});