summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2020-03-27 13:54:46 +0000
committerAaron Bohy <aab@odoo.com>2020-03-30 13:33:40 +0000
commit009fe3e81bc982f25b052dc4430f6a232e4bff95 (patch)
tree1c8e08ea0a6ab533869df1658111113b949691c5
parent4fd30ecbc1207fc370688c32798dd78eb5cef0e8 (diff)
[FIX] web: list: keep header checkbox selected
... when toggling an optional field. This bug wasn't really important until now, but with the new selection mechanism, it could lead to weird situations (e.g. the selection box says that all records are selected, but the thead checkbox isn't checked). Part of task 2185145
-rw-r--r--addons/web/static/src/js/views/list/list_renderer.js3
-rw-r--r--addons/web/static/tests/views/list_tests.js49
2 files changed, 52 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/list/list_renderer.js b/addons/web/static/src/js/views/list/list_renderer.js
index 418c39b14e0..5cf4b022c5d 100644
--- a/addons/web/static/src/js/views/list/list_renderer.js
+++ b/addons/web/static/src/js/views/list/list_renderer.js
@@ -989,6 +989,9 @@ var ListRenderer = BasicRenderer.extend({
return _.contains(self.selection, $(el).data('id'));
});
$checked_rows.find('.o_list_record_selector input').prop('checked', true);
+ if ($checked_rows.length === self.$('.o_data_row').length) { // all rows are checked
+ self.$('thead .o_list_record_selector input').prop('checked', true);
+ }
}
});
return Promise.all([this._super.apply(this, arguments), prom]);
diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js
index f2a49f5c339..94a7a3bb156 100644
--- a/addons/web/static/tests/views/list_tests.js
+++ b/addons/web/static/tests/views/list_tests.js
@@ -8839,6 +8839,55 @@ QUnit.module('Views', {
list.destroy();
});
+ QUnit.test('selection is kept when optional fields are toggled', async function (assert) {
+ assert.expect(7);
+
+ var RamStorageService = AbstractStorageService.extend({
+ storage: new RamStorage(),
+ });
+
+ var list = await createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree>' +
+ '<field name="foo"/>' +
+ '<field name="m2o" optional="hide"/>' +
+ '</tree>',
+ services: {
+ local_storage: RamStorageService,
+ },
+ });
+
+ assert.containsN(list, 'th', 2);
+
+ // select a record
+ await testUtils.dom.click(list.$('.o_data_row .o_list_record_selector input:first'));
+
+ assert.containsOnce(list, '.o_list_record_selector input:checked');
+
+ // add an optional field
+ await testUtils.dom.click(list.$('table .o_optional_columns_dropdown_toggle'));
+ await testUtils.dom.click(list.$('div.o_optional_columns div.dropdown-item:first input'));
+ assert.containsN(list, 'th', 3);
+
+ assert.containsOnce(list, '.o_list_record_selector input:checked');
+
+ // select all records
+ await testUtils.dom.click(list.$('thead .o_list_record_selector input'));
+
+ assert.containsN(list, '.o_list_record_selector input:checked', 5);
+
+ // remove an optional field
+ await testUtils.dom.click(list.$('table .o_optional_columns_dropdown_toggle'));
+ await testUtils.dom.click(list.$('div.o_optional_columns div.dropdown-item:first input'));
+ assert.containsN(list, 'th', 2);
+
+ assert.containsN(list, '.o_list_record_selector input:checked', 5);
+
+ list.destroy();
+ });
+
QUnit.test('change the viewType of the current action', async function (assert) {
assert.expect(25);