[FIX] web: keep the search options visibility state

The search buttons visibility is saved in the local storage. Rev.
6448420 changed the API of the LocalStorage servive (by JSON
parsing the values), and didn't adapt the calls done for the
search buttons.

Closes #33833

closes odoo/odoo#34206

Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
This commit is contained in:
Jakub Hrubý
2019-06-18 10:13:39 +00:00
committed by Aaron Bohy
parent 0c302e30a0
commit 36abc4641c
3 changed files with 55 additions and 2 deletions
@@ -304,7 +304,7 @@ var SearchView = Widget.extend({
'click .o_searchview_more': function (e) {
$(e.target).toggleClass('fa-search-plus fa-search-minus');
var visibleSearchMenu = this.call('local_storage', 'getItem', 'visible_search_menu');
this.call('local_storage', 'setItem', 'visible_search_menu', visibleSearchMenu !== 'true');
this.call('local_storage', 'setItem', 'visible_search_menu', visibleSearchMenu === false);
this.toggle_buttons();
},
'keydown .o_searchview_input, .o_searchview_facet': function (e) {
@@ -395,7 +395,7 @@ var SearchView = Widget.extend({
this.timeRanges = options.action && options.action.context ?
options.action.context.time_ranges : undefined;
var visibleSearchMenu = this.call('local_storage', 'getItem', 'visible_search_menu');
this.visible_filters = (visibleSearchMenu !== 'false');
this.visible_filters = (visibleSearchMenu !== false);
this.input_subviews = []; // for user input in searchbar
this.search_defaults = this.options.search_defaults || {};
this.headless = this.options.hidden && _.isEmpty(this.search_defaults);
@@ -1,7 +1,9 @@
odoo.define('web.search_view_tests', function (require) {
"use strict";
var AbstractStorageService = require('web.AbstractStorageService');
var FormView = require('web.FormView');
var RamStorage = require('web.RamStorage');
var testUtils = require('web.test_utils');
var testUtilsDom = require('web.test_utils_dom');
var createActionManager = testUtils.createActionManager;
@@ -1087,5 +1089,45 @@ QUnit.module('Search View', {
form.destroy();
});
QUnit.module('Misc');
QUnit.test('search buttons visibility is stored in/retrieved from local storage', async function (assert) {
assert.expect(9);
var RamStorageService = AbstractStorageService.extend({
storage: new RamStorage(),
});
var actionManager = createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
services: {
local_storage: RamStorageService,
},
});
testUtils.intercept(actionManager, 'call_service', function (ev) {
if (ev.data.service === 'local_storage' && ev.data.args[0] === 'visible_search_menu') {
assert.step(`${ev.data.method} ${ev.data.args.length > 1 ? ev.data.args[1] : ''}`);
}
}, true);
await actionManager.doAction(1);
assert.isVisible($('.o_search_options .o_dropdown_toggler_btn:first'));
await testUtils.dom.click($('.o_searchview_more'));
assert.isNotVisible($('.o_search_options .o_dropdown_toggler_btn:first'));
assert.verifySteps(['getItem ', 'getItem ', 'setItem false']);
await actionManager.doAction(2);
assert.isNotVisible($('.o_search_options .o_dropdown_toggler_btn:first'));
assert.verifySteps(['getItem ', 'getItem ', 'setItem false', 'getItem ']);
actionManager.destroy();
});
});
});
+11
View File
@@ -0,0 +1,11 @@
Czech Republic, 2019-06-03
I hereby agree to the terms of the Odoo Individual Contributor License
Agreement v1.0.
I declare that I am authorized and able to make this agreement and sign this
declaration.
Signed,
Jakub Hrubý jakub@jhruby.cz https://github.com/jakubhruby