[FIX] filter preceded by an invisible filter in the same group

On click on a filter in the drawer, FilterGroup would just match the
offset of the filter in the group's DOM with an index in the internal
#filters array. 

This worked until invisible fields, and then again only for filters
*preceded* by an invisible sibling in the same group: invisible
filters are not rendered in the DOM, so the indexes would get out of
sync.

Fix by using explicit indexes stored in a filter's @data-index and
using that to get the filter object/node.

An alternative fix (but hackier I think): instead of not rendering
invisible filters, render them with display: none. Remains an option
in the future if needed...

lp bug: https://launchpad.net/bugs/1157125 fixed

bzr revid: xmo@openerp.com-20130321155123-211iht7c6zme712e
This commit is contained in:
Xavier Morel 2013-03-21 16:51:23 +01:00
parent 3b2e26af18
commit 3c5d38918b
3 changed files with 23 additions and 2 deletions

View File

@ -1136,7 +1136,7 @@ instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends in
});
},
toggle_filter: function (e) {
this.toggle(this.filters[$(e.target).index()]);
this.toggle(this.filters[Number($(e.target).data('index'))]);
},
toggle: function (filter) {
this.view.query.toggle(this.make_facet([this.make_value(filter)]));

View File

@ -1521,7 +1521,8 @@
</button>
<ul t-name="SearchView.filters">
<li t-foreach="widget.filters" t-as="filter" t-if="!filter.visible || filter.visible()"
t-att-title="filter.attrs.string ? filter.attrs.help : undefined">
t-att-title="filter.attrs.string ? filter.attrs.help : undefined"
t-att-data-index="filter_index">
<t t-esc="filter.attrs.string or filter.attrs.help or filter.attrs.name or 'Ω'"/>
</li>
</ul>

View File

@ -1400,6 +1400,26 @@ openerp.testing.section('search.invisible', {
return done;
});
});
test('invisible-previous-sibling', {asserts: 3}, function (instance, $fix, mock) {
var view = makeView(instance, mock, {}, [
'<search>',
'<filter string="filter 0" context="{&quot;test&quot;: 0}"/>',
'<filter string="filter 1" modifiers="{&quot;invisible&quot;: true}" context="{&quot;test&quot;: 1}"/>',
'<filter string="filter 2" modifiers="{&quot;invisible&quot;: true}" context="{&quot;test&quot;: 2}"/>',
'<filter string="filter 3" context="{&quot;test&quot;: 3}"/>',
'</search>'].join(''));
return view.appendTo($fix)
.done(function () {
// Select filter 3
$fix.find('.oe_searchview_filters ul li:contains("filter 3")').click();
equal(view.query.length, 1, "should have selected a filter");
var facet = view.query.at(0);
strictEqual(facet.values.at(0).get('label'), "filter 3",
"should have correctly labelled the facet");
deepEqual(view.build_search_data().contexts, [{test: 3}],
"should have built correct context");
});
});
// Invisible filter groups should not appear in the drawer
// Group invisibility should be inherited by children
test('group-invisibility', {asserts: 6}, function (instance, $fix, mock) {