From fd8d6cb393ff4ca077bcfad3b3fa560eed0ba9b2 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Wed, 12 Sep 2018 17:21:26 +0200 Subject: [PATCH] [FIX] website: make theme customization modal multi-faster Since the recent fixes on multi website, the customization modal is restored but is a lot slower the first time we use it (around 20sec to save an option on my machine). This was because when we change an option, all the others options are sent to the server to be (re-)saved and, on the first time, the multi-website system has to duplicate them all to make them website-specific. Now, we only enable/disable views which are modified by the user. --- addons/website/static/src/js/widgets/theme.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/addons/website/static/src/js/widgets/theme.js b/addons/website/static/src/js/widgets/theme.js index 5cef69414ba..16e99de52e7 100644 --- a/addons/website/static/src/js/widgets/theme.js +++ b/addons/website/static/src/js/widgets/theme.js @@ -289,7 +289,7 @@ var ThemeCustomizeDialog = Dialog.extend({ this.$modal.addClass('o_theme_customize_loading'); var bodyCustomImageXMLID = 'option_custom_body_image'; - var $inputBodyCustomImage = $inputs.filter('[data-xmlid*="website.' + bodyCustomImageXMLID + '"]'); + var $inputBodyCustomImage = $inputs.filter('[data-xmlid*="website.' + bodyCustomImageXMLID + '"]:checked'); if (!$inputBodyCustomImage.length) { return $.when(); } @@ -439,8 +439,8 @@ var ThemeCustomizeDialog = Dialog.extend({ var $options = $option; var checked = $option.is(':checked'); - // If it was enabled, enable/disable the related input (see data-enable, data-disable) - // and retain the ones that actually changed + // If it was enabled, enable/disable the related input (see data-enable, + // data-disable) and retain the ones that actually changed if (checked) { var $inputs; // Input to enable @@ -452,10 +452,16 @@ var ThemeCustomizeDialog = Dialog.extend({ $options = $options.add($inputs.filter(':checked')); $inputs.prop('checked', false); } + var optionNames = _.uniq(_.map($options, function (option) { + return option.name; + })); + $options = this.$inputs.filter(function (i, input) { + return _.contains(optionNames, input.name); + }); // Look at all options to see if they are enabled or disabled - var $enable = this.$inputs.filter('[data-xmlid]:checked'); - var $disable = this.$inputs.filter('[data-xmlid]:not(:checked)'); + var $enable = $options.filter('[data-xmlid]:checked'); + var $disable = $options.filter('[data-xmlid]:not(:checked)'); this._setActive();