wysiwyg fix paste upload duplicate

This commit is contained in:
Yuri Kuznetsov
2022-05-24 16:08:48 +03:00
parent 280a1a9313
commit fe15eeeac7
+29 -71
View File
@@ -446,40 +446,17 @@ define('views/fields/wysiwyg', ['views/fields/text', 'lib!Summernote'], function
keyMap: keyMap,
callbacks: {
onImageUpload: (files) => {
var file = files[0];
let file = files[0];
this.notify('Uploading...');
Espo.Ui.notify(this.translate('Uploading...'));
this.getModelFactory().create('Attachment', (attachment) => {
var fileReader = new FileReader();
this.uploadInlineAttachment(file)
.then(attachment => {
let url = '?entryPoint=attachment&id=' + attachment.id;
this.$summernote.summernote('insertImage', url);
fileReader.onload = (e) => {
attachment.set('name', file.name);
attachment.set('type', file.type);
attachment.set('role', 'Inline Attachment');
attachment.set('global', true);
attachment.set('size', file.size);
if (this.model.id) {
attachment.set('relatedId', this.model.id);
}
attachment.set('relatedType', this.model.name);
attachment.set('file', e.target.result);
attachment.set('field', this.name);
attachment
.save()
.then(() => {
let url = '?entryPoint=attachment&id=' + attachment.id;
this.$summernote.summernote('insertImage', url);
Espo.Ui.notify(false);
});
};
fileReader.readAsDataURL(file);
});
Espo.Ui.notify(false);
});
},
onBlur: () => {
this.trigger('change');
@@ -523,55 +500,36 @@ define('views/fields/wysiwyg', ['views/fields/text', 'lib!Summernote'], function
this.$toolbar = this.$el.find('.note-toolbar');
this.$area = this.$el.find('.note-editing-area');
},
this.$area.on('paste', (e) => {
var items = e.originalEvent.clipboardData.items;
if (!items) {
return;
}
for (var i = 0; i < items.length; i++) {
if (!~items[i].type.indexOf('image')) {
continue;
}
let file = items[i].getAsFile();
e.preventDefault();
e.stopPropagation();
uploadInlineAttachment: function (file) {
return new Promise((resolve, reject) => {
this.getModelFactory().create('Attachment', attachment => {
let fileReader = new FileReader();
fileReader.onload = e => {
this.getModelFactory().create('Attachment', attachment => {
attachment.set('name', file.name);
attachment.set('type', file.type);
attachment.set('role', 'Inline Attachment');
attachment.set('global', true);
attachment.set('size', file.size);
fileReader.onload = (e) => {
attachment.set('name', file.name);
attachment.set('type', file.type);
attachment.set('role', 'Inline Attachment');
attachment.set('global', true);
attachment.set('size', file.size);
if (this.model.id) {
attachment.set('relatedId', this.model.id);
}
if (this.model.id) {
attachment.set('relatedId', this.model.id);
}
attachment.set('relatedType', this.model.name);
attachment.set('file', e.target.result);
attachment.set('field', this.name);
attachment.set('relatedType', this.model.name);
attachment.set('file', e.target.result);
attachment.set('field', this.name);
attachment
.save()
.then(() => {
let url = '?entryPoint=attachment&id=' + attachment.id;
this.$summernote.summernote('insertImage', url);
Espo.Ui.notify(false);
});
});
attachment
.save()
.then(() => resolve(attachment))
.catch(() => reject());
};
fileReader.readAsDataURL(file);
}
});
});
},