EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
ref
Yuri Kuznetsov598655ef3354
diff --git a/client/src/views/attachment/modals/select-one.js b/client/src/views/attachment/modals/select-one.jsindex 52948b07a6..6581610022 100644--- a/client/src/views/attachment/modals/select-one.js+++ b/client/src/views/attachment/modals/select-one.js@@ -28,7 +28,7 @@import ModalView from 'views/modal';-export default class extends ModalView {+export default class SelectOneAttachmentModalView extends ModalView {backdrop = true@@ -36,7 +36,8 @@ export default class extends ModalView {templateContent =`<ul class="list-group no-side-margin">{{#each viewObject.options.dataList}}- <li class="list-group-item"+ <li+ class="list-group-item"><arole="button"class="action"@@ -44,21 +45,34 @@ export default class extends ModalView {data-id="{{id}}">{{name}}</a></li>{{/each}}- </ul>+ </ul>`+ /**+ *+ * @param {{+ * fieldLabel?: string,+ * dataList: {id: string, name: string}[],+ * onSelect: function(string),+ * }} options+ */+ constructor(options) {+ super(options);++ this.options = options;+ }+setup() {this.headerText = this.translate('Select');if (this.options.fieldLabel) {- this.headerText += ': ' + this.options.fieldLabel;+ this.headerText += ' · ' + this.options.fieldLabel;}- }- // noinspection JSUnusedGlobalSymbols- actionSelect(data) {- this.trigger('select', data.id);+ this.addActionHandler('select', (e, target) => {+ this.options.onSelect(target.dataset.id);- this.remove();+ this.close();+ });}}diff --git a/client/src/views/email/detail.js b/client/src/views/email/detail.jsindex c4fa77c676..8565a7600a 100644--- a/client/src/views/email/detail.js+++ b/client/src/views/email/detail.js@@ -28,6 +28,8 @@import DetailView from 'views/detail';import EmailHelper from 'email-helper';+import RecordModal from 'helpers/record-modal';+import SelectOneAttachmentModalView from 'views/attachment/modals/select-one';class EmailDetailView extends DetailView {@@ -630,7 +632,7 @@ class EmailDetailView extends DetailView {const names = this.model.get('attachmentsNames') || {};const types = this.model.get('attachmentsTypes') || {};- const proceed = (id) => {+ const proceed = async id => {const attributes = {};if (this.model.get('accountId')) {@@ -641,29 +643,20 @@ class EmailDetailView extends DetailView {Espo.Ui.notifyWait();- Espo.Ajax.postRequest('Attachment/copy/' + id, {+ const attachment = await Espo.Ajax.postRequest(`Attachment/copy/${id}`, {relatedType: 'Document',field: 'file',- }).then((attachment) => {- attributes.fileId = attachment.id;- attributes.fileName = attachment.name;- attributes.name = attachment.name;+ })- const viewName = this.getMetadata().get('clientDefs.Document.modalViews.edit') ||- 'views/modals/edit';+ attributes.fileId = attachment.id;+ attributes.fileName = attachment.name;+ attributes.name = attachment.name;- this.createView('quickCreate', viewName, {- scope: 'Document',- attributes: attributes,- }, (view) => {- view.render();+ const helper = new RecordModal();- Espo.Ui.notify(false);-- this.listenToOnce(view, 'after:save', () => {- view.close();- });- });+ await helper.showCreate(this, {+ entityType: 'Document',+ attributes: attributes,});};@@ -683,14 +676,15 @@ class EmailDetailView extends DetailView {});});- this.createView('dialog', 'views/attachment/modals/select-one', {+ const modalView = new SelectOneAttachmentModalView({dataList: dataList,fieldLabel: this.translate('attachments', 'fields', 'Email'),- }, view => {- view.render();-- this.listenToOnce(view, 'select', proceed.bind(this));+ onSelect: id => proceed(id),});++ this.assignView('selectModal', modalView);++ modalView.render();}}