From eaf0d9f8ed92593076b6ddfaad6ca22b9571ab36 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 5 Nov 2020 16:25:46 +0000 Subject: [PATCH] [FIX] website: prevent traceback on countdown bg color reset When the layout background color was reset using the colorpicker of the countdown option, a traceback occurred. This was because the countdown widget relies on having a set color. The text and progress bar colors were working with unset colors but with inconsistent behavior. This commit fixes the traceback and makes the widget consistent: using the reset button on any color tells the countdown widget "use the color you want" and our countdown widget will simply set it to black. Thanks to @dwa-odoo and @jpr-odoo for original investigation. task-2227149 closes odoo/odoo#61682 X-original-commit: abbf88770442bded27b5e490ce3d3e1a7025dc04 Signed-off-by: Quentin Smetz (qsm) --- addons/website/static/src/snippets/s_countdown/000.js | 3 ++- .../static/src/snippets/s_countdown/options.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/addons/website/static/src/snippets/s_countdown/000.js b/addons/website/static/src/snippets/s_countdown/000.js index d8c6a87b164..8e5895a158a 100644 --- a/addons/website/static/src/snippets/s_countdown/000.js +++ b/addons/website/static/src/snippets/s_countdown/000.js @@ -13,6 +13,7 @@ const CountdownWidget = publicWidget.Widget.extend({ selector: '.s_countdown', xmlDependencies: ['/website/static/src/snippets/s_countdown/000.xml'], disabledInEditableMode: false, + defaultColor: 'rgba(0, 0, 0, 255)', /** * @override @@ -76,7 +77,7 @@ const CountdownWidget = publicWidget.Widget.extend({ if (ColorpickerWidget.isCSSColor(color)) { return color; } - return weUtils.getCSSVariableValue(color); + return weUtils.getCSSVariableValue(color) || this.defaultColor; }, /** * Gets the time difference in seconds between now and countdown due date. diff --git a/addons/website/static/src/snippets/s_countdown/options.js b/addons/website/static/src/snippets/s_countdown/options.js index 1cfab973a79..c813e5cf71a 100644 --- a/addons/website/static/src/snippets/s_countdown/options.js +++ b/addons/website/static/src/snippets/s_countdown/options.js @@ -3,6 +3,7 @@ odoo.define('website.s_countdown_options', function (require) { const core = require('web.core'); const snippetOptions = require('web_editor.snippets.options'); +const CountdownWidget = require('website.s_countdown'); const qweb = core.qweb; @@ -154,6 +155,16 @@ snippetOptions.registry.countdown = snippetOptions.SnippetOptionWidget.extend({ case 'endAction': case 'layout': return this.$target[0].dataset[methodName]; + + case 'selectDataAttribute': { + if (params.colorNames) { + // In this case, it is a colorpicker controlling a data + // value on the countdown: the default value is determined + // by the countdown public widget. + params.attributeDefaultValue = CountdownWidget.prototype.defaultColor; + } + break; + } } return this._super(...arguments); },