Revision 53748
Added by Sofia Baltzi almost 6 years ago
invite.component.ts | ||
---|---|---|
21 | 21 |
private properties: EnvProperties = null; |
22 | 22 |
public email: Email; |
23 | 23 |
public body: Body; |
24 |
public recipients: string; |
|
24 | 25 |
|
25 | 26 |
private ckeditorContent: string; |
26 | 27 |
|
... | ... | |
40 | 41 |
this.properties = data.envSpecific; |
41 | 42 |
this.body = {salutation: "Dear Sir/Madame,", fromMessage: "On behalf of ", fromName: "", paragraphs: this.defaultBody, closing: "Kind regards,", signature: "OpenAIRE team"}; |
42 | 43 |
this.email = {body: "", subject: "", recipients: []}; |
44 |
this.recipients = ""; |
|
43 | 45 |
|
44 | 46 |
}); |
45 | 47 |
} |
46 | 48 |
|
47 | 49 |
public invite() { |
48 |
if (this.email.recipients != null) { |
|
49 |
this.composeEmail(); |
|
50 |
console.log(this.email.body); |
|
50 |
if (this.recipients != "") { |
|
51 |
if (this.validateEmails()) { |
|
52 |
this.composeEmail(); |
|
53 |
console.log(this.email.body); |
|
51 | 54 |
|
52 |
this._emailService.sendEmail(this.properties.sendMailUrl, this.email).subscribe( |
|
53 |
res => console.log("Mail has been sent successfully!") |
|
54 |
, |
|
55 |
error => console.log(error) |
|
56 |
); |
|
55 |
this._emailService.sendEmail(this.properties.sendMailUrl, this.email).subscribe( |
|
56 |
res => console.log("The email has been sent successfully!") |
|
57 |
, |
|
58 |
error => console.log(error) |
|
59 |
); |
|
60 |
} |
|
57 | 61 |
} |
58 | 62 |
} |
59 | 63 |
|
64 |
public validateEmails(): boolean { |
|
65 |
if (this.parseEmails()) { |
|
66 |
if (this.hasValidEmails()) { |
|
67 |
return true; |
|
68 |
} |
|
69 |
} |
|
70 |
return false; |
|
71 |
} |
|
72 |
|
|
73 |
public parseEmails(): boolean { |
|
74 |
let email = new Array<string>(); |
|
75 |
|
|
76 |
// remove spaces |
|
77 |
this.recipients = this.recipients.replace(/\s/g, ''); |
|
78 |
|
|
79 |
// remove commas |
|
80 |
email = this.recipients.split(","); |
|
81 |
|
|
82 |
// remove empty fields |
|
83 |
for (let i = 0; i < email.length; i++) { |
|
84 |
if (!(email[i] == "")) { |
|
85 |
this.email.recipients.push(email[i]); |
|
86 |
} |
|
87 |
} |
|
88 |
console.log(this.email.recipients); |
|
89 |
return true; |
|
90 |
} |
|
91 |
|
|
92 |
private hasValidEmails(): boolean { |
|
93 |
let length = this.email.recipients.length; |
|
94 |
|
|
95 |
for(let i = 0; i < length; i++) { |
|
96 |
if (!this.emailValidator(this.email.recipients[i])){ |
|
97 |
// TODO remove console message after final testing |
|
98 |
console.log("INVALID EMAIL"); |
|
99 |
return false; |
|
100 |
} |
|
101 |
} |
|
102 |
// TODO remove console message after final testing |
|
103 |
console.log("ALL EMAILS ARE VALID"); |
|
104 |
return true; |
|
105 |
} |
|
106 |
|
|
107 |
private emailValidator(email : any): boolean { |
|
108 |
if (email.match("^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$")) |
|
109 |
return true; |
|
110 |
else |
|
111 |
return false; |
|
112 |
} |
|
113 |
|
|
60 | 114 |
public composeEmail() { |
61 |
this.email.subject = "Argiro is going to tell me about the subject";
|
|
115 |
this.email.subject = "[OpenAIRE-Connect] Community_name";
|
|
62 | 116 |
this.email.body = this.formatEmailBody(); |
63 | 117 |
} |
64 | 118 |
|
Also available in: Unified diff
Check if input emails are valid and Send inviatation to multiple emails