[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) <qsm@odoo.com>
This commit is contained in:
@@ -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);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user