diff options
| author | Christophe Matthieu <chm@odoo.com> | 2017-12-06 10:09:02 +0100 |
|---|---|---|
| committer | Martin Geubelle <mge@odoo.com> | 2018-01-05 17:34:25 +0100 |
| commit | b7ee1aa4b1ea906195c234020cb708a1da9de6a7 (patch) | |
| tree | d6c7263b6b4f40e89ede6b3a55b86909e9ffba15 /addons/web/static/src/js/fields | |
| parent | d3cebdc4a2c8cb5c31cc56a79821b09a4d4712a8 (diff) | |
[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
Diffstat (limited to 'addons/web/static/src/js/fields')
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 8 |
1 files changed, 8 insertions, 0 deletions
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, |
