From 4b2656b020d3e9c2b0b1ede5fb6fa0238216a211 Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Tue, 12 Mar 2024 13:52:58 +0000 Subject: [PATCH] [FIX] web_editor: remove image to save when removing background image Since [1] when options on background images have been applied as soon as they were modified instead of on save, those options were not reset when the background was removed. This commit removes those options when the background image is removed. Steps to reproduce: - Drop a Text snippet. - Add a background image. - Remove the background image. - Save. => Save failed. [1]: https://github.com/odoo/odoo/commit/4a797f51ec9d3d378fc30033e4fda2bc1e73586c task-3794812 closes odoo/odoo#158326 X-original-commit: 23c805030abb89ca449cf430d5661d725f5801a8 Signed-off-by: Romain Derie (rde) Signed-off-by: Benoit Socias (bso) Co-authored-by: Serge Bayet --- addons/web_editor/static/src/js/editor/image_processing.js | 4 +++- addons/web_editor/static/src/js/editor/snippets.options.js | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/image_processing.js b/addons/web_editor/static/src/js/editor/image_processing.js index ee52f6ad31f..ebff1ecad2d 100644 --- a/addons/web_editor/static/src/js/editor/image_processing.js +++ b/addons/web_editor/static/src/js/editor/image_processing.js @@ -15,6 +15,8 @@ const modifierFields = [ 'originalSrc', 'resizeWidth', 'aspectRatio', + "bgSrc", + "mimetypeBeforeConversion", ]; export const isGif = (mimetype) => mimetype === 'image/gif'; @@ -598,7 +600,7 @@ export function getDataURLBinarySize(dataURL) { return dataURL.split(',')[1].length / 4 * 3; } -export const removeOnImageChangeAttrs = [...cropperDataFields, ...modifierFields, 'aspectRatio']; +export const removeOnImageChangeAttrs = [...cropperDataFields, ...modifierFields]; export default { applyModifications, 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 2f077a90135..0b769afde97 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -7973,7 +7973,11 @@ registry.BackgroundImage = SnippetOptionWidget.extend({ this.$target.addClass('oe_img_bg o_bg_img_center'); } else { delete parts.url; - this.$target.removeClass('oe_img_bg o_bg_img_center'); + this.$target[0].classList.remove( + "oe_img_bg", + "o_bg_img_center", + "o_modified_image_to_save", + ); } const combined = backgroundImagePartsToCss(parts); this.$target.css('background-image', combined);