From e2abbdcc594090de024cfef254367f15760e174d Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Fri, 10 Apr 2020 09:04:57 +0000 Subject: [PATCH] [FIX] web_editor: fix original not being properly set when cropping Previously, if you opened the cropper on an already cropped image, it would load the crop data for that image. If you then changed the image and cropped that new image, it would keep most of the metadata of the previous image when saving, causing any subsequent crop to show the previous original image instead of the current one. This commit fixes that by removing all crop-related jQuery data from the image, so it's considered a fresh crop and a new attachment is created. closes odoo/odoo#50066 X-original-commit: 46c08050998d0c94d8955cd23ac783f38ecb5af1 Signed-off-by: Quentin Smetz (qsm) --- addons/web_editor/static/src/js/wysiwyg/widgets/media.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js index 13c7d086aac..c717417f428 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js @@ -498,7 +498,12 @@ var FileWidget = SearchableMediaWidget.extend({ // Remove crop related attributes if (this.$media.attr('data-aspect-ratio')) { - var attrs = ['aspect-ratio', 'x', 'y', 'width', 'height', 'rotate', 'scale-x', 'scale-y', 'crop:originalSrc']; + var attrs = ['aspect-ratio', 'x', 'y', 'width', 'height', 'rotate', 'scale-x', 'scale-y']; + Object.keys(self.$media.data()).forEach(function (key) { + if (_.str.startsWith(key, 'crop:')) { + attrs.push(key); + } + }); this.$media.removeClass('o_cropped_img_to_save'); attrs.forEach(attr => { this.$media.removeData(attr);