[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:
@@ -1493,20 +1493,16 @@ ListView.Groups = Class.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
setup_resequence_rows: function (list, dataset) {
|
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
|
// 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
|
// its sequence field (ASC)), and there is a visible column with
|
||||||
// or "sequence" column in the view.
|
// @widget=handle or "sequence" column in the view.
|
||||||
if ((dataset.sort && dataset.sort() && dataset.sort() !== 'sequence'
|
if ((dataset.sort && [seqname, seqname + 'ASC', ''].indexOf(dataset.sort()) === -1)
|
||||||
&& dataset.sort() !== 'sequence ASC')
|
|| !_(this.columns).findWhere({'name': seqname})) {
|
||||||
|| !_(this.columns).any(function (column) {
|
|
||||||
return column.widget === 'handle'
|
|
||||||
|| column.name === 'sequence'; })) {
|
|
||||||
return;
|
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
|
// ondrop, move relevant record & fix sequences
|
||||||
list.$current.sortable({
|
list.$current.sortable({
|
||||||
|
|||||||
Reference in New Issue
Block a user