80 lines
3.1 KiB
TypeScript
80 lines
3.1 KiB
TypeScript
import {Component, OnInit, Input} from '@angular/core';
|
|
import {SimpleChanges, OnChanges} from '@angular/core';
|
|
import {FormGroup, FormArray, FormBuilder, Validators} from "@angular/forms";
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
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';
|
|
|
|
@Component({
|
|
selector: 'invite',
|
|
templateUrl: './invite.component.html',
|
|
})
|
|
|
|
export class InviteComponent implements OnInit {
|
|
|
|
@Input() longView: boolean = true;
|
|
|
|
private properties: EnvProperties = null;
|
|
public email: Email;
|
|
public body: Body;
|
|
|
|
private ckeditorContent: string;
|
|
|
|
public defaultBody = '<div>Dear Sir/Madame,<br> <p><span>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><p>Kind regards,<br>OpenAIRE team</p></div>'
|
|
public defaultBody2 = 'OpenAIRE invites you to subscribe in Community_name dashboard. </p><p>The community dashboard is part of the OpenAIRE-Connect</a> project</p>'
|
|
|
|
@Input() communityId = null;
|
|
|
|
constructor (
|
|
private route: ActivatedRoute,
|
|
private _router: Router,
|
|
public _fb: FormBuilder,
|
|
private _emailService: EmailService) { }
|
|
|
|
|
|
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: "", closing: "Kind regards,", signature: "OpenAIRE team"};
|
|
this.email = {body: "", subject: "", recipients: []};
|
|
|
|
});
|
|
}
|
|
|
|
public invite() {
|
|
if (this.email.recipients != null) {
|
|
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)
|
|
);
|
|
}
|
|
}
|
|
|
|
public composeEmail() {
|
|
this.email.subject = "Argiro is going to tell me about the subject";
|
|
this.email.body = this.formatEmailBody();
|
|
}
|
|
|
|
public formatEmailBody(): string {
|
|
let fromMessageAndName = "";
|
|
|
|
if (this.body.fromName != "") {
|
|
fromMessageAndName = "<span>" + this.body.fromMessage + this.body.fromName + "</span>";
|
|
}
|
|
|
|
let formattedEmail = "<div>" + this.body.salutation + "<br>" +
|
|
"<p>" + fromMessageAndName + "..." + "</p>" +
|
|
"<p>" + this.body.closing + "<br>" + this.body.signature + "</p></div>";
|
|
|
|
return formattedEmail;
|
|
}
|
|
}
|