[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) <rde@odoo.com>
Signed-off-by: Benoit Socias (bso) <bso@odoo.com>
Co-authored-by: Serge Bayet <seba@odoo.com>
This commit is contained in:
Benoit Socias
2024-03-21 23:02:55 +00:00
co-authored by Serge Bayet
parent 0b8010a4e6
commit 4b2656b020
2 changed files with 8 additions and 2 deletions
@@ -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,
@@ -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);