Change email format
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@53923 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
8a9f632e51
commit
a02587529f
|
@ -4,8 +4,10 @@
|
|||
<div class="uk-container uk-margin-bottom">
|
||||
|
||||
<div id="invite" class=" uk-card uk-card-default uk-padding">
|
||||
<div class="uk-text-large uk-text-center uk-width-5-6@l uk-width ">Invite users to subscribe</div>
|
||||
<!--table *ngIf="communityId != null && community != null && !showLoading && !errorMessage" class="uk-table uk-align-center"-->
|
||||
<div class="uk-text-large uk-text-center uk-width-5-6@l uk-width ">Invite users to subscribe</div>
|
||||
<div *ngIf="showLoading" class="uk-animation-fade uk-width-1-1" role="alert"><span class="loading-gif uk-align-center"></span>></div>
|
||||
<div *ngIf="communityId != null && !showLoading && !errorMessage">
|
||||
<!--table *ngIf="communityId != null && community != null && !showLoading && !errorMessage" class="uk-table uk-align-center"-->
|
||||
<table class="uk-table uk-align-center">
|
||||
<tbody>
|
||||
<!-- <tr>
|
||||
|
@ -33,6 +35,8 @@
|
|||
class="uk-width-large uk-text-danger uk-text-small uk-margin-top"> Please add a valid email. </div> -->
|
||||
<!-- </div>
|
||||
</div> -->
|
||||
<div *ngIf="!recipients && !areValid" class="uk-width-large uk-text-danger uk-text-small uk-margin-top">Please add valid email/s.</div>
|
||||
<div *ngIf="!recipients" class="uk-width-large uk-text-danger uk-text-small uk-margin-top">Please add a recipient.</div>
|
||||
<input placeholder="email" type="text"
|
||||
class="form-control uk-input uk-width-large@l uk-width-medium@s" [(ngModel)] = "recipients" id="recipients"
|
||||
required>
|
||||
|
@ -46,11 +50,11 @@
|
|||
|
||||
<table class="uk-table uk-align-center">
|
||||
<tbody>
|
||||
<tr>
|
||||
<!-- <tr>
|
||||
<td class="uk-text-bold uk-width-1-4@xl uk-width-1-4@m uk-width-1-4@s uk-text-right"></td>
|
||||
<td class="uk-text-left">
|
||||
{{body.salutation}}<br>
|
||||
<span *ngIf="body.fromName == ''" class="uk-text-muted">
|
||||
<{{body.salutation}}<br>-->
|
||||
<!-- <span *ngIf="body.fromName == ''" class="uk-text-muted">
|
||||
<i>{{body.fromMessage}}...</i>
|
||||
</span>
|
||||
<span *ngIf="body.fromName !=''">
|
||||
|
@ -58,7 +62,7 @@
|
|||
<b>{{body.fromName}}</b>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tr> -->
|
||||
<tr>
|
||||
<td for="email.body" class="uk-text-bold uk-text-right">Message:</td>
|
||||
<td class="uk-text-left">
|
||||
|
@ -82,8 +86,16 @@
|
|||
<tr>
|
||||
<td></td>
|
||||
<td class="uk-text-left">
|
||||
{{body.closing}}<br>
|
||||
<!-- {{body.closing}}<br> -->
|
||||
{{body.signature}}
|
||||
<span *ngIf="body.fromName == ''" class="uk-text-muted">
|
||||
<i>{{body.fromMessage}}...</i>
|
||||
</span>
|
||||
<span *ngIf="body.fromName !=''">
|
||||
{{body.fromMessage}}
|
||||
<b>{{body.fromName}}</b>
|
||||
</span>
|
||||
<br><a href="https://www.openaire.eu">www.openaire.eu</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -131,6 +143,7 @@
|
|||
<div class="uk-text-left">
|
||||
<span uk-icon="chevron-left"></span><span class="uk-margin-small-left"><a href="invite">Back</a></span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -3,11 +3,14 @@ import {SimpleChanges, OnChanges} from '@angular/core';
|
|||
import {FormGroup, FormArray, FormBuilder, Validators} from "@angular/forms";
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
|
||||
import {ConnectHelper} from '../../../openaireLibrary/connect/connectHelper';
|
||||
|
||||
import {Email} from '../../../openaireLibrary/utils/email/email';
|
||||
import {Body} from '../../../openaireLibrary/utils/email/body';
|
||||
|
||||
import {EnvProperties} from '../../../openaireLibrary/utils/properties/env-properties';
|
||||
import {EmailService} from '../../../openaireLibrary/utils/email/email.service';
|
||||
import {CommunityService} from "../../../openaireLibrary/connect/community/community.service";
|
||||
|
||||
@Component({
|
||||
selector: 'invite',
|
||||
|
@ -17,45 +20,86 @@ import {EmailService} from '../../../openaire
|
|||
export class InviteComponent implements OnInit {
|
||||
|
||||
@Input() longView: boolean = true;
|
||||
@Input() communityId = null;
|
||||
|
||||
private properties: EnvProperties = null;
|
||||
|
||||
public community = null;
|
||||
public showLoading: boolean = true;
|
||||
public errorMessage: string = '';
|
||||
|
||||
public email: Email;
|
||||
public body: Body;
|
||||
public recipients: string;
|
||||
|
||||
public areValid: boolean = true;
|
||||
|
||||
private ckeditorContent: string;
|
||||
|
||||
public defaultBody = '<p>OpenAIRE invites you to subscribe in <a href="https://beta.egi.openaire.eu">_Community_name_</a> dashboard. </p><p>The community dashboard is part of the <a href="https://beta.egi.openaire.eu">OpenAIRE-Connect</a> project.</p>';
|
||||
|
||||
@Input() communityId = null;
|
||||
// public defaultBody = '<p>OpenAIRE invites you to subscribe in <a href="https://beta.egi.openaire.eu">_Community_name_</a> dashboard. </p><p>The community dashboard is part of the <a href="https://beta.egi.openaire.eu">OpenAIRE-Connect</a> project.</p>';
|
||||
public defaultBody ='';
|
||||
|
||||
constructor (
|
||||
private route: ActivatedRoute,
|
||||
private _router: Router,
|
||||
public _fb: FormBuilder,
|
||||
private _emailService: EmailService) { }
|
||||
private _emailService: EmailService,
|
||||
private _communityService: CommunityService) {
|
||||
|
||||
this.route.queryParams.subscribe(
|
||||
communityId => {
|
||||
this.communityId = communityId['communityId'];
|
||||
if(!this.communityId){
|
||||
this.communityId = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public ngOnInit() {
|
||||
this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||
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 = "";
|
||||
this.errorMessage = "";
|
||||
this.showLoading = true;
|
||||
if (this.communityId != null && this.communityId != '') {
|
||||
this._communityService.getCommunity(this.properties, this.properties.communityAPI+this.communityId).subscribe (
|
||||
community => {
|
||||
this.community = community;
|
||||
|
||||
this.defaultBody = '<p>You are invited to subscribe in <a href="https://beta.' + this.communityId + '.openaire.eu/">' + this.community.title + '</a> dashboard.'
|
||||
+ '<br>The purpose of this dashboard is to gather, link & 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>';
|
||||
|
||||
// TODO move the initialisation
|
||||
this.body = {/*salutation: "Dear Sir/Madame,",*/ fromMessage: ", on behalf of ", fromName: "", paragraphs: this.defaultBody, /*closing: "Kind regards,",*/ signature: "OpenAIRE team", ps: ""};
|
||||
this.email = {body: "", subject: "", recipients: []};
|
||||
this.recipients = "";
|
||||
|
||||
this.showLoading = false;
|
||||
},
|
||||
error => this.handleError('System error retrieving community name', error)
|
||||
);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public invite() {
|
||||
this.showLoading = true;
|
||||
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("The email has been sent successfully!")
|
||||
,
|
||||
error => console.log(error)
|
||||
res => {
|
||||
console.log("The email has been sent successfully!");
|
||||
this.showLoading = false;
|
||||
},
|
||||
error => {
|
||||
console.log(error);
|
||||
this.showLoading = false;
|
||||
this.errorMessage = "gdgd";//inviteErrorMessage
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -64,10 +108,11 @@ export class InviteComponent implements OnInit {
|
|||
public validateEmails(): boolean {
|
||||
if (this.parseEmails()) {
|
||||
if (this.hasValidEmails()) {
|
||||
return true;
|
||||
return this.areValid;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
this.areValid = false;
|
||||
return this.areValid;
|
||||
}
|
||||
|
||||
public parseEmails(): boolean {
|
||||
|
@ -90,26 +135,26 @@ export class InviteComponent implements OnInit {
|
|||
}
|
||||
|
||||
private hasValidEmails(): boolean {
|
||||
let length = this.email.recipients.length;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
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 = "[OpenAIRE-Connect] Community_name";
|
||||
|
@ -123,10 +168,19 @@ export class InviteComponent implements OnInit {
|
|||
fromMessageAndName = "<span>" + this.body.fromMessage + this.body.fromName + "</span>";
|
||||
}
|
||||
|
||||
let formattedEmail = "<div>" + this.body.salutation + "<br><br>" +
|
||||
fromMessageAndName + this.body.paragraphs +
|
||||
"<p>" + this.body.closing + "<br>" + this.body.signature + "</p></div>";
|
||||
let formattedEmail = "<div style='font-size:14px;'>" + /*+ this.body.salutation + "<br><br>" +*/
|
||||
this.body.paragraphs +
|
||||
"<p>" /*+ this.body.closing + "<br>"*/ + this.body.signature + fromMessageAndName + "<br>" +
|
||||
"<a href='https://www.openaire.eu'>www.openaire.eu</a>" + "</p></div>";
|
||||
|
||||
|
||||
return formattedEmail;
|
||||
}
|
||||
|
||||
public handleError(message: string, error) {
|
||||
this.errorMessage = message;
|
||||
console.log('Server responded: ' + error);
|
||||
|
||||
this.showLoading = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import {PreviousRouteRecorder} from '../../../openaireLibrary/utils/piwik/p
|
|||
|
||||
import {FreeGuard} from '../../../openaireLibrary/login/freeGuard.guard';
|
||||
import {EmailService} from '../../../openaireLibrary/utils/email/email.service';
|
||||
import {CommunityService} from '../../../openaireLibrary/connect/community/community.service';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
|
@ -21,7 +22,7 @@ import {EmailService} from '../../../openaireLibrary/utils/email/e
|
|||
],
|
||||
providers: [
|
||||
FreeGuard, PreviousRouteRecorder,
|
||||
EmailService
|
||||
EmailService, CommunityService
|
||||
],
|
||||
exports: [
|
||||
InviteComponent
|
||||
|
|
Loading…
Reference in New Issue