From b7ee1aa4b1ea906195c234020cb708a1da9de6a7 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 6 Dec 2017 10:09:02 +0100 Subject: [FIX] web: sort and onchange in tabbed editable x2m Two attempts of dealing with sorting (and resequencing) in tabbed (multi-pages) x2many editable lists (see odoo/odoo@c2563db and odoo/odoo@983c7ae) have been previously done, using a static attribute (`keepChangesUnsorted`) on the datapoint. This solution sadly only covers both cases separately, not if they are combined. Morever, onchanges were not correctly managed in neither of these two cases. A new approach is used here, by "freezing" and "unfreezing" the datapoint when needed, which is more flexible. Some modifications have been introduced: - when ordering a x2many, all records are now considered (and not only the records on the current page) ; an additional read is thus done on the sorted field for all records in the x2many relation - `setSort` is now asynchronous as a `read` might be needed --- addons/web/static/src/js/fields/relational_fields.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'addons/web/static/src/js/fields/relational_fields.js') diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 9d8a7b6e170..c399ffebe88 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -1018,6 +1018,7 @@ var FieldX2Many = AbstractField.extend({ */ _onEditLine: function (ev) { ev.stopPropagation(); + this.trigger_up('freeze_order', {id: this.value.id}); var editedRecord = this.value.data[ev.data.index]; this.renderer.setRowMode(editedRecord.id, 'edit') .done(ev.data.onSuccess); @@ -1104,6 +1105,7 @@ var FieldX2Many = AbstractField.extend({ */ _onResequence: function (event) { var self = this; + this.trigger_up('freeze_order', {id: this.value.id}); var rowIDs = event.data.rowIDs.slice(); var rowID = rowIDs.pop(); var defs = _.map(rowIDs, function (rowID, index) { @@ -1123,6 +1125,11 @@ var FieldX2Many = AbstractField.extend({ operation: 'UPDATE', id: rowID, data: _.object([event.data.handleField], [event.data.offset + rowIDs.length]), + }).always(function () { + self.trigger_up('toggle_column_order', { + id: self.value.id, + name: event.data.handleField, + }); }); }); }, @@ -1229,6 +1236,7 @@ var FieldOne2Many = FieldX2Many.extend({ } } else if (!this.creatingRecord) { this.creatingRecord = true; + this.trigger_up('freeze_order', {id: this.value.id}); this._setValue({ operation: 'CREATE', position: this.editable, -- cgit v1.2.3