[ADD] single-facet handling of groupby
bzr revid: xmo@openerp.com-20120504094306-dieslsoibjjbtcs5
This commit is contained in:
parent
2251227058
commit
7e0bd0103b
|
@ -880,6 +880,13 @@ instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends in
|
||||||
* @param {instance.web.SearchView} view view in which the filters are contained
|
* @param {instance.web.SearchView} view view in which the filters are contained
|
||||||
*/
|
*/
|
||||||
init: function (filters, view) {
|
init: function (filters, view) {
|
||||||
|
// If all filters are group_by and we're not initializing a GroupbyGroup,
|
||||||
|
// create a GroupbyGroup instead of the current FilterGroup
|
||||||
|
if (!(this instanceof instance.web.search.GroupbyGroup) &&
|
||||||
|
_(filters).all(function (f) {
|
||||||
|
return f.attrs.context && f.attrs.context.group_by; })) {
|
||||||
|
return new instance.web.search.GroupbyGroup(filters, view);
|
||||||
|
}
|
||||||
this._super(view);
|
this._super(view);
|
||||||
this.filters = filters;
|
this.filters = filters;
|
||||||
},
|
},
|
||||||
|
@ -887,6 +894,13 @@ instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends in
|
||||||
this.$element.on('click', 'li', this.proxy('toggle_filter'));
|
this.$element.on('click', 'li', this.proxy('toggle_filter'));
|
||||||
return $.when(null);
|
return $.when(null);
|
||||||
},
|
},
|
||||||
|
make_facet: function (values) {
|
||||||
|
return {
|
||||||
|
category: _t("Filter"),
|
||||||
|
values: values,
|
||||||
|
field: this
|
||||||
|
}
|
||||||
|
},
|
||||||
facet_for_defaults: function (defaults) {
|
facet_for_defaults: function (defaults) {
|
||||||
var fs = _(this.filters).chain()
|
var fs = _(this.filters).chain()
|
||||||
.filter(function (f) {
|
.filter(function (f) {
|
||||||
|
@ -896,11 +910,7 @@ instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends in
|
||||||
value: f};
|
value: f};
|
||||||
}).value();
|
}).value();
|
||||||
if (_.isEmpty(fs)) { return $.when(null); }
|
if (_.isEmpty(fs)) { return $.when(null); }
|
||||||
return $.when({
|
return $.when(this.make_facet(fs));
|
||||||
category: _t("Filter"),
|
|
||||||
values: fs,
|
|
||||||
field: this
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Fetches contexts for all enabled filters in the group
|
* Fetches contexts for all enabled filters in the group
|
||||||
|
@ -957,14 +967,37 @@ instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends in
|
||||||
this.toggle(this.filters[$(e.target).index()]);
|
this.toggle(this.filters[$(e.target).index()]);
|
||||||
},
|
},
|
||||||
toggle: function (filter) {
|
toggle: function (filter) {
|
||||||
this.view.query.toggle({
|
this.view.query.toggle(this.make_facet([{
|
||||||
category: _t("Filter"),
|
label: filter.attrs.string || filter.attrs.name,
|
||||||
field: this,
|
value: filter
|
||||||
values: [{
|
}]));
|
||||||
label: filter.attrs.string || filter.attrs.name,
|
}
|
||||||
value: filter
|
});
|
||||||
}]
|
instance.web.search.GroupbyGroup = instance.web.search.FilterGroup.extend({
|
||||||
});
|
init: function (filters, view) {
|
||||||
|
this._super(filters, view);
|
||||||
|
// Not flanders: facet unicity is handled through the
|
||||||
|
// (category, field) pair of facet attributes. This is all well and
|
||||||
|
// good for regular filter groups where a group matche a facet, but for
|
||||||
|
// groupby we want a single facet. So cheat: add an attribute on the
|
||||||
|
// view which proxies to the first GroupbyGroup, so it can be used
|
||||||
|
// for every GroupbyGroup and still provides the various methods needed
|
||||||
|
// by the search view. Use weirdo name to avoid risks of conflicts
|
||||||
|
if (!this.getParent()._s_groupby) {
|
||||||
|
this.getParent()._s_groupby = {
|
||||||
|
help: "See GroupbyGroup#init",
|
||||||
|
get_context: this.proxy('get_context'),
|
||||||
|
get_domain: this.proxy('get_domain'),
|
||||||
|
get_groupby: this.proxy('get_groupby')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
make_facet: function (values) {
|
||||||
|
return {
|
||||||
|
category: _t("GroupBy"),
|
||||||
|
values: values,
|
||||||
|
field: this.getParent()._s_groupby
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
instance.web.search.Filter = instance.web.search.Input.extend(/** @lends instance.web.search.Filter# */{
|
instance.web.search.Filter = instance.web.search.Input.extend(/** @lends instance.web.search.Filter# */{
|
||||||
|
|
Loading…
Reference in New Issue