From 469bacb91fb37fefb9071aeb969f7fd166ba8260 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Fri, 18 Sep 2020 11:35:49 +0000 Subject: [PATCH] [FIX] web_editor: fix color comparison and store normalized colors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, shape colors were stored in non-normalized form (eg, would use the color's name if it was a palette color), this caused some issues if you chose a palette color for a shape, then changed the palette: the wrong color would appear in the color picker because it would look use the color of the current palette instead of the color that was actually chosen. This commit also normalizes the case of color strings before comparing them, as this was causing some colors to be considered non-default because of different capitalization. closes odoo/odoo#58180 X-original-commit: cc8589f74d69816357cb614933358000166fa161 Signed-off-by: Jérémy Kersten (jke) --- .../web_editor/static/src/js/editor/snippets.options.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index 1a0e8d34935..fe99064abaf 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -3703,7 +3703,7 @@ registry.BackgroundShape = SnippetOptionWidget.extend({ this._handlePreviewState(previewMode, () => { const {colorName} = params; const {colors: previousColors} = this._getShapeData(); - const newColor = widgetValue || this._getDefaultColors()[colorName]; + const newColor = normalizeColor(widgetValue) || this._getDefaultColors()[colorName]; const newColors = Object.assign(previousColors, {[colorName]: newColor}); return {colors: newColors}; }); @@ -3741,7 +3741,7 @@ registry.BackgroundShape = SnippetOptionWidget.extend({ const {shape, colors: customColors} = this._getShapeData(); const colors = Object.assign(this._getDefaultColors(), customColors); const color = shape && colors[params.colorName]; - return color ? normalizeColor(color) : ''; + return color || ''; } case 'flipX': { return this.$target.find('> .o_we_shape.o_we_flip_x').length !== 0; @@ -3869,7 +3869,7 @@ registry.BackgroundShape = SnippetOptionWidget.extend({ const defaultColors = this._getDefaultColors(); const shapeData = Object.assign(this._getShapeData(), newData); const areColorsDefault = Object.entries(shapeData.colors).every(([colorName, colorValue]) => { - return colorValue === defaultColors[colorName]; + return colorValue.toLowerCase() === defaultColors[colorName].toLowerCase(); }); if (areColorsDefault) { delete shapeData.colors; @@ -3902,7 +3902,7 @@ registry.BackgroundShape = SnippetOptionWidget.extend({ } const queryString = Object.entries(colors) .map(([colorName, colorValue]) => { - const encodedCol = encodeURIComponent(normalizeColor(colorValue)); + const encodedCol = encodeURIComponent(colorValue); return `${colorName}=${encodedCol}`; }).join('&'); return `/web_editor/shape/${shape}.svg?${queryString}`;