Skip to content

EspoCRM – Open Source CRM Application

Mailto helper ref. Mailto from notification.

Yurii074f2953df78
diff --git a/client/src/helpers/misc/mailto.js b/client/src/helpers/misc/mailto.js
index 5279f51f87..a1ee30f7a5 100644
--- a/client/src/helpers/misc/mailto.js
+++ b/client/src/helpers/misc/mailto.js
@@ -26,18 +26,30 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
+import {inject} from 'di';
+import Settings from 'models/settings';
+import Preferences from 'models/preferences';
+import AclManager from 'acl-manager';
+
class MailtoHelper {
/**
- * @param {import('models/settings').default} config
- * @param {import('models/preferences').default} preferences
- * @param {import('acl-manager').default} acl
+ * @type {Settings}
*/
- constructor(config, preferences, acl) {
- this.config = config;
- this.preferences = preferences;
- this.acl = acl;
- }
+ @inject(Settings)
+ config
+
+ /**
+ * @type {Preferences}
+ */
+ @inject(Preferences)
+ preferences
+
+ /**
+ * @type {AclManager}
+ */
+ @inject(AclManager)
+ acl
/**
* Whether mailto should be used.
diff --git a/client/src/views/fields/email.ts b/client/src/views/fields/email.ts
index f03640c29f..108a9ac360 100644
--- a/client/src/views/fields/email.ts
+++ b/client/src/views/fields/email.ts
@@ -485,7 +485,7 @@ class EmailFieldView<
attributes.nameHash[emailAddress] = this.model.get('name');
}
- const helper = new MailtoHelper(this.getConfig(), this.getPreferences(), this.getAcl());
+ const helper = new MailtoHelper();
if (helper.toUse()) {
document.location.href = helper.composeLink(attributes);
diff --git a/client/src/views/fields/text.ts b/client/src/views/fields/text.ts
index 4918927096..dfc4b37750 100644
--- a/client/src/views/fields/text.ts
+++ b/client/src/views/fields/text.ts
@@ -26,7 +26,6 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
-
import BaseFieldView, {BaseOptions, BaseParams, BaseViewSchema} from 'views/fields/base';
import MailtoHelper from 'helpers/misc/mailto';
import TextPreviewModalView from 'views/modals/text-preview';
@@ -570,7 +569,7 @@ class TextFieldView<
to: emailAddress,
};
- const helper = new MailtoHelper(this.getConfig(), this.getPreferences(), this.getAcl());
+ const helper = new MailtoHelper();
if (helper.toUse()) {
document.location.href = helper.composeLink(attributes);
diff --git a/client/src/views/modals/compose-email.js b/client/src/views/modals/compose-email.js
index 13623ba851..aab8a779c7 100644
--- a/client/src/views/modals/compose-email.js
+++ b/client/src/views/modals/compose-email.js
@@ -120,7 +120,7 @@ class ComposeEmailModalView extends EditModalView {
this.dialogIsHidden = false;
});
- const helper = new MailtoHelper(this.getConfig(), this.getPreferences(), this.getAcl());
+ const helper = new MailtoHelper();
if (helper.toUse()) {
this.once('after:render', () => this.actionClose());
diff --git a/client/src/views/notification/items/message.js b/client/src/views/notification/items/message.js
index 8c3341e763..1fd84afa58 100644
--- a/client/src/views/notification/items/message.js
+++ b/client/src/views/notification/items/message.js
@@ -28,6 +28,8 @@
import BaseNotificationItemView from 'views/notification/items/base';
import DOMPurify from 'dompurify';
+import MailtoHelper from 'helpers/misc/mailto';
+import Ui from 'ui';
class MessageNotificationItemView extends BaseNotificationItemView {
@@ -69,6 +71,35 @@ class MessageNotificationItemView extends BaseNotificationItemView {
.text(data.entityName);
this.createMessage();
+
+ this.addActionHandler('mailTo', (_, target) => this.mailTo(target.dataset.emailAddress));
+ }
+
+ /**
+ * @private
+ * @param {string} emailAddress
+ * @return {Promise<void>}
+ */
+ async mailTo(emailAddress) {
+ const attributes = {
+ status: 'Draft',
+ to: emailAddress,
+ };
+
+ const helper = new MailtoHelper();
+
+ if (helper.toUse()) {
+ document.location.href = helper.composeLink(attributes);
+
+ return;
+ }
+
+ Ui.notifyWait();
+
+ const view = await this.createView('dialog', 'views/modals/compose-email', {attributes: attributes});
+ await view.render();
+
+ Ui.notify();
}
}