summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRomeo Fragomeli <rfr@odoo.com>2020-10-08 08:20:25 +0000
committerRomeo Fragomeli <rfr@odoo.com>2020-12-08 12:04:36 +0000
commitc6c4b9f0e4bae03b51d232ea920de9587d8e2b73 (patch)
treefd4a269aeb0d74af1ec22ab7c24855b008d43a34
parent52bf0e331fb9230423b76b9014bb13d490930e76 (diff)
[FIX] web: don't update the list view if not needed
Before this commit, an event was triggered even when no change occurred. Steps to reproduces: * Go to Document * Change to list view * Go to app switcher * Select another app that has enough content to be able to scroll * Scroll the view => Bug Task ID: 2347584 closes odoo/odoo#63012 Signed-off-by: Adrien Dieudonné (adr) <adr@odoo.com> Co-authored-by: Michaël Mattiello <mcm@odoo.com>
-rw-r--r--addons/web/static/src/js/views/list/list_renderer.js5
-rw-r--r--addons/web/static/tests/views/list_tests.js46
2 files changed, 50 insertions, 1 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 4571b1275a4..7559fda1063 100644
--- a/addons/web/static/src/js/views/list/list_renderer.js
+++ b/addons/web/static/src/js/views/list/list_renderer.js
@@ -1168,6 +1168,7 @@ var ListRenderer = BasicRenderer.extend({
* @private
*/
_updateSelection: function () {
+ const previousSelection = JSON.stringify(this.selection);
this.selection = [];
var self = this;
var $inputs = this.$('tbody .o_list_record_selector input:visible:not(:disabled)');
@@ -1180,7 +1181,9 @@ var ListRenderer = BasicRenderer.extend({
}
});
this.$('thead .o_list_record_selector input').prop('checked', allChecked);
- this.trigger_up('selection_changed', { allChecked, selection: this.selection });
+ if (JSON.stringify(this.selection) !== previousSelection) {
+ this.trigger_up('selection_changed', { allChecked, selection: this.selection });
+ }
this._updateFooter();
},
diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js
index 29a3bcddbf4..81e95ddfabc 100644
--- a/addons/web/static/tests/views/list_tests.js
+++ b/addons/web/static/tests/views/list_tests.js
@@ -10871,6 +10871,52 @@ QUnit.module('Views', {
unpatchDate();
testUtils.mock.unpatch(BasicModel);
});
+
+ QUnit.test("update control panel while list view is mounting", async function (assert) {
+ const ControlPanel = require('web.ControlPanel');
+ const ListController = require('web.ListController');
+
+ let mountedCounterCall = 0;
+
+ ControlPanel.patch('test.ControlPanel', T => {
+ class ControlPanelPatchTest extends T {
+ mounted() {
+ mountedCounterCall = mountedCounterCall + 1;
+ assert.step(`mountedCounterCall-${mountedCounterCall}`);
+ super.mounted(...arguments);
+ }
+ }
+ return ControlPanelPatchTest;
+ });
+
+ const MyListView = ListView.extend({
+ config: Object.assign({}, ListView.prototype.config, {
+ Controller: ListController.extend({
+ async start() {
+ await this._super(...arguments);
+ this.renderer._updateSelection();
+ },
+ }),
+ }),
+ });
+
+ assert.expect(2);
+
+ const list = await createView({
+ View: MyListView,
+ model: 'event',
+ data: this.data,
+ arch: '<tree><field name="name"/></tree>',
+ });
+
+ assert.verifySteps([
+ 'mountedCounterCall-1',
+ ]);
+
+ ControlPanel.unpatch('test.ControlPanel');
+
+ list.destroy();
+ });
});
});