summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2019-09-12 09:01:28 +0000
committerJulien Mougenot <jum@odoo.com>2019-09-18 08:24:13 +0000
commita7782cadbec5e3a73b3d2fb7791b2c4b06c8a545 (patch)
tree14e48a7a14917a40a6f5584db4d83e9e1a635085 /addons/web/static
parentaf65475a4cd33ca8c6b25ba525d2f59cc28b3f43 (diff)
[FIX] web: lists: focus last edited cell
Gave back focus to the last edited cell to increase usability with key nav. Before this commit, after saving several records with multi edition in a list, focus was lost (given to the body). Now, last edited cell is given back the focus after multi editing.
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/src/js/views/list/list_controller.js20
-rw-r--r--addons/web/static/src/js/views/list/list_editable_renderer.js11
-rw-r--r--addons/web/static/tests/views/list_tests.js6
3 files changed, 31 insertions, 6 deletions
diff --git a/addons/web/static/src/js/views/list/list_controller.js b/addons/web/static/src/js/views/list/list_controller.js
index bd0322c92b0..f99ec19dea7 100644
--- a/addons/web/static/src/js/views/list/list_controller.js
+++ b/addons/web/static/src/js/views/list/list_controller.js
@@ -396,6 +396,7 @@ var ListController = BasicController.extend({
var nbInvalid = recordIds.length - validRecordIds.length;
return new Promise(function (resolve, reject) {
+ var dialog;
var rejectAndDiscard = function () {
self.model.discardChanges(recordId);
return self._confirmSave(recordId).then(reject);
@@ -411,24 +412,33 @@ var ListController = BasicController.extend({
_t("Do you want to set the value on the %d valid selected records? (%d invalid)"),
validRecordIds.length, nbInvalid);
}
- Dialog.confirm(self, message, {
+ dialog = Dialog.confirm(self, message, {
confirm_callback: function () {
- self.model.saveRecords(recordId, validRecordIds, fieldName)
+ return self.model.saveRecords(recordId, validRecordIds, fieldName)
.then(function () {
self._updateButtons('readonly');
var state = self.model.get(self.handle);
- self.renderer.updateState(state, {});
- resolve(Object.keys(changes));
+ return self.renderer.updateState(state, {}).then(function () {
+ resolve(Object.keys(changes));
+ });
})
.guardedCatch(rejectAndDiscard);
},
cancel_callback: rejectAndDiscard,
});
} else {
- Dialog.alert(self, _t("No valid record to save"), {
+ dialog = Dialog.alert(self, _t("No valid record to save"), {
confirm_callback: rejectAndDiscard,
});
}
+ dialog.on('closed', self, function () {
+ // we need to wait for the dialog to be actually closed, but
+ // the 'closed' event is triggered just before, and it prevents
+ // from focussing the cell
+ Promise.resolve().then(function () {
+ self.renderer.focusCell(recordId, node);
+ });
+ });
});
},
/**
diff --git a/addons/web/static/src/js/views/list/list_editable_renderer.js b/addons/web/static/src/js/views/list/list_editable_renderer.js
index cd67feb0b34..b23b7a85e0a 100644
--- a/addons/web/static/src/js/views/list/list_editable_renderer.js
+++ b/addons/web/static/src/js/views/list/list_editable_renderer.js
@@ -277,6 +277,17 @@ ListRenderer.include({
this._selectCell(rowIndex, 0);
},
/**
+ * Gives focus to a specific cell, given its row and its related column.
+ *
+ * @param {string} recordId
+ * @param {Object} column
+ */
+ focusCell: function (recordId, column) {
+ var $row = this._getRow(recordId);
+ var cellIndex = this.columns.indexOf(column);
+ $row.find('.o_data_cell')[cellIndex].focus();
+ },
+ /**
* Returns the recordID associated to the line which is currently in edition
* or null if there is no line in edition.
*
diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js
index ba61d49b78b..94f6ced9fc4 100644
--- a/addons/web/static/tests/views/list_tests.js
+++ b/addons/web/static/tests/views/list_tests.js
@@ -4480,7 +4480,7 @@ QUnit.module('Views', {
});
QUnit.test('editable list view: multi edition', async function (assert) {
- assert.expect(22);
+ assert.expect(24);
var list = await createView({
View: ListView,
@@ -4536,6 +4536,8 @@ QUnit.module('Views', {
await testUtils.dom.click($('.modal .btn:contains(Cancel)'));
assert.strictEqual(list.$('.o_data_row:eq(0) .o_data_cell').text(), 'yop10',
"changes have been discarded and row is back to readonly");
+ assert.strictEqual(document.activeElement, list.$('.o_data_row:eq(0) .o_data_cell:eq(1)')[0],
+ "focus should be given to the most recently edited cell after discard");
await testUtils.dom.click(list.$('.o_data_row:eq(0) .o_data_cell:eq(1)'));
await testUtils.fields.editInput(list.$('.o_field_widget[name=int_field]'), 666);
await testUtils.dom.click(list.$('.o_data_row:eq(1) .o_data_cell:eq(0)'));
@@ -4548,6 +4550,8 @@ QUnit.module('Views', {
assert.strictEqual(list.$('.o_data_row:eq(1) .o_data_cell').text(), "blip666",
"the second row should be updated");
assert.containsNone(list, '.o_data_cell input.o_field_widget', "no field should be editable anymore");
+ assert.strictEqual(document.activeElement, list.$('.o_data_row:eq(0) .o_data_cell:eq(1)')[0],
+ "focus should be given to the most recently edited cell after confirm");
list.destroy();
});