Skip to content

EspoCRM – Open Source CRM Application

ref

Yuri Kuznetsov4126b99a7be3
diff --git a/client/modules/crm/res/templates/mass-email/modals/send-test.tpl b/client/modules/crm/res/templates/mass-email/modals/send-test.tpl
deleted file mode 100644
index b114e8bc86..0000000000
--- a/client/modules/crm/res/templates/mass-email/modals/send-test.tpl
+++ /dev/null
@@ -1,20 +0,0 @@
-<div class="row">
- <div class="cell col-sm-6 form-group" data-name="users">
- <label class="control-label" data-name="users">{{translate 'users' category='links' scope='TargetList'}}</label>
- <div class="field" data-name="users">{{{users}}}</div>
- </div>
- <div class="cell col-sm-6 form-group" data-name="contacts">
- <label class="control-label" data-name="contacts">{{translate 'contacts' category='links' scope='TargetList'}}</label>
- <div class="field" data-name="contacts">{{{contacts}}}</div>
- </div>
-</div>
-<div class="row">
- <div class="cell col-sm-6 form-group" data-name="leads">
- <label class="control-label" data-name="leads">{{translate 'leads' category='links' scope='TargetList'}}</label>
- <div class="field" data-name="leads">{{{leads}}}</div>
- </div>
- <div class="cell col-sm-6 form-group" data-name="accounts">
- <label class="control-label" data-name="accounts">{{translate 'accounts' category='links' scope='TargetList'}}</label>
- <div class="field" data-name="accounts">{{{accounts}}}</div>
- </div>
-</div>
\ No newline at end of file
diff --git a/client/modules/crm/src/views/mass-email/detail.js b/client/modules/crm/src/views/mass-email/detail.js
index e43919cbf1..f271bd990b 100644
--- a/client/modules/crm/src/views/mass-email/detail.js
+++ b/client/modules/crm/src/views/mass-email/detail.js
@@ -26,29 +26,31 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
-define('crm:views/mass-email/detail', ['views/detail'], function (Dep) {
+import DetailView from 'views/detail';
+import MassEmailSendTestModalView from 'crm:views/mass-email/modals/send-test';
- return Dep.extend({
+export default class extends DetailView {
- setup: function () {
- Dep.prototype.setup.call(this);
- if (~['Draft', 'Pending'].indexOf(this.model.get('status'))) {
- if (this.getAcl().checkModel(this.model, 'edit')) {
- this.menu.buttons.push({
- 'label': 'Send Test',
- 'action': 'sendTest',
- 'acl': 'edit'
- });
- }
- }
- },
+ setup() {
+ super.setup();
- actionSendTest: function () {
- this.createView('sendTest', 'crm:views/mass-email/modals/send-test', {
- model: this.model
- }, function (view) {
- view.render();
- }, this);
- },
- });
-});
+ if (
+ ['Draft', 'Pending'].includes(this.model.attributes.status) &&
+ this.getAcl().checkModel(this.model, 'edit')
+ ) {
+ this.addMenuItem('buttons', {
+ label: 'Send Test',
+ action: 'sendTest',
+ acl: 'edit',
+ onClick: () => this.actionSendTest(),
+ });
+ }
+ }
+
+ async actionSendTest() {
+ const view = new MassEmailSendTestModalView({model: this.model});
+
+ await this.assignView('modal', view);
+ await view.render();
+ }
+}
diff --git a/client/modules/crm/src/views/mass-email/modals/send-test.js b/client/modules/crm/src/views/mass-email/modals/send-test.js
index f7f753317c..9d49bb6c07 100644
--- a/client/modules/crm/src/views/mass-email/modals/send-test.js
+++ b/client/modules/crm/src/views/mass-email/modals/send-test.js
@@ -26,140 +26,193 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
-define('crm:views/mass-email/modals/send-test', ['views/modal', 'model'], function (Dep, Model) {
-
- return Dep.extend({
-
- scope: 'MassEmail',
-
- template: 'crm:mass-email/modals/send-test',
-
- setup: function () {
- Dep.prototype.setup.call(this);
-
- this.headerText = this.translate('Send Test', 'labels', 'MassEmail');
-
- var model = new Model();
-
- model.set('usersIds', [this.getUser().id]);
-
- var usersNames = {};
-
- usersNames[this.getUser().id] = this.getUser().get('name');
- model.set('usersNames', usersNames);
-
- this.createView('users', 'views/fields/link-multiple', {
- model: model,
- selector: '.field[data-name="users"]',
- foreignScope: 'User',
- defs: {
- name: 'users',
- params: {
- }
- },
- mode: 'edit',
- });
-
- this.createView('contacts', 'views/fields/link-multiple', {
- model: model,
- selector: '.field[data-name="contacts"]',
- foreignScope: 'Contact',
- defs: {
- name: 'contacts',
- params: {
- }
- },
- mode: 'edit',
- });
-
- this.createView('leads', 'views/fields/link-multiple', {
- model: model,
- selector: '.field[data-name="leads"]',
- foreignScope: 'Lead',
- defs: {
- name: 'leads',
- params: {
- }
- },
- mode: 'edit',
- });
-
- this.createView('accounts', 'views/fields/link-multiple', {
- model: model,
- selector: '.field[data-name="accounts"]',
- foreignScope: 'Account',
- defs: {
- name: 'accounts',
- params: {
- }
- },
- mode: 'edit',
- });
-
- this.buttonList.push({
- name: 'sendTest',
- label: 'Send Test',
- style: 'danger',
- });
-
- this.buttonList.push({
- name: 'cancel',
- label: 'Cancel',
- });
- },
-
- actionSendTest: function () {
-
- var list = [];
-
- this.getView('users').fetch().usersIds.forEach(function (id) {
+import ModalView from 'views/modal';
+import Model from 'model';
+import EditForModalRecordView from 'views/record/edit-for-modal';
+import LinkMultipleFieldView from 'views/fields/link-multiple';
+
+export default class MassEmailSendTestModalView extends ModalView {
+
+ // language=Handlebars
+ templateContent = `
+ <div class="record-container no-side-margin">{{{record}}}</div>
+ `
+
+ /**
+ * @private
+ * @type {EditForModalRecordView}
+ */
+ recordView
+
+ /**
+ * @private
+ * @type {Model}
+ */
+ formModel
+
+ /**
+ * @param {{model: import('model').default}} options
+ */
+ constructor(options) {
+ super(options);
+
+ this.model = options.model;
+ }
+
+ setup() {
+ super.setup();
+
+ this.headerText = this.translate('Send Test', 'labels', 'MassEmail');
+
+ const formModel = this.formModel = new Model();
+
+ formModel.set('usersIds', [this.getUser().id]);
+
+ const usersNames = {};
+
+ usersNames[this.getUser().id] = this.getUser().get('name');
+ formModel.set('usersNames', usersNames);
+
+ this.recordView = new EditForModalRecordView({
+ model: formModel,
+ detailLayout: [
+ {
+ rows: [
+ [
+ {
+ view: new LinkMultipleFieldView({
+ name: 'users',
+ labelText: this.translate('users', 'links', 'TargetList'),
+ mode: 'edit',
+ params: {
+ entity: 'User',
+ },
+ })
+ },
+ false
+ ],
+ [
+ {
+ view: new LinkMultipleFieldView({
+ name: 'contacts',
+ labelText: this.translate('contacts', 'links', 'TargetList'),
+ mode: 'edit',
+ params: {
+ entity: 'Contact',
+ },
+ })
+ },
+ false
+ ],
+ [
+ {
+ view: new LinkMultipleFieldView({
+ name: 'leads',
+ labelText: this.translate('leads', 'links', 'TargetList'),
+ mode: 'edit',
+ params: {
+ entity: 'Lead',
+ },
+ })
+ },
+ false
+ ],
+ [
+ {
+ view: new LinkMultipleFieldView({
+ name: 'accounts',
+ labelText: this.translate('accounts', 'links', 'TargetList'),
+ mode: 'edit',
+ params: {
+ entity: 'Account',
+ },
+ })
+ },
+ false
+ ],
+ ]
+ }
+ ]
+ });
+
+ this.assignView('record', this.recordView);
+
+ this.buttonList.push({
+ name: 'sendTest',
+ label: 'Send Test',
+ style: 'danger',
+ onClick: () => this.actionSendTest(),
+ });
+
+ this.buttonList.push({
+ name: 'cancel',
+ label: 'Cancel',
+ onClick: () => this.actionClose(),
+ });
+ }
+
+ actionSendTest() {
+ const list = [];
+
+ if (Array.isArray(this.formModel.attributes.usersIds)) {
+ this.formModel.attributes.usersIds.forEach(id => {
list.push({
id: id,
- type: 'User'
+ type: 'User',
});
});
+ }
- this.getView('contacts').fetch().contactsIds.forEach(function (id) {
+ if (Array.isArray(this.formModel.attributes.contactsIds)) {
+ this.formModel.attributes.contactsIds.forEach(id => {
list.push({
id: id,
- type: 'Contact'
+ type: 'Contact',
});
});
+ }
- this.getView('leads').fetch().leadsIds.forEach(function (id) {
+ if (Array.isArray(this.formModel.attributes.leadsIds)) {
+ this.formModel.attributes.leadsIds.forEach(id => {
list.push({
id: id,
- type: 'Lead'
+ type: 'Lead',
});
});
+ }
- this.getView('accounts').fetch().accountsIds.forEach(function (id) {
+ if (Array.isArray(this.formModel.attributes.accountsIds)) {
+ this.formModel.attributes.accountsIds.forEach(id => {
list.push({
id: id,
- type: 'Account'
+ type: 'Account',
});
});
+ }
- if (list.length === 0) {
- alert(this.translate('selectAtLeastOneTarget', 'messages', 'MassEmail'));
-
- return;
- }
-
- this.disableButton('sendTest');
-
- Espo.Ajax
- .postRequest('MassEmail/action/sendTest', {
- id: this.model.id,
- targetList: list,
- })
- .then(() => {
- Espo.Ui.success(this.translate('testSent', 'messages', 'MassEmail'));
- this.close();
- })
- .catch(() => {
- this.enableButton('sendTest');
- });
- },
- });
-});
+ if (list.length === 0) {
+ Espo.Ui.error(this.translate('selectAtLeastOneTarget', 'messages', 'MassEmail'));
+
+ return;
+ }
+
+ console.log(list);
+
+ return;
+
+ this.disableButton('sendTest');
+
+ Espo.Ajax.postRequest('MassEmail/action/sendTest', {
+ id: this.model.id,
+ targetList: list,
+ })
+ .then(() => {
+ Espo.Ui.success(this.translate('testSent', 'messages', 'MassEmail'));
+
+ this.close();
+ })
+ .catch(() => {
+ this.enableButton('sendTest');
+ });
+ }
+}
diff --git a/client/modules/crm/src/views/mass-email/record/list-for-campaign.js b/client/modules/crm/src/views/mass-email/record/list-for-campaign.js
index 3f8bdccb40..d5ef716a68 100644
--- a/client/modules/crm/src/views/mass-email/record/list-for-campaign.js
+++ b/client/modules/crm/src/views/mass-email/record/list-for-campaign.js
@@ -26,24 +26,24 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
-define('crm:views/mass-email/record/list-for-campaign', ['views/record/list'], function (Dep) {
+import ListRecordView from 'views/record/list';
+import MassEmailSendTestModalView from 'crm:views/mass-email/modals/send-test';
- return Dep.extend({
+export default class extends ListRecordView {
- actionSendTest: function (data) {
- var id = data.id;
+ // noinspection JSUnusedGlobalSymbols
+ async actionSendTest(data) {
+ const id = data.id;
- var model = this.collection.get(id);
+ const model = this.collection.get(id);
- if (!model) {
- return;
- }
+ if (!model) {
+ return;
+ }
- this.createView('sendTest', 'crm:views/mass-email/modals/send-test', {
- model: model,
- }, (view) => {
- view.render();
- });
- },
- });
-});
+ const view = new MassEmailSendTestModalView({model: this.model});
+
+ await this.assignView('modal', view);
+ await view.render();
+ }
+}