From 7ae7f47cd7fa5f13f110ae5636268221e26bf683 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Mon, 16 Mar 2020 11:22:50 +0000 Subject: [PATCH] [FIX] web_editor: stop base 64 being saved in the DOM when recropping When saving after cropping an attachment, a new cropped attachment is created, and the temporary base64 URL is replaced by the url of the new attachment. However, when cropping an image for a second time, the original image is recropped, and the cropped image attachment that was created previously is overriden with the new data. Previously, the step that overrides the temporary base64 url with the url of the croppped attachment was not present when overriding a previously cropped attachment, meaning it would be saved as is in the DOM, and the overriden attachment would no longer have any links pointing to it. This commit fixes that by overriding the temporary base64 url both when cropping for the first time, but also for subsequent re-crops of the same image. closes odoo/odoo#47836 X-original-commit: 3b23f137a2b519b88087452fa4c33a9f97ccdf61 Signed-off-by: Quentin Smetz (qsm) --- .../static/src/js/editor/rte.summernote.js | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/rte.summernote.js b/addons/web_editor/static/src/js/editor/rte.summernote.js index 0ea828d5589..8b2a2c1d8c2 100644 --- a/addons/web_editor/static/src/js/editor/rte.summernote.js +++ b/addons/web_editor/static/src/js/editor/rte.summernote.js @@ -1083,7 +1083,7 @@ var SummernoteManager = Class.extend(mixins.EventDispatcherMixin, ServicesMixin, * @returns {Promise} */ saveCroppedImages: function ($editable) { - var defs = _.map($editable.find('.o_cropped_img_to_save'), croppedImg => { + var defs = _.map($editable.find('.o_cropped_img_to_save'), async croppedImg => { var $croppedImg = $(croppedImg); $croppedImg.removeClass('o_cropped_img_to_save'); @@ -1094,10 +1094,10 @@ var SummernoteManager = Class.extend(mixins.EventDispatcherMixin, ServicesMixin, var originalSrc = $croppedImg.data('crop:originalSrc'); var datas = $croppedImg.attr('src').split(',')[1]; - + let attachmentID = cropID; if (!cropID) { var name = originalSrc + '.crop'; - return this._rpc({ + attachmentID = await this._rpc({ model: 'ir.attachment', method: 'create', args: [{ @@ -1108,22 +1108,20 @@ var SummernoteManager = Class.extend(mixins.EventDispatcherMixin, ServicesMixin, mimetype: mimetype, url: originalSrc, // To save the original image that was cropped }], - }).then(attachmentID => { - return this._rpc({ - model: 'ir.attachment', - method: 'generate_access_token', - args: [[attachmentID]], - }).then(access_token => { - $croppedImg.attr('src', '/web/image/' + attachmentID + '?access_token=' + access_token[0]); - }); }); } else { - return this._rpc({ + await this._rpc({ model: 'ir.attachment', method: 'write', args: [[cropID], {datas: datas}], }); } + const access_token = await this._rpc({ + model: 'ir.attachment', + method: 'generate_access_token', + args: [[attachmentID]], + }); + $croppedImg.attr('src', '/web/image/' + attachmentID + '?access_token=' + access_token[0]); }); return Promise.all(defs); },