Mailto helper ref. Mailto from notification.

This commit is contained in:
Yurii
2026-06-02 12:28:53 +03:00
parent 568bf1e17f
commit 074f2953df
5 changed files with 54 additions and 12 deletions

View File

@@ -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.

View File

@@ -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);

View File

@@ -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);

View File

@@ -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());

View File

@@ -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();
}
}