[IMP] partially fix group_by handling

* Don't just use the domain out of a FilterGroup as group_by keys in filters will overwrite one another
* Add dedicated get_groupby API returning an array of groups to evaluate

limitation: can't intersperse groupby from a different FilterGroup, that'll have to be fixed by ungrouping buttons

bzr revid: xmo@openerp.com-20120403120742-o3liksqaigsnxvb4
This commit is contained in:
Xavier Morel 2012-04-03 14:07:42 +02:00
parent 71c98a510b
commit 30ba123a1f
2 changed files with 28 additions and 2 deletions

View File

@ -593,7 +593,10 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
var context = field.get_context(facet);
if (context) {
contexts.push(context);
groupbys.push(context);
}
var group_by = field.get_groupby(facet);
if (group_by) {
groupbys.push.apply(groupbys, group_by);
}
} catch (e) {
if (e instanceof openerp.web.search.Invalid) {
@ -798,6 +801,10 @@ openerp.web.search.Input = openerp.web.search.Widget.extend( /** @lends openerp.
throw new Error(
"get_context not implemented for widget " + this.attrs.type);
},
get_groupby: function () {
throw new Error(
"get_groupby not implemented for widget " + this.attrs.type);
},
get_domain: function () {
throw new Error(
"get_domain not implemented for widget " + this.attrs.type);
@ -865,6 +872,18 @@ openerp.web.search.FilterGroup = openerp.web.search.Input.extend(/** @lends open
__contexts: contexts
});
},
/**
* Fetches group_by sequence for all enabled filters in the group
*
* @param {VS.model.SearchFacet} facet
* @return {Array} enabled filters in this group
*/
get_groupby: function (facet) {
return _(facet.get('json')).chain()
.map(function (filter) { return filter.attrs.context; })
.reject(_.isEmpty)
.value();
},
/**
* Handles domains-fetching for all the filters within it: groups them.
*
@ -948,7 +967,7 @@ openerp.web.search.Filter = openerp.web.search.Input.extend(/** @lends openerp.w
},
facet_for: function () { return $.when(null); },
get_context: function () { },
get_domain: function () { }
get_domain: function () { },
});
openerp.web.search.Field = openerp.web.search.Input.extend( /** @lends openerp.web.search.Field# */ {
template: 'SearchView.field',
@ -989,6 +1008,7 @@ openerp.web.search.Field = openerp.web.search.Input.extend( /** @lends openerp.w
return new openerp.web.CompoundContext(context)
.set_eval_context({self: val});
},
get_groupby: function () { },
/**
* Function creating the returned domain for the field, override this
* methods in children if you only need to customize the field's domain

View File

@ -254,6 +254,12 @@ Widgets API
:js:class:`~VS.model.SearchFacet` as parameter, from which it's
their job to get whatever value they want
* :js:func:`~openerp.web.search.Input.get_groupby` has been added. It returns
an :js:class:`Array` of context-like constructs. By default, it does not do
anything in :js:class:`~openerp.web.search.Field` and it returns the various
contexts of its enabled filters in
:js:class:`~openerp.web.search.FilterGroup`.
Filters
+++++++