From f910bc67804e185e486a8355b8ba329942a5c0eb Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 18 Oct 2012 14:40:05 +0200 Subject: [PATCH] [FIX] don't trigger search twice when a facet is removed from the query due to its values becoming empty The facet removal from its last value being removed (`this.remove(facet)` in the 'change' handler of the SearchQuery) broadcasted its `remove` event, triggering the `do_search` (and repaint) hook of the SearchView a second time right after the `change`-triggered search. Not only is this unnecessary and duplicated work (the `remove` is a sync operation, so searchview-attached events haven't yet executed by the time `remove` is called), the listview really doesn't like getting a ``search`` signal while it's already executing a search. So fix that. bzr revid: xmo@openerp.com-20121018124005-6vfi7tqasz32ai8v --- addons/web/static/src/js/search.js | 2 +- addons/web/static/test/search.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index 8a6019be9d5..80d5e57bd8f 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -61,7 +61,7 @@ my.SearchQuery = B.Collection.extend({ this.on('change', function (facet) { if(!facet.values.isEmpty()) { return; } - this.remove(facet); + this.remove(facet, {silent: true}); }, this); }, add: function (values, options) { diff --git a/addons/web/static/test/search.js b/addons/web/static/test/search.js index 6dc37f31d08..59353f9d22d 100644 --- a/addons/web/static/test/search.js +++ b/addons/web/static/test/search.js @@ -1044,8 +1044,12 @@ $(document).ready(function () { "second value should be clicked filter"); }); }); - asyncTest('click removing from query', 2, function () { + asyncTest('click removing from query', 4, function () { + var calls = 0; var view = makeSearchView({}, {foo2: true}); + view.on_search.add(function () { + ++calls; + }); var $fix = $('#qunit-fixture'); view.appendTo($fix) .always(start) @@ -1054,8 +1058,10 @@ $(document).ready(function () { var $fs = $fix.find('.oe_searchview_filters ul'); // sanity check equal(view.query.length, 1, "query should have default facet"); + strictEqual(calls, 0); $fs.children(':eq(1)').trigger('click'); equal(view.query.length, 0, "click should have removed facet"); + strictEqual(calls, 1, "one search should have been triggered"); }); });