openaire-library/utils/email/composer.ts

116 lines
5.8 KiB
TypeScript

import {Email} from "./email";
import {Body} from "./body";
export class Composer {
private static noteBodySize = "14px";
private static noteFontSize = "11px";
// TODO move to properties
private static openaireEmail = "mailto:openaire.test@gmail.com";
private static openaireAddress = "<a href='https://www.openaire.eu'>www.openaire.eu</a><br>";
private static signature = "OpenAIRE team<br>" + Composer.openaireAddress;
private static ifYouAreNotResponsible(): string {
return "If you are not responsible for this community, please "
+ "<a href=\'" + this.openaireEmail + "\'>contact us</a>. ";
}
private static manageNotificationSettings(communityId: string): string {
return "Click <a href='https://beta.admin.connect.openaire.eu/manage-user-notifications?communityId="
+ communityId + "'>here</a> to manage your notification settings. ";
}
private static youAreManagerOfTheCommunity(communityId: string, communityName: string): string {
return "You are receiving this e-mail as manager of the community "
+ "<a href='https://beta." + communityId + ".openaire.eu/'>" + communityName + "</a>. ";
}
public static composeEmailForNewManager(communityId: string, communityName: string, newCommunityManagers: any): Email {
let email: Email = new Email();
email.subject = "[OpenAIRE-Connect] " + communityName + ": Welcome new manager";
email.body = "<div style='font-size:" + this.noteBodySize + "'><p>Welcome to OpenAIRE Connect!</p>"
+ "<p>You are receiving this e-mail as you were assigned as manager of the community <a href='https://beta."
+ communityId + ".openaire.eu/'>" + communityName + "</a> dashboard. "
+ "In order to access the administration section of your community you must first login using one of the available options. "
+ "<br>The administrative rights are associated to the e-mail address, that was used to send you this message."
+ " If you login with an account associated to a different email, please <a href='mailto:helpdesk@openaire.eu'>contact us</a>"
+ " or your colleagues, that already have access to the administration tool, to update your e-mail. <br>"
+ "You can access the administration tool by clicking the \"Manage\" button that will be available in the top right corner of the dashboard."
+ "</p>"
+ this.signature
+ "<p style='font-size:" + this.noteFontSize + "'>" + this.ifYouAreNotResponsible() + "<p>"
+ "</div>";
email.recipients = newCommunityManagers;
return email;
}
public static composeEmailToInformOldManagersForTheNewOnes(communityName: string, communityId: string, firstVersionOfManagers: any, managers: any) : Email {
let email: Email = new Email();
email.subject = "[OpenAIRE-Connect] " + communityName + ": Managers list notification";
email.body = "<div style='font-size:" + this.noteBodySize + "'>"
+ "<p>There are updates in the managers list for \"" + communityName + "\" community.<br>"
+ "The list of managers is: " + managers.join(', ') + "</p>"
+ this.signature
+ "<p style='font-size:" + this.noteFontSize + "'>"
+ this.youAreManagerOfTheCommunity(communityId, communityName)
+ this.ifYouAreNotResponsible()
+ "<br>"
+ this.manageNotificationSettings(communityId)
+ "</p>"
+ "</div>";
email.recipients = firstVersionOfManagers;
return email;
}
public static composeEmailToInformManagers(communityName: string, communityId: string, managers: any): Email {
let email: Email = new Email();
email.subject = "[OpenAIRE-Connect] " + communityName + ": New subscriber notification";
email.body = "<div style='font-size" + this.noteBodySize + "'>"
+ "<p>There is a new subscriber for \"" + communityName + "\" community. Click "
+ "<a href='https://beta.admin.connect.openaire.eu/manage-subscribers?communityId="
+ communityId + "'>here</a> to manage the subscibers list. </p>"
+ this.signature
+ "<p style='font-size:" + this.noteFontSize + "'>"
+ this.youAreManagerOfTheCommunity(communityId, communityName)
+ "<br>"
+ this.manageNotificationSettings(communityId)
+ "</p>"
+ "</div>";
email.recipients = managers;
return email;
}
public static formatEmailBodyForInvitation(body: Body): string {
let fromMessageAndName = "";
if (body.fromName != "") {
fromMessageAndName = "<span>" + body.fromMessage + body.fromName + "</span>";
}
let formattedEmail = "<div style='font-size:" + this.noteBodySize + "'>"
+ body.paragraphs
+ "<p>" + body.signature + fromMessageAndName + "<br>"
+ this.openaireAddress
+ "</p>"
+ "</div>";
return formattedEmail;
}
public static initializeInvitationEmailsBody(communityId: string, communityTitle: string): string {
return '<p>You are invited to subscribe to <a href="https://beta.' + communityId + '.openaire.eu/">'
+ communityTitle + '</a> dashboard.<br>'
+ 'The purpose of this dashboard is to gather, link &amp; monitor the research results related to your community.</p>'
+ '<p>The community dashboard is part of the <a href="https://connect.openaire.eu/">OpenAIRE-Connect</a> '
+ 'project and currently is in BETA version.'
+ '</p>';
}
}