Check if input emails are valid and Send inviatation to multiple emails

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@53748 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
sofia.baltzi 2018-11-14 15:05:51 +00:00
parent 0c27a2c17e
commit ebed6e2b83
3 changed files with 76 additions and 18 deletions

View File

@ -170,4 +170,4 @@
</div>
<invite longView=false></invite>
<invite [longView]=false></invite>

View File

@ -25,13 +25,17 @@
<tr>
<td for="email.recipients[0]" class="uk-text-bold uk-text-right">To <span class="uk-text-danger uk-text-bold">*</span> :</td>
<td class="uk-text-left">
<!-- <div *ngIf="!email.recipients[1].match('^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$')"
class="uk-width-large uk-text-danger uk-text-small uk-margin-top"> Please add a valid email. </div> -->
<!-- <div *ngIf="email.recipients && email.recipients[0] != ''">
<div >
</div>
<div *ngFor='let emailsss of email.recipients.split(,), let index; trackBy:trackByFn'> -->
<!-- <div *ngIf="!email[i].match('^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$')"
class="uk-width-large uk-text-danger uk-text-small uk-margin-top"> Please add a valid email. </div> -->
<!-- </div>
</div> -->
<input placeholder="email" type="text"
class="form-control uk-input uk-width-large@l uk-width-medium@s" [(ngModel)] = "email.recipients[0]" id="recipients"
required >
{{email.recipients}}
class="form-control uk-input uk-width-large@l uk-width-medium@s" [(ngModel)] = "recipients" id="recipients"
required>
<div class="uk-width-medium uk-text-muted uk-text-small style=display:none">separate multiple emails with a comma</div>
</td>
@ -69,7 +73,7 @@
<!--[config]="{uiColor: '#99000'}"-->
<!--(blur)="onBlur($event)"-->
<!--(change)="onChange($event)"-->
</ckeditor>
</ckeditor>
<!-- <textarea type="text"
class="form-control uk-input uk-width-large@l uk-width-medium@s" [(ngModel)] = "email.body" id="message">
</textarea> -->
@ -131,7 +135,7 @@
</div>
</div>
</div>
<div *ngIf="longView =='false'">
<div *ngIf="longView == false">
<div class="uk-width-large@m uk-width-1-1@s">
<div class="uk-card uk-card-default uk-card-body">
<div class="uk-text-center uk-text-large">

View File

@ -21,6 +21,7 @@ export class InviteComponent implements OnInit {
private properties: EnvProperties = null;
public email: Email;
public body: Body;
public recipients: string;
private ckeditorContent: string;
@ -40,25 +41,78 @@ export class InviteComponent implements OnInit {
this.properties = data.envSpecific;
this.body = {salutation: "Dear Sir/Madame,", fromMessage: "On behalf of ", fromName: "", paragraphs: this.defaultBody, closing: "Kind regards,", signature: "OpenAIRE team"};
this.email = {body: "", subject: "", recipients: []};
this.recipients = "";
});
}
public invite() {
if (this.email.recipients != null) {
this.composeEmail();
console.log(this.email.body);
if (this.recipients != "") {
if (this.validateEmails()) {
this.composeEmail();
console.log(this.email.body);
this._emailService.sendEmail(this.properties.sendMailUrl, this.email).subscribe(
res => console.log("Mail has been sent successfully!")
,
error => console.log(error)
);
this._emailService.sendEmail(this.properties.sendMailUrl, this.email).subscribe(
res => console.log("The email has been sent successfully!")
,
error => console.log(error)
);
}
}
}
public validateEmails(): boolean {
if (this.parseEmails()) {
if (this.hasValidEmails()) {
return true;
}
}
return false;
}
public parseEmails(): boolean {
let email = new Array<string>();
// remove spaces
this.recipients = this.recipients.replace(/\s/g, '');
// remove commas
email = this.recipients.split(",");
// remove empty fields
for (let i = 0; i < email.length; i++) {
if (!(email[i] == "")) {
this.email.recipients.push(email[i]);
}
}
console.log(this.email.recipients);
return true;
}
private hasValidEmails(): boolean {
let length = this.email.recipients.length;
for(let i = 0; i < length; i++) {
if (!this.emailValidator(this.email.recipients[i])){
// TODO remove console message after final testing
console.log("INVALID EMAIL");
return false;
}
}
// TODO remove console message after final testing
console.log("ALL EMAILS ARE VALID");
return true;
}
private emailValidator(email : any): boolean {
if (email.match("^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"))
return true;
else
return false;
}
public composeEmail() {
this.email.subject = "Argiro is going to tell me about the subject";
this.email.subject = "[OpenAIRE-Connect] Community_name";
this.email.body = this.formatEmailBody();
}