[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
This commit is contained in:
Xavier Morel 2012-10-18 14:40:05 +02:00
parent 8b2a07eb55
commit f910bc6780
2 changed files with 8 additions and 2 deletions

View File

@ -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) {

View File

@ -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");
});
});