From 46b0b33d06d3b8068a44d2f573362c445316d17f Mon Sep 17 00:00:00 2001 From: Thanh Dodeur Date: Tue, 23 Apr 2019 07:14:39 +0000 Subject: [PATCH] [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) --- .../src/js/views/kanban/search_panel.js | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/addons/web/static/src/js/views/kanban/search_panel.js b/addons/web/static/src/js/views/kanban/search_panel.js index d06eacbdb07..c3e67032d73 100644 --- a/addons/web/static/src/js/views/kanban/search_panel.js +++ b/addons/web/static/src/js/views/kanban/search_panel.js @@ -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. *