From 2d753ab5ec3a2e99da5864a1ba20bd834d5d465e Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 13 Jan 2017 14:37:23 +0100 Subject: [PATCH] [FIX] web: handle widget order and custom sequence An editable list can be drag-and-drop sorted by: - displaying a sequence field, - displaying a field with the `handle` widget At first it was only working if the list was not specifically ordered, but with 26bf35260 it also worked if the list was ordered on `sequence` or `sequence ASC`. This commit changes this so it works: - if the list is not ordered (same as the original intention), - if the list is ordered by the sequence field (widget `handle` or sequence) This allows to have a custom model (on which we can't define _order) to be ordered on a custom field. This also remove a far-fetched oddity such as having the view ordered by sequence but having a custom sequence field before `sequence`. opw-704612 --- addons/web/static/src/js/views/list_view.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/addons/web/static/src/js/views/list_view.js b/addons/web/static/src/js/views/list_view.js index 1cd26ddbcb1..3cca3fa7949 100644 --- a/addons/web/static/src/js/views/list_view.js +++ b/addons/web/static/src/js/views/list_view.js @@ -1493,20 +1493,16 @@ ListView.Groups = Class.extend({ }); }, setup_resequence_rows: function (list, dataset) { + var sequence_field = _(this.columns).findWhere({'widget': 'handle'}); + var seqname = sequence_field ? sequence_field.name : 'sequence'; + // drag and drop enabled if list is not sorted (unless it is sorted by - // sequence (ASC)), and there is a visible column with @widget=handle - // or "sequence" column in the view. - if ((dataset.sort && dataset.sort() && dataset.sort() !== 'sequence' - && dataset.sort() !== 'sequence ASC') - || !_(this.columns).any(function (column) { - return column.widget === 'handle' - || column.name === 'sequence'; })) { + // its sequence field (ASC)), and there is a visible column with + // @widget=handle or "sequence" column in the view. + if ((dataset.sort && [seqname, seqname + 'ASC', ''].indexOf(dataset.sort()) === -1) + || !_(this.columns).findWhere({'name': seqname})) { return; } - var sequence_field = _(this.columns).find(function (c) { - return c.widget === 'handle'; - }); - var seqname = sequence_field ? sequence_field.name : 'sequence'; // ondrop, move relevant record & fix sequences list.$current.sortable({