diff options
| author | Martin Geubelle <mge@odoo.com> | 2017-09-04 11:36:26 +0200 |
|---|---|---|
| committer | Martin Geubelle <mge@odoo.com> | 2017-09-06 16:34:18 +0200 |
| commit | 3052a434947f71955a5e287e373164be46f8860c (patch) | |
| tree | 1293720a076492bd91172df7bca7b0389d25909f /addons/web/static/src/js/views/basic/basic_model.js | |
| parent | 64d56995e049d7e7bc3aa7af5a16603220b0d4bc (diff) | |
[FIX] web: edit editable list view after resequence
In an editable list view with the widget `handle`, resequencing a record
and try to edit it afterwards won't work. The selected record isn't the
correct one, as if the resequencing had no impact.
A small refactoring has been done to fix this because the resequence logic
was placed in the ListController (but should logically be placed in the model).
Several views are using the resequencing ; the code is thus now placed in the
BasicModel.
The list renderer state is then updated after the resequence.
The resequencing and the line edition have been placed in a common mutex to
avoid problems when the user tries to edit a record while the resequence rpc
isn't finished yet.
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_model.js')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 9c4599f1683..202545c2c8f 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -780,6 +780,55 @@ var BasicModel = AbstractModel.extend({ } }, /** + * Resequences records. + * + * @param {string} modelName the resIDs model + * @param {Array[integer]} resIDs the new sequence of ids + * @param {string} parentID the localID of the parent + * @param {object} [options] + * @param {integer} [options.offset] + * @param {string} [options.field] the field name used as sequence + * @returns {Deferred<string>} resolves to the local id of the parent + */ + resequence: function (modelName, resIDs, parentID, options) { + options = options || {}; + if ((resIDs.length <= 1)) { + return $.when(parentID); // there is nothing to sort + } + var self = this; + var data = this.localData[parentID]; + var params = { + model: modelName, + ids: resIDs, + }; + if (options.offset) { + params.offset = options.offset; + } + if (options.field) { + params.field = options.field; + } + return this._rpc({ + route: '/web/dataset/resequence', + params: params, + }) + .then(function () { + data.data = _.sortBy(data.data, function (d) { + return _.indexOf(resIDs, self.localData[d].res_id); + }); + data.res_ids = []; + _.each(data.data, function (d) { + var dataPoint = self.localData[d]; + if (dataPoint.type === 'record') { + data.res_ids.push(dataPoint.res_id); + } else { + data.res_ids = data.res_ids.concat(dataPoint.res_ids); + } + }); + self._updateParentResIDs(data); + return parentID; + }); + }, + /** * Save a local resource, if needed. This is a complicated operation, * - it needs to check all changes, * - generate commands for x2many fields, |
