diff options
| author | Lucas Perais (lpe) <lpe@odoo.com> | 2019-06-14 15:38:44 +0000 |
|---|---|---|
| committer | Lucas Perais (lpe) <lpe@odoo.com> | 2019-06-17 07:49:06 +0000 |
| commit | 800a55c06f70d36673defa808b2a943130e69c8f (patch) | |
| tree | 923f2d3ef2d4417a9e6bfab6f0001732005320c4 /addons | |
| parent | caaaa129f752da7bcb541cc43a2303b6d32b1359 (diff) | |
[FIX] web: Favorites checkboxes are mutually exclusive
Before this commit, one could activate the two checkboxes "use by default", and "share for all users"
After this commit, only one out of the two can be checked
OPW 2010458
closes odoo/odoo#34167
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/web/static/src/js/views/control_panel/search/add_new_favorite_menu.js | 28 | ||||
| -rw-r--r-- | addons/web/static/tests/views/control_panel_tests.js | 41 |
2 files changed, 69 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/control_panel/search/add_new_favorite_menu.js b/addons/web/static/src/js/views/control_panel/search/add_new_favorite_menu.js index 0a2498c69df..421fec3e04b 100644 --- a/addons/web/static/src/js/views/control_panel/search/add_new_favorite_menu.js +++ b/addons/web/static/src/js/views/control_panel/search/add_new_favorite_menu.js @@ -12,6 +12,7 @@ var AddNewFavoriteMenu = Widget.extend({ events: _.extend({}, Widget.prototype.events, { 'click .o_save_favorite': '_onSaveFavoriteClick', 'click .o_add_favorite.o_menu_header': '_onMenuHeaderClick', + 'click input[type="checkbox"]': '_onCheckboxClick', 'keyup .o_save_name input': '_onKeyUp', }), /** @@ -108,6 +109,33 @@ var AddNewFavoriteMenu = Widget.extend({ //-------------------------------------------------------------------------- /** + * Additional behavior when a checkbox is clicked upon + * Namely, some checkbox are mutually exclusive + * this function allows this + * + * @private + * @param {jQueryEvent} ev + */ + _onCheckboxClick: function (ev) { + function mutuallyExclusive (elem) { + if (!elem.id) return false; + return ['use_by_default', 'share_all_users'].some(function (str) { + return elem.id.indexOf(str); + }); + } + var $checkboxes = this.$('input[type="checkbox"]'); + var currentCheckBox = ev.target; + + if (mutuallyExclusive(currentCheckBox)) { + for (var i=0; i < $checkboxes.length; i++) { + var checkbox = $checkboxes[i]; + if (checkbox !== currentCheckBox && mutuallyExclusive(checkbox)) { + checkbox.checked = false; + } + } + } + }, + /** * @private * @param {jQueryEvent} ev */ diff --git a/addons/web/static/tests/views/control_panel_tests.js b/addons/web/static/tests/views/control_panel_tests.js index f2654e55e1b..5c38c58ca45 100644 --- a/addons/web/static/tests/views/control_panel_tests.js +++ b/addons/web/static/tests/views/control_panel_tests.js @@ -416,6 +416,47 @@ QUnit.module('Views', { controlPanel.destroy(); }); + QUnit.test('Favorites Use by Default and Share are exclusive', async function (assert) { + assert.expect(11); + var controlPanel = await createControlPanel({ + model: 'partner', + arch: "<search></search>", + data: this.data, + searchMenuTypes: ['favorite'], + }); + testUtils.dom.click(controlPanel.$('.o_favorites_menu_button')); + testUtils.dom.click(controlPanel.$('button.o_add_favorite')); + var $checkboxes = controlPanel.$('input[type="checkbox"]'); + + assert.strictEqual($checkboxes.length, 2, + '2 checkboxes are present') + + assert.notOk($checkboxes[0].checked, 'Start: None of the checkboxes are checked (1)'); + assert.notOk($checkboxes[1].checked, 'Start: None of the checkboxes are checked (2)'); + + testUtils.dom.click($checkboxes.eq(0)); + assert.ok($checkboxes[0].checked, 'The first checkbox is checked'); + assert.notOk($checkboxes[1].checked, 'The second checkbox is not checked'); + + testUtils.dom.click($checkboxes.eq(1)); + assert.notOk($checkboxes[0].checked, + 'Clicking on the second checkbox checks it, and unchecks the first (1)'); + assert.ok($checkboxes[1].checked, + 'Clicking on the second checkbox checks it, and unchecks the first (2)'); + + testUtils.dom.click($checkboxes.eq(0)); + assert.ok($checkboxes[0].checked, + 'Clicking on the first checkbox checks it, and unchecks the second (1)'); + assert.notOk($checkboxes[1].checked, + 'Clicking on the first checkbox checks it, and unchecks the second (2)'); + + testUtils.dom.click($checkboxes.eq(0)); + assert.notOk($checkboxes[0].checked, 'End: None of the checkboxes are checked (1)'); + assert.notOk($checkboxes[1].checked, 'End: None of the checkboxes are checked (2)'); + + controlPanel.destroy(); + }); + QUnit.test('load filter', async function (assert) { assert.expect(1); |
