[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
This commit is contained in:
Nicolas Lempereur
2017-01-18 14:30:57 +01:00
parent 6825ddf9ad
commit 2d753ab5ec
+7 -11
View File
@@ -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({