summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2012-05-04 11:43:06 +0200
committerXavier Morel <xmo@openerp.com>2012-05-04 11:43:06 +0200
commit7e0bd0103bda6ebd25ee0edfd239df889b79ccf7 (patch)
treeb7d4cfc1ed0f931071f3e6c00fb641c14d108018 /addons/web/static/src
parent2251227058da557f51b9a3199135ac45503801dd (diff)
[ADD] single-facet handling of groupby
bzr revid: xmo@openerp.com-20120504094306-dieslsoibjjbtcs5
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/search.js59
1 files changed, 46 insertions, 13 deletions
diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js
index 39a53cf603f..a9d26bf747b 100644
--- a/addons/web/static/src/js/search.js
+++ b/addons/web/static/src/js/search.js
@@ -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
*/
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.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'));
return $.when(null);
},
+ make_facet: function (values) {
+ return {
+ category: _t("Filter"),
+ values: values,
+ field: this
+ }
+ },
facet_for_defaults: function (defaults) {
var fs = _(this.filters).chain()
.filter(function (f) {
@@ -896,11 +910,7 @@ instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends in
value: f};
}).value();
if (_.isEmpty(fs)) { return $.when(null); }
- return $.when({
- category: _t("Filter"),
- values: fs,
- field: this
- });
+ return $.when(this.make_facet(fs));
},
/**
* 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()]);
},
toggle: function (filter) {
- this.view.query.toggle({
- category: _t("Filter"),
- field: this,
- values: [{
- label: filter.attrs.string || filter.attrs.name,
- value: filter
- }]
- });
+ this.view.query.toggle(this.make_facet([{
+ 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# */{