Project

General

Profile

1
import {Email} from "./email";
2
import {Body} from "./body";
3
import {ContactForm} from "./contact-form";
4

    
5
export class Composer {
6
  private static noteBodySize = "14px";
7
  private static noteFontSize = "11px";
8

    
9
  // TODO move to properties
10
  private static openaireEmail = "mailto:openaire.test@gmail.com";
11
  private static subjectPrefix = "[OpenAIRE-Connect] ";
12
  private static closing = "OpenAIRE team"
13
  private static openaireAddress = "<a href='https://www.openaire.eu'>www.openaire.eu</a><br>";
14
  private static signature =  Composer.closing + "<br>" + Composer.openaireAddress;
15

    
16
  private static ifYouAreNotResponsible(): string {
17
      return "If you are not responsible for this community, please "
18
              + "<a href=\'" + this.openaireEmail + "\'>contact us</a>. ";
19
  }
20

    
21
  private static manageNotificationSettings(communityId: string): string {
22
      return "Click  <a href='https://beta.admin.connect.openaire.eu/manage-user-notifications?communityId="
23
              + communityId + "'>here</a> to manage your notification settings. ";
24
  }
25

    
26
  private static youAreManagerOfTheCommunity(communityId: string, communityName: string): string {
27
      return "You are receiving this e-mail as manager of the community "
28
              + "<a href='https://beta." + communityId + ".openaire.eu/'>" + communityName + "</a>. ";
29
  }
30

    
31
  public static composeEmailForNewManager(communityId: string, communityName: string, newCommunityManagers: any): Email {
32
      let email: Email = new Email();
33

    
34
      email.subject = this.subjectPrefix + communityName + ": Welcome new manager";
35
      email.body = "<div style='font-size:" + this.noteBodySize + "'><p>Welcome to OpenAIRE Connect!</p>"
36
                    + "<p>You are receiving this e-mail as you were assigned as manager of the community  <a href='https://beta."
37
                    + communityId + ".openaire.eu/'>" + communityName + "</a> dashboard. "
38
                    + "In order to access the administration section of your community you must first login using one of the available options. "
39
                    + "<br>The administrative rights are associated to the e-mail address, that was used to send you this message."
40
                    + " If you login with an account associated to a different email, please  <a href='mailto:helpdesk@openaire.eu'>contact us</a>"
41
                    + " or your colleagues, that already have access to the administration tool, to update your e-mail. <br>"
42
                    + "You can access the administration tool by clicking the \"Manage\" button that will be available in the top right corner of the dashboard."
43
                    + "</p>"
44
                    + this.signature
45
                    + "<p style='font-size:" + this.noteFontSize + "'>" + this.ifYouAreNotResponsible() + "<p>"
46
                    + "</div>";
47
      email.recipients = newCommunityManagers;
48

    
49
      return email;
50
  }
51

    
52
  public static composeEmailForNewCommunity(contactForm: ContactForm, admins: any): Email {
53
    let email: Email = new Email();
54

    
55
    email.subject = "RCD: Request for new community";
56
    email.body = "<div style='font-size:" + this.noteBodySize + "'>"
57
               + "<span><b>Name</b>: " + contactForm.name + "</span><br>"
58
               + "<span><b>Surname</b>: " + contactForm.surname + "</span><br>"
59
               + "<span><b>Email</b>: " + contactForm.email + "</span><br>"
60
               + "<span><b>Affiliation</b>: " + contactForm.affiliation + "</span><br>"
61
               + "<span><b>Community Name</b>: " + contactForm.community + "</span>"
62
               + "<p>" + contactForm.message + "</p>"
63
               + "</div>";
64
    email.recipients = admins;
65
    return email;
66
  }
67

    
68
  public static composeEmailToInformOldManagersForTheNewOnes(communityName: string, communityId: string, firstVersionOfManagers: any, managers: any) : Email {
69
      let email: Email = new Email();
70

    
71
      email.subject = this.subjectPrefix + communityName + ": Managers list notification";
72
      email.body = "<div style='font-size:" + this.noteBodySize + "'>"
73
                    + "<p>There are updates in the managers list for \"" + communityName + "\" community.<br>"
74
                    + "The list of managers is: " + managers.join(', ') + "</p>"
75
                    + this.signature
76
                    + "<p style='font-size:" + this.noteFontSize + "'>"
77
                    + this.youAreManagerOfTheCommunity(communityId, communityName)
78
                    + this.ifYouAreNotResponsible()
79
                    + "<br>"
80
                    + this.manageNotificationSettings(communityId)
81
                    + "</p>"
82
                    + "</div>";
83
      email.recipients = firstVersionOfManagers;
84

    
85
      return email;
86
  }
87

    
88
  public static composeEmailToInformManagers(communityName: string, communityId: string, managers: any, subscriberMail: any): Email {
89
    let email: Email = new Email();
90

    
91
    email.subject = this.subjectPrefix + communityName + ": New subscriber notification";
92
    email.body = "<div style='font-size" + this.noteBodySize + "'>"
93
                 + "<p>There is a new subscriber ("+subscriberMail+") for \"" + communityName + "\" community. Click  "
94
                 + "<a href='https://beta.admin.connect.openaire.eu/manage-subscribers?communityId="
95
                 + communityId + "'>here</a> to manage the subscribers list. </p>"
96
                 + this.signature
97
                 + "<p style='font-size:" + this.noteFontSize + "'>"
98
                 + this.youAreManagerOfTheCommunity(communityId, communityName)
99
                 + "<br>"
100
                 + this.manageNotificationSettings(communityId)
101
                 + "</p>"
102
                 + "</div>";
103
    email.recipients = managers;
104

    
105
    return email;
106
  }
107

    
108
  public static formatEmailBodyForInvitation(body: Body): string {
109
    let fromMessageAndName = "";
110

    
111
    if (body.fromName != "") {
112
      fromMessageAndName = "<span>" + body.fromMessage + body.fromName + "</span>";
113
    }
114

    
115
    let formattedEmail = "<div style='font-size:" + this.noteBodySize + "'>"
116
                         + body.paragraphs
117
                         + "<p>" + body.signature + fromMessageAndName + "<br>"
118
                         + this.openaireAddress
119
                         + "</p>"
120
                         + "</div>";
121

    
122
    return formattedEmail;
123
  }
124

    
125
  public static initializeInvitationsBody(communityId: string, communityTitle: string, fullname: string): Body {
126
    let body: Body = new Body();
127
    let defaultMainBody = '<p>You are invited to subscribe to <a href="https://beta.' + communityId + '.openaire.eu/">'
128
                          + communityTitle + '</a> dashboard.<br>'
129
                          + 'The purpose of this dashboard  is to gather, link &amp; monitor the research results related to your community.</p>'
130
                          + '<p>The community dashboard is part of the <a href="https://connect.openaire.eu/">OpenAIRE-Connect</a> '
131
                          + 'project and currently is in BETA version.'
132
                          + '</p>';
133

    
134
    return body = {fromMessage: ", on behalf of ", fromName: fullname, paragraphs: defaultMainBody, signature: this.closing, note: ""};
135
  }
136

    
137
  public static initializeInvitationsEmail(communityTitle: string) {
138
    let email: Email = new Email();
139

    
140
    return email = {body: "", subject: this.subjectPrefix + communityTitle, recipients: []};
141
  }
142
}
(2-2/6)