Skip to content

EspoCRM – Open Source CRM Application

Ref

Yurii83953ec8f6e8
diff --git a/client/modules/crm/src/views/meeting/modals/send-invitations.js b/client/modules/crm/src/views/meeting/modals/send-invitations.js
index 3e5c3fa1f2..93eefc76ca 100644
--- a/client/modules/crm/src/views/meeting/modals/send-invitations.js
+++ b/client/modules/crm/src/views/meeting/modals/send-invitations.js
@@ -26,173 +26,170 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
-define('crm:views/meeting/modals/send-invitations', ['views/modal', 'collection'], function (Dep, Collection) {
- /**
- * @module crm_views/meeting/modals/send-invitations
- */
+import Utils from 'utils';
+import ModalView from 'views/modal';
+import Collection from 'collection';
+import Ajax from 'ajax';
+
+export default class SendInvitationsModalView extends ModalView {
+
+ backdrop = true
+
+ templateContent = `
+ <div class="margin-bottom">
+ <p>{{message}}</p>
+ </div>
+ <div class="list-container">{{{list}}}</div>
+ `
+
+ data() {
+ return {
+ message: this.translate('sendInvitationsToSelectedAttendees', 'messages', 'Meeting'),
+ };
+ }
+
+ setup() {
+ this.shortcutKeys = {};
+ this.shortcutKeys['Control+Enter'] = e => {
+ if (!this.hasAvailableActionItem('send')) {
+ return;
+ }
+
+ e.preventDefault();
+
+ this.actionSend();
+ };
+
+ this.$header = $('<span>').append(
+ $('<span>')
+ .text(this.translate(this.model.entityType, 'scopeNames')),
+ ' <span class="chevron-right"></span> ',
+ $('<span>')
+ .text(this.model.get('name')),
+ ' <span class="chevron-right"></span> ',
+ $('<span>')
+ .text(this.translate('Send Invitations', 'labels', 'Meeting'))
+ );
+
+ this.addButton({
+ label: 'Send',
+ name: 'send',
+ style: 'danger',
+ disabled: true,
+ });
+
+ this.addButton({
+ label: 'Cancel',
+ name: 'cancel',
+ });
+
+ this.collection = new Collection();
+ this.collection.url = this.model.entityType + `/${this.model.id}/attendees`;
+
+ this.wait(
+ this.prepareList()
+ );
+ }
/**
- * @class
- * @name Class
- * @extends module:views/modal
- * @memberOf module:crm_views/meeting/modals/send-invitations
+ * @private
+ * @return {Promise<void>}
*/
- return Dep.extend(/** @lends module:crm_views/meeting/modals/send-invitations.Class# */{
+ async prepareList() {
+ await this.collection.fetch();
+
+ Utils.clone(this.collection.models).forEach(model => {
+ model.entityType = model.get('_scope');
+
+ if (!model.get('emailAddress')) {
+ this.collection.remove(model.id);
+ }
+ });
+
+ const view = await this.createView('list', 'views/record/list', {
+ selector: '.list-container',
+ collection: this.collection,
+ rowActionsDisabled: true,
+ massActionsDisabled: true,
+ checkAllResultDisabled: true,
+ selectable: true,
+ buttonsDisabled: true,
+ listLayout: [
+ {
+ name: 'name',
+ customLabel: this.translate('name', 'fields'),
+ notSortable: true,
+ },
+ {
+ name: 'acceptanceStatus',
+ width: 40,
+ customLabel: this.translate('acceptanceStatus', 'fields', 'Meeting'),
+ notSortable: true,
+ view: 'views/fields/enum',
+ params: {
+ options: this.model.getFieldParam('acceptanceStatus', 'options'),
+ style: this.model.getFieldParam('acceptanceStatus', 'style'),
+ },
+ },
+ ],
+ });
+
+ this.collection.models
+ .filter(model => {
+ const status = model.get('acceptanceStatus');
+
+ return !status || status === 'None';
+ })
+ .forEach(model => {
+ this.getListView().checkRecord(model.id);
+ });
- backdrop: true,
+ this.listenTo(view, 'check', () => this.controlSendButton());
- templateContent: `
- <div class="margin-bottom">
- <p>{{message}}</p>
- </div>
- <div class="list-container">{{{list}}}</div>
- `,
+ this.controlSendButton();
+ }
- data: function () {
- return {
- message: this.translate('sendInvitationsToSelectedAttendees', 'messages', 'Meeting'),
- };
- },
+ controlSendButton() {
+ this.getListView().getCheckedIds().length ?
+ this.enableButton('send') :
+ this.disableButton('send');
+ }
- setup: function () {
- Dep.prototype.setup.call(this);
+ /**
+ * @return {import('views/record/list').default}
+ */
+ getListView() {
+ return this.getView('list');
+ }
- this.shortcutKeys = {};
- this.shortcutKeys['Control+Enter'] = e => {
- if (!this.hasAvailableActionItem('send')) {
- return;
- }
+ actionSend() {
+ this.disableButton('send');
- e.preventDefault();
+ Espo.Ui.notifyWait();
- this.actionSend();
+ const targets = this.getListView().checkedList.map(id => {
+ return {
+ entityType: this.collection.get(id).entityType,
+ id: id,
};
-
- this.$header = $('<span>').append(
- $('<span>')
- .text(this.translate(this.model.entityType, 'scopeNames')),
- ' <span class="chevron-right"></span> ',
- $('<span>')
- .text(this.model.get('name')),
- ' <span class="chevron-right"></span> ',
- $('<span>')
- .text(this.translate('Send Invitations', 'labels', 'Meeting'))
- );
-
- this.addButton({
- label: 'Send',
- name: 'send',
- style: 'danger',
- disabled: true,
- });
-
- this.addButton({
- label: 'Cancel',
- name: 'cancel',
+ });
+
+ Ajax
+ .postRequest(`${this.model.entityType}/action/sendInvitations`, {
+ id: this.model.id,
+ targets: targets,
+ })
+ .then(result => {
+ result ?
+ Espo.Ui.success(this.translate('Sent')) :
+ Espo.Ui.warning(this.translate('nothingHasBeenSent', 'messages', 'Meeting'));
+
+ this.trigger('sent');
+
+ this.close();
+ })
+ .catch(() => {
+ this.enableButton('send');
});
-
- this.collection = new Collection();
- this.collection.url = this.model.entityType + `/${this.model.id}/attendees`;
-
- this.wait(
- this.collection.fetch()
- .then(() => {
- Espo.Utils.clone(this.collection.models).forEach(model => {
- model.entityType = model.get('_scope');
-
- if (!model.get('emailAddress')) {
- this.collection.remove(model.id);
- }
- });
-
- return this.createView('list', 'views/record/list', {
- selector: '.list-container',
- collection: this.collection,
- rowActionsDisabled: true,
- massActionsDisabled: true,
- checkAllResultDisabled: true,
- selectable: true,
- buttonsDisabled: true,
- listLayout: [
- {
- name: 'name',
- customLabel: this.translate('name', 'fields'),
- notSortable: true,
- },
- {
- name: 'acceptanceStatus',
- width: 40,
- customLabel: this.translate('acceptanceStatus', 'fields', 'Meeting'),
- notSortable: true,
- view: 'views/fields/enum',
- params: {
- options: this.model.getFieldParam('acceptanceStatus', 'options'),
- style: this.model.getFieldParam('acceptanceStatus', 'style'),
- },
- },
- ],
- })
- })
- .then(view => {
- this.collection.models
- .filter(model => {
- let status = model.get('acceptanceStatus');
-
- return !status || status === 'None';
- })
- .forEach(model => {
- this.getListView().checkRecord(model.id);
- });
-
- this.listenTo(view, 'check', () => this.controlSendButton());
-
- this.controlSendButton();
- })
- );
- },
-
- controlSendButton: function () {
- this.getListView().checkedList.length ?
- this.enableButton('send') :
- this.disableButton('send');
- },
-
- /**
- * @return {module:views/record/list}
- */
- getListView: function () {
- return this.getView('list');
- },
-
- actionSend: function () {
- this.disableButton('send');
-
- Espo.Ui.notifyWait();
-
- let targets = this.getListView().checkedList.map(id => {
- return {
- entityType: this.collection.get(id).entityType,
- id: id,
- };
- });
-
- Espo.Ajax
- .postRequest(this.model.entityType + '/action/sendInvitations', {
- id: this.model.id,
- targets: targets,
- })
- .then(result => {
- result ?
- Espo.Ui.success(this.translate('Sent')) :
- Espo.Ui.warning(this.translate('nothingHasBeenSent', 'messages', 'Meeting'));
-
- this.trigger('sent');
-
- this.close();
- })
- .catch(() => {
- this.enableButton('send');
- });
- },
- });
-});
+ }
+}