Skip to content

Commit 16ba3ee

Browse files
shsa-odoomsh-odoo
authored andcommitted
[FIX] web_editor: unstuck the UI after an image crop is denied
Steps to produce: - Drop 'Text - Image' block - Replace image by illustration - Try to crop image - A notification is displayed - Try saving The issue is ImageCrop is still not opened and we are trying to wait for image_cropper_destroyed to trigger, so here we check if ImageCrop is not opened. task-4246644 closes odoo#188577 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com> Co-authored-by: Mohammed Shekha <msh@odoo.com>
1 parent eabaa4b commit 16ba3ee

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

addons/web_editor/static/src/js/editor/snippets.options.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6602,22 +6602,27 @@ registry.ImageTools = ImageHandlerOption.extend({
66026602
const document = this.$el[0].ownerDocument;
66036603
const imageCropWrapperElement = document.createElement('div');
66046604
document.body.append(imageCropWrapperElement);
6605-
const imageCropWrapper = await attachComponent(this, imageCropWrapperElement, ImageCrop, {
6606-
rpc: this.rpc,
6607-
activeOnStart: true,
6608-
media: img,
6609-
mimetype: this._getImageMimetype(img),
6610-
});
66116605

6612-
await new Promise(resolve => {
6613-
this.$target.one('image_cropper_destroyed', async () => {
6606+
// Attach the event listener before attaching the component
6607+
const cropperPromise = new Promise(resolve => {
6608+
this.$target.one("image_cropper_destroyed", async () => {
66146609
if (isGif(this._getImageMimetype(img))) {
6615-
img.dataset[img.dataset.shape ? 'originalMimetype' : 'mimetype'] = 'image/png';
6610+
img.dataset[img.dataset.shape ? "originalMimetype" : "mimetype"] = "image/png";
66166611
}
66176612
await this._reapplyCurrentShape();
66186613
resolve();
66196614
});
66206615
});
6616+
6617+
const imageCropWrapper = await attachComponent(this, imageCropWrapperElement, ImageCrop, {
6618+
rpc: this.rpc,
6619+
activeOnStart: true,
6620+
media: img,
6621+
mimetype: this._getImageMimetype(img),
6622+
});
6623+
6624+
await cropperPromise;
6625+
66216626
imageCropWrapperElement.remove();
66226627
imageCropWrapper.destroy();
66236628
this.trigger_up('enable_loading_effect');

addons/website/static/tests/tours/media_dialog.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ wTourUtils.registerWebsitePreviewTour("website_media_dialog_external_library", {
7474
}
7575
},
7676
},
77+
{
78+
content: "Click on the first illustration image",
79+
trigger: ".o_select_media_dialog .o_we_attachment_highlight",
80+
},
81+
{
82+
content: "Select the image",
83+
trigger: "iframe .s_text_image img",
84+
},
85+
{
86+
content: "Try to crop the image",
87+
trigger: "#oe_snippets .o_we_customize_panel .o_we_user_value_widget[data-crop='true']",
88+
},
89+
{
90+
content: "Observe the crop is denied for illustration image",
91+
trigger: ".o_notification_manager .o_notification",
92+
run: () => {}, // it's a check
93+
},
94+
...wTourUtils.clickOnSave(),
7795
]);
7896

7997
wTourUtils.registerWebsitePreviewTour('website_media_dialog_icons', {

0 commit comments

Comments
 (0)