summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2017-01-13 14:37:23 +0100
committerNicolas Lempereur <nle@odoo.com>2017-01-18 14:30:57 +0100
commit2d753ab5ec3a2e99da5864a1ba20bd834d5d465e (patch)
tree3a88bf55d3088f52cb81e713cf5c9891873b5b7f /addons/web/static/src
parent6825ddf9ad093ad47a964bfd78d95563dacd01f0 (diff)
[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
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/views/list_view.js18
1 files 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({