[REF] web: extracts category value selection in a function

This commit extracts the logic of the selection of the default
value for search panel categories into a private function
so it can be hooked in other modules.

task: #1959112

closes odoo/odoo#32448

Signed-off-by: Martin Geubelle (mge) <mge@openerp.com>
This commit is contained in:
Thanh Dodeur
2019-04-25 07:21:19 +00:00
parent 85f3f5d662
commit 46b0b33d06
@@ -151,14 +151,7 @@ var SearchPanel = Widget.extend({
// set active value
var validValues = _.pluck(category.values, 'id').concat([false]);
// set active value from context
var value = this.defaultValues[category.fieldName];
// if not set in context, or set to an unknown value, set active value
// from localStorage
if (!_.contains(validValues, value)) {
var storageKey = this._getLocalStorageKey(category);
value = this.call('local_storage', 'getItem', storageKey);
}
var value = this._getCategoryDefaultValue(category, validValues);
// if not set in localStorage either, select 'All'
category.activeValueId = _.contains(validValues, value) ? value : false;
@@ -296,6 +289,23 @@ var SearchPanel = Widget.extend({
});
return Promise.all(proms);
},
/**
* @private
* @param {Object} category
* @param {Array} validValues
* @returns id of the default item of the category or false
*/
_getCategoryDefaultValue: function (category, validValues) {
// set active value from context
var value = this.defaultValues[category.fieldName];
// if not set in context, or set to an unknown value, set active value
// from localStorage
if (!_.contains(validValues, value)) {
var storageKey = this._getLocalStorageKey(category);
return this.call('local_storage', 'getItem', storageKey);
}
return value;
},
/**
* Compute and return the domain based on the current active categories.
*