summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorMathieu Duckerts-Antoine <dam@odoo.com>2018-07-04 11:40:40 +0200
committerAdrien Dieudonne <adr@odoo.com>2018-07-06 13:28:17 +0200
commit94c027efdd9cf180f4ebcf7faadae2af6645d191 (patch)
treeb2b1f62a714f169b5c134864f3d59bd68ac0dab5 /addons/web/static/src
parent4094f75527d51f7a2e3c04a48a6d1600800c55c5 (diff)
[FIX] web: manage correctly deletion of facets
This commit fixes many synchronization problems between search view bar and the filters and groupby menus.
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/views/search/groupby_menu.js7
-rw-r--r--addons/web/static/src/js/views/search/search_view.js81
2 files changed, 46 insertions, 42 deletions
diff --git a/addons/web/static/src/js/views/search/groupby_menu.js b/addons/web/static/src/js/views/search/groupby_menu.js
index 4e3c4eb573d..32aaea64c4d 100644
--- a/addons/web/static/src/js/views/search/groupby_menu.js
+++ b/addons/web/static/src/js/views/search/groupby_menu.js
@@ -126,7 +126,7 @@ var GroupByMenu = DropdownMenu.extend({
itemId: groupbyName,
description: field.string,
fieldName: fieldName,
- groupId: this.groupId,
+ groupId: _.uniqueId('__group__'),
isActive: true,
};
var eventData = _.clone(groupby);
@@ -153,11 +153,6 @@ var GroupByMenu = DropdownMenu.extend({
item.options = this.intervalOptions;
item.defaultOptionId = item.defaultOptionId || this.defaultOptionId;
}
- // the idea is that we have only one group in the groupby menu
- // like in the search view.
- if (!this.groupId) {
- this.groupId = item.groupId;
- }
// super has to be called here because we need to add options to groupby
// before to call it since some keys in a groupby are initialized using
// the keys 'options' and 'defaultOptionId'
diff --git a/addons/web/static/src/js/views/search/search_view.js b/addons/web/static/src/js/views/search/search_view.js
index e307ca2a240..fe2ee0b47d7 100644
--- a/addons/web/static/src/js/views/search/search_view.js
+++ b/addons/web/static/src/js/views/search/search_view.js
@@ -578,32 +578,35 @@ var SearchView = Widget.extend({
this.query.each(function (facet) {
+ var values = facet.get('values');
if (facet.attributes.cat === "groupByCategory") {
- selectedGroupIds.groupByCategory = selectedGroupIds.groupByCategory.concat(
- _.compact(
- _.uniq(
- _.map(facet.attributes.values, function (value) {
- var groupby = value.value;
- var groupbyDescription = _.findWhere(self.groupbysMapping, {groupby: groupby});
- if (groupbyDescription) {
- return groupbyDescription.groupId;
- }
- })
- )
+ selectedGroupIds.groupByCategory = _.uniq(
+ values.reduce(
+ function (acc, value) {
+ var groupby = value.value;
+ var description = _.findWhere(self.groupbysMapping, {groupby: groupby});
+ if (description) {
+ acc.push(description.groupId);
+ }
+ return acc;
+ },
+ []
)
);
}
if (facet.attributes.cat === "filterCategory") {
selectedGroupIds.filterCategory = selectedGroupIds.filterCategory.concat(
_.uniq(
- _.compact(
- _.map(facet.attributes.values, function (value) {
+ values.reduce(
+ function (acc, value) {
var filter = value.value;
- var filterDescription = _.findWhere(self.filtersMapping, {filter: filter});
- if (filterDescription) {
- return filterDescription.groupId;
+ var description = _.findWhere(self.filtersMapping, {filter: filter});
+ if (description) {
+ acc.push(description.groupId);
}
- })
+ return acc;
+ },
+ []
)
)
);
@@ -869,39 +872,45 @@ var SearchView = Widget.extend({
return fv;
},
/**
- * @private
+ * This function ask the groupby menu to deactive all groupbys if no
+ * groupby is used.
+ *
* @param {string[]]} selectedGroupIds
*/
_unsetUnusedGroupbys: function (selectedGroupIds) {
- var groupIds = this.selectedGroupIds.groupByCategory.reduce(
- function (acc, id) {
- if (!_.contains(selectedGroupIds, id)) {
- acc.push(id);
+ var groupIds = this.groupsMapping.reduce(
+ function (acc, triple) {
+ if (triple.category === 'Group By') {
+ acc.push(triple.groupId);
}
return acc;
},
[]
);
this.selectedGroupIds.groupByCategory = selectedGroupIds;
- this.groupby_menu.unsetGroups(groupIds);
+ if (selectedGroupIds.length === 0) {
+ this.groupby_menu.unsetGroups(groupIds);
+ }
},
/**
* @private
* @param {string[]]} selectedGroupIds
*/
- _unsetUnusedFilters: function (selectedGroupIds) {
- var groupIds = this.selectedGroupIds.filterCategory.reduce(
- function (acc, id) {
- if (!_.contains(selectedGroupIds, id)) {
- acc.push(id);
- }
- return acc;
- },
- []
- );
- this.selectedGroupIds.filterCategory = selectedGroupIds;
- this.filters_menu.unsetGroups(groupIds);
- },
+ _unsetUnusedFilters: function (selectedGroupIds) {
+ var groupIds = this.groupsMapping.reduce(
+ function (acc, triple) {
+ if (triple.category === 'Filters') {
+ if (!_.contains(selectedGroupIds, triple.groupId)) {
+ acc.push(triple.groupId);
+ }
+ }
+ return acc;
+ },
+ []
+ );
+ this.selectedGroupIds.filterCategory = selectedGroupIds;
+ this.filters_menu.unsetGroups(groupIds);
+ },
//--------------------------------------------------------------------------
// Handlers