From dc0630833b2a43373b9da45cf310039510fd2f7d Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Mon, 5 Aug 2019 15:51:20 +0000 Subject: [PATCH] [FIX] website: prevent multi checked options in the same group In the customize theme modal, if one option enabled views which were a subset of the views which are enabled by another option, both options would be checked on modal opening if all the related views were active. This is the case for the "choose an image" and the "choose a pattern" options: the first one enables a view which adds an image on the body and the second one enables the same view but also another which enables the fact that the image must be repeated. This commit solves the issue by always selecting the option enabling the most views among the checked options in a same set. opw-1958395 closes odoo/odoo#35465 Signed-off-by: Quentin Smetz (qsm) --- addons/website/static/src/js/widgets/theme.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/addons/website/static/src/js/widgets/theme.js b/addons/website/static/src/js/widgets/theme.js index 420f90da04d..355447c86a4 100644 --- a/addons/website/static/src/js/widgets/theme.js +++ b/addons/website/static/src/js/widgets/theme.js @@ -332,6 +332,34 @@ var ThemeCustomizeDialog = Dialog.extend({ _setActive: function () { var self = this; + // First enforce that all input groups have only one element checked as + // it is supposed to be (it might not be the case on initialization, for + // exemple if we had data-xmlid="A" and data-xmlid="A,B" and if A and B + // are active, the 2 related inputs would be checked). + var $radioXMLInputs = this.$inputs.filter('[type="radio"][data-xmlid]'); + var optionNames = _.uniq(_.map($radioXMLInputs, function (option) { + return option.name; + })); + _.each(optionNames, function (optionName) { + var $inputs = $radioXMLInputs.filter('[name="' + optionName + '"]:checked'); + if ($inputs.length > 1) { + $inputs.prop('checked', false); + + var maxNbXMLIDs = -1; + var $maxInput = null; + _.each($inputs, function (input) { + var $input = $(input); + var xmlID = $input.data('xmlid'); + var nbXMLIDs = xmlID ? xmlID.split(',').length : 0; + if (nbXMLIDs >= maxNbXMLIDs) { + maxNbXMLIDs = nbXMLIDs; + $maxInput = $input; + } + }); + $maxInput.prop('checked', true); + } + }); + // Look at all options to see if they are enabled or disabled var $enable = this.$inputs.filter('[data-xmlid]:checked');