Skip to content

Commit

Permalink
[FIX] web: lock handle when sorting on a different field
Browse files Browse the repository at this point in the history
The resequence mechanism works if the sequence is sorted by its handle field.
Therefore sorting on another field should lock the handle, while sorting on the
handle field should unlock the handle.

opw 1867049
  • Loading branch information
len-odoo authored and len-foss committed Sep 14, 2018
1 parent 6e0afe8 commit 8179960
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
3 changes: 2 additions & 1 deletion addons/web/static/src/js/views/list/list_renderer.js
Expand Up @@ -184,7 +184,6 @@ var ListRenderer = BasicRenderer.extend({
reject = columnInvisibleFields[c.attrs.name];
}
if (!reject && c.attrs.widget === 'handle') {
self.hasHandle = true;
self.handleField = c.attrs.name;
}
return reject;
Expand Down Expand Up @@ -649,6 +648,8 @@ var ListRenderer = BasicRenderer.extend({
this._computeAggregates();
$table.toggleClass('o_list_view_grouped', is_grouped);
$table.toggleClass('o_list_view_ungrouped', !is_grouped);
this.hasHandle = this.state.orderedBy.length === 0 ||
this.state.orderedBy[0].name === this.handleField;
if (is_grouped) {
$table
.append(this._renderHeader(true))
Expand Down
70 changes: 70 additions & 0 deletions addons/web/static/tests/views/list_tests.js
Expand Up @@ -3175,6 +3175,76 @@ QUnit.module('Views', {
list.destroy();
});

QUnit.test('editable list, handle widget locks and unlocks on sort', function (assert) {
assert.expect(6);

// we need another sortable field to lock/unlock the handle
this.data.foo.fields.amount.sortable = true;
// resequence makes sense on a sequence field, not on arbitrary fields
this.data.foo.records[0].int_field = 0;
this.data.foo.records[1].int_field = 1;
this.data.foo.records[2].int_field = 2;
this.data.foo.records[3].int_field = 3;

var list = createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree editable="top" default_order="int_field">' +
'<field name="int_field" widget="handle"/>' +
'<field name="amount" widget="float"/>' +
'</tree>',
});

assert.strictEqual(list.$('tbody').text(), '1200.00500.00300.000.00',
"default should be sorted by int_field");

// Drag and drop the fourth line in second position
testUtils.dragAndDrop(
list.$('.ui-sortable-handle').eq(3),
list.$('tbody tr').first(),
{position: 'bottom'}
);

// Handle should be unlocked at this point
assert.strictEqual(list.$('tbody').text(), '1200.000.00500.00300.00',
"drag and drop should have succeeded, as the handle is unlocked");

// Sorting by a field different for int_field should lock the handle
list.$('.o_column_sortable').eq(1).click();

assert.strictEqual(list.$('tbody').text(), '0.00300.00500.001200.00',
"should have been sorted by amount");

// Drag and drop the fourth line in second position (not)
testUtils.dragAndDrop(
list.$('.ui-sortable-handle').eq(3),
list.$('tbody tr').first(),
{position: 'bottom'}
);

assert.strictEqual(list.$('tbody').text(), '0.00300.00500.001200.00',
"drag and drop should have failed as the handle is locked");

// Sorting by int_field should unlock the handle
list.$('.o_column_sortable').eq(0).click();

assert.strictEqual(list.$('tbody').text(), '1200.000.00500.00300.00',
"records should be ordered as per the previous resequence");

// Drag and drop the fourth line in second position
testUtils.dragAndDrop(
list.$('.ui-sortable-handle').eq(3),
list.$('tbody tr').first(),
{position: 'bottom'}
);

assert.strictEqual(list.$('tbody').text(), '1200.00300.000.00500.00',
"drag and drop should have worked as the handle is unlocked");

list.destroy();
});

QUnit.test('editable list with handle widget with slow network', function (assert) {
assert.expect(15);

Expand Down

0 comments on commit 8179960

Please sign in to comment.