EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
ref
Yuri Kuznetsov72120f262d35
diff --git a/client/modules/crm/src/views/dashlets/activities.js b/client/modules/crm/src/views/dashlets/activities.jsindex 74ab582d8f..457e7afd36 100644--- a/client/modules/crm/src/views/dashlets/activities.js+++ b/client/modules/crm/src/views/dashlets/activities.js@@ -28,6 +28,7 @@import BaseDashletView from 'views/dashlets/abstract/base';import MultiCollection from 'multi-collection';+import RecordModalHelper from 'helpers/record-modal';class ActivitiesDashletView extends BaseDashletView {@@ -212,20 +213,14 @@ class ActivitiesDashletView extends BaseDashletView {this.populateAttributesAssignedUser(scope, attributes);- Espo.Ui.notifyWait();+ const helper = new RecordModalHelper();- const viewName = this.getMetadata().get('clientDefs.' + scope + '.modalViews.edit') || 'views/modals/edit';-- this.createView('quickCreate', viewName, {- scope: scope,+ helper.showCreate(this, {+ entityType: scope,attributes: attributes,- }, view => {- view.render();- view.notify(false);-- this.listenToOnce(view, 'after:save', () => {+ afterSave: () => {this.actionRefresh();- });+ },});}@@ -235,20 +230,14 @@ class ActivitiesDashletView extends BaseDashletView {this.populateAttributesAssignedUser('Meeting', attributes);- Espo.Ui.notifyWait();+ const helper = new RecordModalHelper();- const viewName = this.getMetadata().get('clientDefs.Meeting.modalViews.edit') || 'views/modals/edit';-- this.createView('quickCreate', viewName, {- scope: 'Meeting',+ helper.showCreate(this, {+ entityType: 'Meeting',attributes: attributes,- }, view => {- view.render();- view.notify(false);-- this.listenToOnce(view, 'after:save', () => {+ afterSave: () => {this.actionRefresh();- });+ },});}@@ -258,20 +247,14 @@ class ActivitiesDashletView extends BaseDashletView {this.populateAttributesAssignedUser('Call', attributes);- Espo.Ui.notifyWait();-- const viewName = this.getMetadata().get('clientDefs.Call.modalViews.edit') || 'views/modals/edit';+ const helper = new RecordModalHelper();- this.createView('quickCreate', viewName, {- scope: 'Call',+ helper.showCreate(this, {+ entityType: 'Call',attributes: attributes,- }, view => {- view.render();- view.notify(false);-- this.listenToOnce(view, 'after:save', () => {+ afterSave: () => {this.actionRefresh();- });+ },});}diff --git a/client/modules/crm/src/views/record/panels/history.js b/client/modules/crm/src/views/record/panels/history.jsindex 037813e094..4f1d02a5ba 100644--- a/client/modules/crm/src/views/record/panels/history.js+++ b/client/modules/crm/src/views/record/panels/history.js@@ -28,6 +28,7 @@import ActivitiesPanelView from 'crm:views/record/panels/activities';import EmailHelper from 'email-helper';+import RecordModalHelper from 'helpers/record-modal';class HistoryPanelView extends ActivitiesPanelView {@@ -134,31 +135,25 @@ class HistoryPanelView extends ActivitiesPanelView {let relate = null;- if ('emails' in this.model.defs['links']) {+ if (this.model.hasLink('emails')) {relate = {model: this.model,- link: this.model.defs['links']['emails'].foreign,+ link: this.model.getLinkParam('emails', 'foreign'),};}- Espo.Ui.notifyWait();-- const viewName = this.getMetadata().get(`clientDefs.${scope}.modalViews.edit`) ||- 'views/modals/edit';-this.getArchiveEmailAttributes(scope, data, attributes => {- this.createView('quickCreate', viewName, {- scope: scope,- relate: relate,- attributes: attributes,- }, (view) => {- view.render();- view.notify(false);+ const helper = new RecordModalHelper();- this.listenToOnce(view, 'after:save', () => {+ helper.showCreate(this, {+ entityType: 'Email',+ attributes: attributes,+ relate: relate,+ afterSave: () => {this.collection.fetch();+this.model.trigger('after:relate');- });+ },});});}diff --git a/client/modules/crm/src/views/record/panels/tasks.js b/client/modules/crm/src/views/record/panels/tasks.jsindex 63c2700357..7fb6a85afa 100644--- a/client/modules/crm/src/views/record/panels/tasks.js+++ b/client/modules/crm/src/views/record/panels/tasks.js@@ -27,6 +27,7 @@************************************************************************/import RelationshipPanelView from 'views/record/panels/relationship';+import CreateRelatedHelper from 'helpers/record/create-related';export default class TasksRelationshipPanelView extends RelationshipPanelView {@@ -169,29 +170,9 @@ export default class TasksRelationshipPanelView extends RelationshipPanelView {link = 'tasks';}- const scope = 'Task';- const foreignLink = this.model.defs['links'][link].foreign;+ const helper = new CreateRelatedHelper(this);- Espo.Ui.notifyWait();-- const viewName = this.getMetadata().get(`clientDefs.${scope}.modalViews.edit`) ||- 'views/modals/edit';-- this.createView('quickCreate', viewName, {- scope: scope,- relate: {- model: this.model,- link: foreignLink,- }- }, (view) => {- view.render();- view.notify(false);-- this.listenToOnce(view, 'after:save', () => {- this.model.trigger(`update-related:${this.link}`);- this.model.trigger('after:relate');- });- });+ helper.process(this.model, link)}// noinspection JSUnusedGlobalSymbolsdiff --git a/client/src/helpers/record-modal.js b/client/src/helpers/record-modal.jsindex 84043977bf..1fe1e5af7b 100644--- a/client/src/helpers/record-modal.js+++ b/client/src/helpers/record-modal.js@@ -67,7 +67,9 @@ class RecordModalHelper {* model?: import('model').default,* editDisabled?: boolean,* removeDisabled?: boolean,+ * fullFormDisabled?: string,* rootUrl?: string,+ * fullFormUrl?: string,* layoutName?: string,* afterSave?: function(import('model').default, {bypassClose: boolean}),* afterDestroy?: function(import('model').default),@@ -106,6 +108,8 @@ class RecordModalHelper {rootUrl: params.rootUrl,removeDisabled: params.removeDisabled,layoutName: params.layoutName,+ fullFormDisabled: params.fullFormDisabled,+ fullFormUrl: params.fullFormUrl,};Espo.Ui.notifyWait();@@ -151,6 +155,7 @@ class RecordModalHelper {* model?: import('model').default,* rootUrl?: string,* fullFormDisabled?: boolean,+ * fullFormUrl?: string,* returnUrl?: string,* layoutName?: string,* afterSave?: function(import('model').default, {bypassClose: boolean}),@@ -182,6 +187,7 @@ class RecordModalHelper {returnUrl: params.returnUrl || this.router.getCurrentUrl(),returnDispatchParams: params.returnDispatchParams,layoutName: params.layoutName,+ fullFormUrl: params.fullFormUrl,};if (params.rootUrl) {@@ -225,6 +231,7 @@ class RecordModalHelper {* entityType: string,* rootUrl?: string,* fullFormDisabled?: boolean,+ * fullFormUrl?: string,* returnUrl?: string,* relate?: model:model~setRelateItem | model:model~setRelateItem[],* attributes?: Record.<string, *>,@@ -258,6 +265,7 @@ class RecordModalHelper {attributes: params.attributes,focusForCreate: params.focusForCreate,layoutName: params.layoutName,+ fullFormUrl: params.fullFormUrl,};if (params.rootUrl) {diff --git a/client/src/views/email/detail.js b/client/src/views/email/detail.jsindex 8565a7600a..78c95af7a2 100644--- a/client/src/views/email/detail.js+++ b/client/src/views/email/detail.js@@ -245,33 +245,26 @@ class EmailDetailView extends DetailView {attributes.originalEmailId = this.model.id;- const viewName = this.getMetadata().get('clientDefs.Lead.modalViews.edit') || 'views/modals/edit';+ const helper = new RecordModal();- Espo.Ui.notifyWait();-- this.createView('quickCreate', viewName, {- scope: 'Lead',+ const modalView = helper.showCreate(this, {+ entityType: 'Lead',attributes: attributes,- }, view => {- view.render();- view.notify(false);-- this.listenTo(view, 'before:save', () => {- this.getRecordView().blockUpdateWebSocket(true);- });-- this.listenToOnce(view, 'after:save', () => {+ afterSave: () => {this.model.fetch();+this.removeMenuItem('createContact');this.removeMenuItem('createLead');+ },+ })- view.close();- });+ this.listenTo(modalView, 'before:save', () => {+ this.getRecordView().blockUpdateWebSocket(true);});}// noinspection JSUnusedGlobalSymbols- actionCreateCase() {+ async actionCreateCase() {const attributes = {};const parentId = this.model.get('parentId');@@ -285,8 +278,7 @@ class EmailDetailView extends DetailView {if (parentType === 'Account') {attributes.accountId = parentId;attributes.accountName = parentName;- }- else if (parentType === 'Contact') {+ } else if (parentType === 'Contact') {attributes.contactId = parentId;attributes.contactName = parentName;@@ -298,8 +290,7 @@ class EmailDetailView extends DetailView {attributes.accountId = accountId;attributes.accountName = accountName || accountId;}- }- else if (parentType === 'Lead') {+ } else if (parentType === 'Lead') {attributes.leadId = parentId;attributes.leadName = parentName;}@@ -309,47 +300,34 @@ class EmailDetailView extends DetailView {attributes.name = this.model.get('name');attributes.description = this.model.get('bodyPlain') || '';- const viewName = this.getMetadata().get('clientDefs.Case.modalViews.edit') || 'views/modals/edit';+ const attachmentIds = this.model.get('attachmentsIds') || [];Espo.Ui.notifyWait();- (new Promise(resolve => {- if (!(this.model.get('attachmentsIds') || []).length) {- resolve();-- return;- }-- Espo.Ajax.postRequest(`Email/${this.model.id}/attachments/copy`, {+ if (attachmentIds.length) {+ /** @type {Record} data */+ const data = await Espo.Ajax.postRequest(`Email/${this.model.id}/attachments/copy`, {parentType: 'Case',field: 'attachments',- }).then(data => {- attributes.attachmentsIds = data.ids;- attributes.attachmentsNames = data.names;-- resolve();});- })).then(() => {- this.createView('quickCreate', viewName, {- scope: 'Case',- attributes: attributes,- }, view => {- view.render();- Espo.Ui.notify(false);+ attributes.attachmentsIds = data.ids;+ attributes.attachmentsNames = data.names;+ }- this.listenToOnce(view, 'after:save', () => {- this.model.fetch();- this.removeMenuItem('createCase');+ const helper = new RecordModal();- view.close();- });+ const modalView = await helper.showCreate(this, {+ entityType: 'Case',+ attributes: attributes,+ afterSave: () => {+ this.model.fetch();- this.listenTo(view, 'before:save', () => {- this.getRecordView().blockUpdateWebSocket(true);- });- });+ this.removeMenuItem('createCase');+ },});++ this.listenTo(modalView, 'before:save', () => this.getRecordView().blockUpdateWebSocket(true));}// noinspection JSUnusedGlobalSymbols@@ -361,43 +339,35 @@ class EmailDetailView extends DetailView {attributes.parentType = this.model.get('parentType');attributes.originalEmailId = this.model.id;- const subject = this.model.get('name');+ const subject = this.model.attributes.name;attributes.description =`[${this.translate('Email', 'scopeNames')}: ${subject}](#Email/view/${this.model.id})\n`;- const viewName = this.getMetadata().get('clientDefs.Task.modalViews.edit') || 'views/modals/edit';+ const fullFormUrl = `#Task/create?emailId=${attributes.originalEmailId}`;- Espo.Ui.notifyWait();+ const helper = new RecordModal();- this.createView('quickCreate', viewName, {- scope: 'Task',+ helper.showCreate(this, {+ entityType: 'Task',attributes: attributes,- fullFormUrl: `#Task/create?emailId=${attributes.emailId}`,- }, view => {- const recordView = view.getRecordView();-- const nameFieldView = recordView.getFieldView('name');-- let nameOptionList = [];-- if (nameFieldView && nameFieldView.params.options) {- nameOptionList = nameOptionList.concat(nameFieldView.params.options);- }-- nameOptionList.push(this.translate('replyToEmail', 'nameOptions', 'Task'));-- recordView.setFieldOptionList('name', nameOptionList);+ fullFormUrl: fullFormUrl,+ afterSave: () => {+ this.model.fetch();+ },+ beforeRender: view => {+ const nameFieldView = view.getRecordView().getFieldView('name');- view.render();+ const nameOptionList = [];- view.notify(false);+ if (nameFieldView && nameFieldView.params.options) {+ nameOptionList.push(...nameFieldView.params.options);+ }- this.listenToOnce(view, 'after:save', () => {- view.close();+ nameOptionList.push(this.translate('replyToEmail', 'nameOptions', 'Task'));- this.model.fetch();- });+ view.getRecordView().setFieldOptionList('name', nameOptionList);+ },});}@@ -449,29 +419,21 @@ class EmailDetailView extends DetailView {attributes.originalEmailId = this.model.id;- const viewName = this.getMetadata().get('clientDefs.Contact.modalViews.edit') || 'views/modals/edit';-- Espo.Ui.notifyWait();+ const helper = new RecordModal();- this.createView('quickCreate', viewName, {- scope: 'Contact',+ const modalView = helper.showCreate(this, {+ entityType: 'Contact',attributes: attributes,- }, (view) => {- view.render();-- view.notify(false);-- this.listenToOnce(view, 'after:save', () => {+ afterSave: () => {this.model.fetch();+this.removeMenuItem('createContact');this.removeMenuItem('createLead');+ },+ })- view.close();- });-- this.listenTo(view, 'before:save', () => {- this.getRecordView().blockUpdateWebSocket(true);- });+ this.listenTo(modalView, 'before:save', () => {+ this.getRecordView().blockUpdateWebSocket(true);});}