[FIX] web_editor: fix color comparison and store normalized colors
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) <jke@openerp.com>
This commit is contained in:
@@ -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}`;
|
||||
|
||||
Reference in New Issue
Block a user