-
Notifications
You must be signed in to change notification settings - Fork 23.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] web_editor: create attachment on _reapplyCurrentShape() call #164699
base: 15.0
Are you sure you want to change the base?
[FIX] web_editor: create attachment on _reapplyCurrentShape() call #164699
Conversation
Note: Adapt the version 17.0 and more specifically this commit |
Steps to reproduce the bug: - Add an image on the website. - Add a shape on the image. - Save and edit. - Click on the cropping option but then outside of the cropper so you do not actually crop the image (the image does not have the `o_we_image_cropped` class). - Save. -> The image has raw data as `src` and no attachment has been created for the image. The problem comes from the `_reapplyCurrentShape()` call at the `image_cropper_destroyed` event interception. Indeed, the current shape of the image is being re applied on the image (so the image src is transformed to raw data) but the `o_modifed_image_to_save` class is not added on the image. Due to it, no attachment linked to the "modified" image is created at the editor save. To solve the problem, the `o_modifed_image_to_save` class is added on the image at the `_reapplyCurrentShape()` call. task-3916313
8f32b4a
to
f517ea4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@loco-odoo The diff LGTM 👍, But I think there is a way to optimize this fix even more:
Actually, the use of .o_modified_image_to_save
will force the creation of a new attachment for technically the same image every time we cancel the crop.
The idea here is to simply keep a copy of the image src
"before the crop", and add it back when the crop widget is destroyed (if the image is not cropped)… Something like (To test 👍):
async crop() {
...
const srcBeforeCrop = this.$target[0].getAttribute("src");
new weWidgets.ImageCropWidget(this, this.$target[0]).appendTo(this.options.wysiwyg.odooEditor.document.body);
await new Promise(resolve => {
this.$target.one('image_cropper_destroyed', async () => {
await this._reapplyCurrentShape();
if (!this._isCropped()) {
this.$target[0].src = srcBeforeCrop;
}
resolve();
});
});
...
},
Also, the second .add("o_modified_image_to_save")
of _reapplyCurrentShape()
won't be needed on resetCrop()
since it was already handled by the ImageCropWidget
> reset()
> _save()
.
What do you think ?
@xO-Tx Indeed, we could try to not create an attachment in this case 👍 However, I think that the
-> The image will have raw data as In this case, I think that what we want is to know if the image has been cropped by the widget that triggered the async crop() {
...
const srcBeforeCrop = this.$target[0].getAttribute("src");
new weWidgets.ImageCropWidget(this, this.$target[0]).appendTo(this.options.wysiwyg.odooEditor.document.body);
await new Promise(resolve => {
this.$target.one('image_cropper_destroyed', async () => {
if (!this.$target[0].classList.contains("image_cropped_saved")) {
// If the image has not been modified by the cropper, reset
// the target to its src before a cropping has been applied.
this.$target[0].src = srcBeforeCrop;
} else {
this.$target[0].classList.remove("image_cropped_saved");
await this._reapplyCurrentShape();
}
resolve();
});
});
...
}, What do you think?
I agree with you, it is not needed in this case, however, I still think that the |
Steps to reproduce the bug:
o_we_image_cropped
class).-> The image has raw data as
src
and no attachment has been created for the image.The problem comes from the
_reapplyCurrentShape()
call at theimage_cropper_destroyed
event interception. Indeed, the current shape of the image is being re applied on the image (so the image src is transformed to raw data) but theo_modifed_image_to_save
class is not added on the image. Due to it, no attachment linked to the "modified" image is created at the editor save. To solve the problem, theo_modifed_image_to_save
class is added on the image at the_reapplyCurrentShape()
call.task-3916313