[IMP] keep focus in the same column when navigating to the previous/next record with up/down arrows

bzr revid: xmo@openerp.com-20120724135655-hjk2l0mxvncker4q
This commit is contained in:
Xavier Morel 2012-07-24 15:56:55 +02:00
parent d6ef80f21e
commit 35bb49701c
2 changed files with 36 additions and 17 deletions

View File

@ -202,6 +202,8 @@ openerp.web.list_editable = function (instance) {
return; return;
} }
// FIXME: need better way to get the field back from bubbling (delegated) DOM events somehow
field.$element.attr('data-fieldname', field_name);
self.fields_for_resize.push({field: field, cell: cell}); self.fields_for_resize.push({field: field, cell: cell});
}, options).pipe(function () { }, options).pipe(function () {
$recordRow.addClass('oe_edition'); $recordRow.addClass('oe_edition');
@ -399,18 +401,20 @@ openerp.web.list_editable = function (instance) {
* *
* @private * @private
* @param {String} [next_record='succ'] method to call on the records collection to get the next record to edit * @param {String} [next_record='succ'] method to call on the records collection to get the next record to edit
* @param {Object} [options]
* @param {String} [options.focus_field]
* @return {*} * @return {*}
*/ */
_next: function (next_record) { _next: function (next_record, options) {
next_record = next_record || 'succ'; next_record = next_record || 'succ';
var self = this; var self = this;
return this.save_edition().pipe(function (saveInfo) { return this.save_edition().pipe(function (saveInfo) {
if (saveInfo.created) { if (saveInfo.created) {
return self.start_edition(); return self.start_edition();
} }
return self.start_edition( var record = self.records[next_record](
self.records[next_record]( saveInfo.record, {wraparound: true});
saveInfo.record, {wraparound: true})); return self.start_edition(record, options);
}); });
}, },
keyup_ENTER: function () { keyup_ENTER: function () {
@ -440,25 +444,34 @@ openerp.web.list_editable = function (instance) {
} }
return selection.start; return selection.start;
}, },
keydown_UP: function (e) { /**
* @param DOMEvent event
* @param {String} record_direction direction to move into to get the next record (pred | succ)
* @param {Function} is_valid_move whether the edition should be moved to the next record
* @private
*/
_key_move_record: function (event, record_direction, is_valid_move) {
if (!this.editor.is_editing('edit')) { return $.when(); } if (!this.editor.is_editing('edit')) { return $.when(); }
// FIXME: assumes editable widgets are input-type elements // FIXME: assumes editable widgets are input-type elements
var index = this._text_cursor(e.target); var index = this._text_cursor(event.target);
// If selecting or not at the start of the input // If selecting or not at the start of the input
if (index === null || index !== 0) { return $.when(); } if (!is_valid_move(event.target, index)) { return $.when(); }
e.preventDefault(); event.preventDefault();
return this._next('pred'); var source_field = $(event.target).closest('[data-fieldname]')
.attr('data-fieldname');
return this._next(record_direction, {focus_field: source_field});
},
keydown_UP: function (e) {
return this._key_move_record(e, 'pred', function (el, index) {
return index === 0;
});
}, },
keydown_DOWN: function (e) { keydown_DOWN: function (e) {
if (!this.editor.is_editing('edit')) { return $.when(); } return this._key_move_record(e, 'succ', function (el, index) {
// FIXME: assumes editable widgets are input-type elements return index === el.value.length;
var index = this._text_cursor(e.target); });
// If selecting or not at the end of the input
if (index === null || index !== e.target.value.length) { return $.when(); }
e.preventDefault();
return this._next();
}, },
keydown_TAB: function (e) { keydown_TAB: function (e) {
var form = this.editor.form; var form = this.editor.form;

View File

@ -47,3 +47,9 @@ Undocumented stuff
* What is the difference between ``readonly`` and * What is the difference between ``readonly`` and
``effective_readonly``? ``effective_readonly``?
* No facilities for DOM events handling/delegations e.g. handling
keyup/keydown/keypress from a form fields into the form's user.
* Also no way to reverse from a DOM node (e.g. DOMEvent#target) back to a
form view field easily