summaryrefslogtreecommitdiff
path: root/addons/web_editor/static
diff options
context:
space:
mode:
authorSamuel Degueldre <sad@odoo.com>2020-11-13 10:40:33 +0000
committerSamuel Degueldre <sad@odoo.com>2020-11-17 11:28:50 +0000
commitda8bb3238d55811658f40471b5d91b1ecad95ddc (patch)
treece8508eaf2e5c2ffe4776fc735d738ab4e493fe4 /addons/web_editor/static
parent333a9124608ff655bd9ad5e63044a5cb7ef9c636 (diff)
[FIX] web_editor: fix shape transparency color preview handling
Previously, the transparency color for shapes was not taken into account when handling the preview state transitions of the background shape snippet option. This caused strange behaviours where the shape transparency color would always get reset when it was a class color, either when changing to a different shape (expected, all shape colors should get reset) or when changing any other shape setting like other shape colors or flipping the shape (not expected). On the other hand, if the transparency color was not a class color, it would always remain untouched, when changing other shapes settings (expected) but also when changing shape type (eg Origins 01 -> Blocks 02, unwanted). This commit fixes that by cloning the entire shape container during preview, and restoring it on preview-reset. task-2380815 closes odoo/odoo#61710 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/web_editor/static')
-rw-r--r--addons/web_editor/static/src/js/editor/snippets.options.js66
1 files changed, 43 insertions, 23 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 051ab4111b2..3b1360c8951 100644
--- a/addons/web_editor/static/src/js/editor/snippets.options.js
+++ b/addons/web_editor/static/src/js/editor/snippets.options.js
@@ -3915,50 +3915,66 @@ registry.BackgroundShape = SnippetOptionWidget.extend({
* @param {function} computeShapeData function to compute the new shape data.
*/
_handlePreviewState(previewMode, computeShapeData) {
+ const target = this.$target[0];
+ const insertShapeContainer = newContainer => {
+ const shapeContainer = target.querySelector(':scope > .o_we_shape');
+ if (shapeContainer) {
+ shapeContainer.remove();
+ }
+ if (newContainer) {
+ const preShapeLayerElement = this._getLastPreShapeLayerElement();
+ if (preShapeLayerElement) {
+ $(preShapeLayerElement).after(newContainer);
+ } else {
+ this.$target.prepend(newContainer);
+ }
+ }
+ return newContainer;
+ };
+
+ let changedShape = false;
if (previewMode === 'reset') {
+ insertShapeContainer(this.prevShapeContainer);
if (this.prevShape) {
- this.$target[0].dataset.oeShapeData = this.prevShape;
+ target.dataset.oeShapeData = this.prevShape;
} else {
- delete this.$target[0].dataset.oeShapeData;
+ delete target.dataset.oeShapeData;
}
+ return;
} else {
if (previewMode === true) {
- this.prevShape = this.$target[0].dataset.oeShapeData;
+ const shapeContainer = target.querySelector(':scope > .o_we_shape');
+ this.prevShapeContainer = shapeContainer && shapeContainer.cloneNode(true);
+ this.prevShape = target.dataset.oeShapeData;
}
+ const curShapeData = target.dataset.oeShapeData || {};
const newShapeData = computeShapeData();
+ const {shape: curShape} = curShapeData;
+ changedShape = newShapeData.shape !== curShape;
this._markShape(newShapeData);
- if (previewMode === false) {
- this.prevShape = this.$target[0].dataset.oeShapeData;
- if (newShapeData.hasOwnProperty('shape')) {
- // Need to rerender for correct number of colorpickers
- this.rerender = true;
- }
+ if (previewMode === false && changedShape) {
+ // Need to rerender for correct number of colorpickers
+ this.rerender = true;
}
}
// Updates/removes the shape container as needed and gives it the
// correct background shape
- const json = this.$target[0].dataset.oeShapeData;
+ const json = target.dataset.oeShapeData;
const {shape, colors, flip = []} = json ? JSON.parse(json) : {};
- const target = this.$target[0];
let shapeContainer = target.querySelector(':scope > .o_we_shape');
if (!shape) {
- if (shapeContainer) {
- shapeContainer.remove();
- }
- return;
+ return insertShapeContainer(null);
+ }
+ // When changing shape we want to reset the shape container (for transparency color)
+ if (changedShape) {
+ shapeContainer = insertShapeContainer(null);
}
if (!shapeContainer) {
- shapeContainer = document.createElement('div');
- const preShapeLayerElement = this._getLastPreShapeLayerElement();
- if (preShapeLayerElement) {
- $(preShapeLayerElement).after(shapeContainer);
- } else {
- target.prepend(shapeContainer);
- }
+ shapeContainer = insertShapeContainer(document.createElement('div'));
target.style.position = 'relative';
+ shapeContainer.className = `o_we_shape o_${shape.replace(/\//g, '_')}`;
}
- shapeContainer.className = `o_we_shape o_${shape.replace(/\//g, '_')}`;
// Compat: remove old flip classes as flipping is now done inside the svg
shapeContainer.classList.remove('o_we_flip_x', 'o_we_flip_y');
@@ -3980,6 +3996,10 @@ registry.BackgroundShape = SnippetOptionWidget.extend({
// Remove custom bg image and let the shape class set the bg shape
$(shapeContainer).css('background-image', '');
}
+ if (previewMode === false) {
+ this.prevShapeContainer = shapeContainer.cloneNode(true);
+ this.prevShape = target.dataset.oeShapeData;
+ }
},
/**
* Overwrites shape properties with the specified data.