EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
ref
Yuri Kuznetsove13f79134ee1
diff --git a/client/src/views/email/fields/from-address-varchar.js b/client/src/views/email/fields/from-address-varchar.jsindex 20a9301607..b886d6b792 100644--- a/client/src/views/email/fields/from-address-varchar.js+++ b/client/src/views/email/fields/from-address-varchar.js@@ -439,7 +439,7 @@ class EmailFromAddressVarchar extends BaseFieldView {* @param {string} scope* @param {string} address*/- addToPerson(scope, address) {+ async addToPerson(scope, address) {const fromString = this.model.get('fromString') || this.model.get('fromName');let name = this.nameHash[address] || null;@@ -467,11 +467,6 @@ class EmailFromAddressVarchar extends BaseFieldView {attributes.accountName = this.model.get('accountName');}- const viewName = this.getMetadata().get(`clientDefs.${scope}.modalViews.select`) ||- 'views/modals/select-records';-- Espo.Ui.notifyWait();-const filters = {};if (name) {@@ -482,67 +477,75 @@ class EmailFromAddressVarchar extends BaseFieldView {};}- this.createView('dialog', viewName, {- scope: scope,+ const afterSave = /** import('model').default */model => {+ const nameHash = Espo.Utils.clone(this.model.get('nameHash') || {});+ const typeHash = Espo.Utils.clone(this.model.get('typeHash') || {});+ const idHash = Espo.Utils.clone(this.model.get('idHash') || {});++ idHash[address] = model.id;+ nameHash[address] = model.attributes.name;+ typeHash[address] = scope;++ this.idHash = idHash;+ this.nameHash = nameHash;+ this.typeHash = typeHash;++ const attributes = {+ nameHash: nameHash,+ idHash: idHash,+ typeHash: typeHash,+ };++ setTimeout(() => {+ this.model.set(attributes);++ if (this.model.attributes.icsContents) {+ this.model.fetch();+ }+ }, 50);+ };++ const viewName = this.getMetadata().get(`clientDefs.${scope}.modalViews.select`) ||+ 'views/modals/select-records';++ /** @type {module:views/modals/select-records~Options} */+ const options = {+ entityType: scope,createButton: false,filters: filters,- }, (view) => {- view.render();-- Espo.Ui.notify(false);-- this.listenToOnce(view, 'select', (model) => {- const afterSave = () => {- const nameHash = Espo.Utils.clone(this.model.get('nameHash') || {});- const typeHash = Espo.Utils.clone(this.model.get('typeHash') || {});- const idHash = Espo.Utils.clone(this.model.get('idHash') || {});-- idHash[address] = model.id;- nameHash[address] = model.get('name');- typeHash[address] = scope;-- this.idHash = idHash;- this.nameHash = nameHash;- this.typeHash = typeHash;-- const attributes = {- nameHash: nameHash,- idHash: idHash,- typeHash: typeHash- };-- setTimeout(() => {- this.model.set(attributes);-- if (this.model.get('icsContents')) {- this.model.fetch();- }- }, 50);- };+ onSelect: async models => {+ const model = models[0];++ if (!model.attributes.emailAddress) {+ await model.save({emailAddress: address}, {patch: true});++ afterSave(model);- if (!model.get('emailAddress')) {- model.save({- 'emailAddress': address- }, {patch: true}).then(afterSave);+ return;}- else {- model.fetch().then(() => {- const emailAddressData = model.get('emailAddressData') || [];- const item = {- emailAddress: address,- primary: emailAddressData.length === 0- };+ await model.fetch();- emailAddressData.push(item);+ const emailAddressData = [...(model.attributes.emailAddressData || [])];- model.save({- 'emailAddressData': emailAddressData- }, {patch: true}).then(afterSave);- });- }- });- });+ emailAddressData.push({+ emailAddress: address,+ primary: emailAddressData.length === 0+ });++ await model.save({emailAddressData: emailAddressData}, {patch: true});++ afterSave(model);+ }+ };++ Espo.Ui.notifyWait();++ const view = await this.createView('modal', viewName, options);++ await view.render();++ Espo.Ui.notify();}fetchSearch() {diff --git a/client/src/views/fields/link-multiple.js b/client/src/views/fields/link-multiple.jsindex ccd5329242..9a6ed3c178 100644--- a/client/src/views/fields/link-multiple.js+++ b/client/src/views/fields/link-multiple.js@@ -1089,9 +1089,6 @@ class LinkMultipleFieldView extends BaseFieldView {const orderBy = filters.orderBy || this.panelDefs.selectOrderBy;const orderDirection = filters.orderBy ? filters.order : this.panelDefs.selectOrderDirection;- /** @type {import('views/modal').default} */- let view;-/** @type {module:views/modals/select-records~Options} */const options = {entityType: this.foreignScope,@@ -1112,8 +1109,7 @@ class LinkMultipleFieldView extends BaseFieldView {},};- view = /** @type {import('views/modal').default} */- await this.createView('modal', viewName, options);+ const view = await this.createView('modal', viewName, options);await view.render();