Project

General

Profile

1
import {Component, OnInit, Input}                        from '@angular/core';
2
import {SimpleChanges, OnChanges}                        from '@angular/core';
3
import {FormGroup, FormArray, FormBuilder, Validators}   from "@angular/forms";
4
import {ActivatedRoute, Router}                          from '@angular/router';
5

    
6
import {Email}                                           from '../../../openaireLibrary/utils/email/email';
7
import {Body}                                            from '../../../openaireLibrary/utils/email/body';
8

    
9
import {EnvProperties}                                   from '../../../openaireLibrary/utils/properties/env-properties';
10
import {EmailService}                                    from '../../../openaireLibrary/utils/email/email.service';
11

    
12
@Component({
13
    selector: 'invite',
14
    templateUrl: './invite.component.html',
15
})
16

    
17
export class InviteComponent implements OnInit {
18

    
19
  @Input() longView: boolean = true;
20

    
21
  private properties: EnvProperties = null;
22
  public email: Email;
23
  public body: Body;
24

    
25
  private ckeditorContent: string;
26

    
27
  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>';
28

    
29
  @Input() communityId = null;
30

    
31
  constructor (
32
      private route: ActivatedRoute,
33
      private _router: Router,
34
      public _fb: FormBuilder,
35
      private _emailService: EmailService) { }
36

    
37

    
38
  public ngOnInit() {
39
      this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
40
          this.properties = data.envSpecific;
41
          this.body = {salutation: "Dear Sir/Madame,", fromMessage: "On behalf of ", fromName: "", paragraphs: this.defaultBody, closing: "Kind regards,", signature: "OpenAIRE team"};
42
          this.email = {body: "", subject: "", recipients: []};
43

    
44
      });
45
  }
46

    
47
  public invite() {
48
      if (this.email.recipients != null) {
49
        this.composeEmail();
50
        console.log(this.email.body);
51

    
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
        );
57
      }
58
  }
59

    
60
  public composeEmail() {
61
      this.email.subject = "Argiro is going to tell me about the subject";
62
      this.email.body = this.formatEmailBody();
63
  }
64

    
65
  public formatEmailBody(): string {
66
      let fromMessageAndName = "";
67

    
68
      if (this.body.fromName != "") {
69
        fromMessageAndName = "<span>" + this.body.fromMessage + this.body.fromName + "</span>";
70
      }
71

    
72
      let formattedEmail = "<div>" + this.body.salutation + "<br><br>" +
73
      fromMessageAndName + this.body.paragraphs +
74
      "<p>" + this.body.closing + "<br>" + this.body.signature + "</p></div>";
75

    
76
      return formattedEmail;
77
  }
78
}
(3-3/4)