From 6b9183a322af10ecb38758b91ebf3e0e7ea04654 Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Fri, 29 Oct 2021 12:52:23 +0000 Subject: [PATCH] [FIX] website: accept default template key in dynamic snippets Before this commit the "first" template key was selected by default before the default options were being considered. Because of this, setting a specific default template key was always ignored since a template was already selected. After this commit the widget keeps track of which value is actually a default one, allowing for setting a specific default for the template key. task-2680578 closes odoo/odoo#80207 X-original-commit: 84130ffb5c7f728e7e61d6979d78c496c473947e Signed-off-by: Quentin Smetz (qsm) --- .../static/src/snippets/s_dynamic_snippet/options.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/website/static/src/snippets/s_dynamic_snippet/options.js b/addons/website/static/src/snippets/s_dynamic_snippet/options.js index 82f2ccb51eb..f1f7cde19ff 100644 --- a/addons/website/static/src/snippets/s_dynamic_snippet/options.js +++ b/addons/website/static/src/snippets/s_dynamic_snippet/options.js @@ -18,6 +18,8 @@ const dynamicSnippetOptions = options.Class.extend({ // name of the model of the currently selected filter, used to fetch templates this.currentModelName = undefined; this.dynamicFilterTemplates = {}; + // Indicates that some current options are a default selection. + this.isOptionDefault = {}; }, /** * @@ -170,6 +172,7 @@ const dynamicSnippetOptions = options.Class.extend({ const selectedFilterId = this.$target.get(0).dataset['filterId']; if (!this.dynamicFilters[selectedFilterId]) { this.$target.get(0).dataset['filterId'] = dynamicFilters[0].id; + this.isOptionDefault['filterId'] = true; } } } @@ -206,6 +209,7 @@ const dynamicSnippetOptions = options.Class.extend({ const selectedTemplateId = this.$target.get(0).dataset['templateKey']; if (!this.dynamicFilterTemplates[selectedTemplateId]) { this.$target.get(0).dataset['templateKey'] = dynamicFilterTemplates[0].key; + this.isOptionDefault['templateKey'] = true; setTimeout(() => { this._templateUpdated(dynamicFilterTemplates[0].key, selectedTemplateId); this._refreshPublicWidgets(); @@ -281,8 +285,13 @@ const dynamicSnippetOptions = options.Class.extend({ * @private */ _setOptionValue: function (optionName, value) { - if (this.$target.get(0).dataset[optionName] === undefined) { + const selectedTemplateId = this.$target.get(0).dataset['templateKey']; + if (this.$target.get(0).dataset[optionName] === undefined || this.isOptionDefault[optionName]) { this.$target.get(0).dataset[optionName] = value; + this.isOptionDefault[optionName] = false; + } + if (optionName === 'templateKey') { + this._templateUpdated(value, selectedTemplateId); } }, });