1
|
import {Component, OnInit, ViewChild} from '@angular/core';
|
2
|
import {ActivatedRoute, Router} from '@angular/router';
|
3
|
import {EmailService} from "../openaireLibrary/utils/email/email.service";
|
4
|
import {Email} from "../openaireLibrary/utils/email/email";
|
5
|
import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties";
|
6
|
import {Composer} from "../openaireLibrary/utils/email/composer";
|
7
|
import {Meta, Title} from "@angular/platform-browser";
|
8
|
import {PiwikService} from "../openaireLibrary/utils/piwik/piwik.service";
|
9
|
import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class";
|
10
|
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
|
11
|
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
|
12
|
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
|
13
|
import {Breadcrumb} from "../openaireLibrary/utils/breadcrumbs/breadcrumbs.component";
|
14
|
import {Subscriber} from "rxjs";
|
15
|
import {properties} from "../../environments/environment";
|
16
|
|
17
|
@Component({
|
18
|
selector: 'contact',
|
19
|
templateUrl: './contact.component.html',
|
20
|
})
|
21
|
|
22
|
export class ContactComponent implements OnInit {
|
23
|
public url: string = null;
|
24
|
public pageTitle: string = "OpenAIRE - Connect | Contact Us";
|
25
|
public showLoading = true;
|
26
|
public errorMessage = '';
|
27
|
public email: Email;
|
28
|
public properties: EnvProperties = null;
|
29
|
public pageContents = null;
|
30
|
public divContents = null;
|
31
|
public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'contact us'}];
|
32
|
|
33
|
public contactForm: FormGroup;
|
34
|
@ViewChild('AlertModal') modal;
|
35
|
private subscriptions = [];
|
36
|
ngOnDestroy() {
|
37
|
this.subscriptions.forEach(subscription => {
|
38
|
if (subscription instanceof Subscriber) {
|
39
|
subscription.unsubscribe();
|
40
|
}
|
41
|
});
|
42
|
}
|
43
|
|
44
|
constructor(private route: ActivatedRoute,
|
45
|
private _router: Router,
|
46
|
private _emailService: EmailService,
|
47
|
private _meta: Meta,
|
48
|
private _title: Title,
|
49
|
private seoService: SEOService,
|
50
|
private _piwikService: PiwikService,
|
51
|
private fb: FormBuilder,
|
52
|
private helper: HelperService) {
|
53
|
}
|
54
|
|
55
|
ngOnInit() {
|
56
|
this._title.setTitle('OpenAIRE-Connect | Contact Us');
|
57
|
|
58
|
this.properties = properties;
|
59
|
this.email = {body: '', subject: '', recipients: []};
|
60
|
|
61
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
62
|
this.subscriptions.push( this._piwikService.trackView(this.properties, this.pageTitle, this.properties.piwikSiteId).subscribe());
|
63
|
}
|
64
|
this.url = this.properties.domain + this._router.url;
|
65
|
this.seoService.createLinkForCanonicalURL(this.url);
|
66
|
this.updateUrl(this.url);
|
67
|
this.updateTitle(this.pageTitle);
|
68
|
this.updateDescription("Contact us to learn more about OpenAIRE Connect Research Gateways");
|
69
|
this.reset();
|
70
|
//this.getDivContents();
|
71
|
this.getPageContents();
|
72
|
this.showLoading = false;
|
73
|
|
74
|
}
|
75
|
|
76
|
private getPageContents() {
|
77
|
this.subscriptions.push(this.helper.getPageHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => {
|
78
|
this.pageContents = contents;
|
79
|
}));
|
80
|
}
|
81
|
|
82
|
private getDivContents() {
|
83
|
this.subscriptions.push(this.helper.getDivHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => {
|
84
|
this.divContents = contents;
|
85
|
}));
|
86
|
}
|
87
|
|
88
|
public send(event) {
|
89
|
HelperFunctions.scroll();
|
90
|
if(event.valid === true) {
|
91
|
this.sendMail(this.properties.admins);
|
92
|
} else {
|
93
|
this.errorMessage = 'Please fill in all the required fields!';
|
94
|
}
|
95
|
}
|
96
|
|
97
|
public reset() {
|
98
|
this.contactForm = this.fb.group( {
|
99
|
name: this.fb.control('', Validators.required),
|
100
|
surname: this.fb.control('', Validators.required),
|
101
|
email: this.fb.control('', [Validators.required, Validators.email]),
|
102
|
affiliation: this.fb.control('', Validators.required),
|
103
|
community: this.fb.control('', Validators.required),
|
104
|
message: this.fb.control('', Validators.required),
|
105
|
recaptcha: this.fb.control('', Validators.required),
|
106
|
});
|
107
|
this.errorMessage = '';
|
108
|
}
|
109
|
|
110
|
private sendMail(admins: any) {
|
111
|
this.showLoading = true;
|
112
|
this.subscriptions.push(this._emailService.contact(this.properties,
|
113
|
Composer.composeEmailForNewCommunity(this.contactForm.value, admins),
|
114
|
this.contactForm.value.recaptcha).subscribe(
|
115
|
res => {
|
116
|
this.showLoading = false;
|
117
|
if (res) {
|
118
|
this.reset();
|
119
|
this.modalOpen();
|
120
|
} else {
|
121
|
this.errorMessage = 'Email sent failed! Please try again.';
|
122
|
this.contactForm.get('recaptcha').setValue('');
|
123
|
}
|
124
|
},
|
125
|
error => {
|
126
|
this.handleError('Email sent failed! Please try again.', error);
|
127
|
this.showLoading = false;
|
128
|
this.contactForm.get('recaptcha').setValue('');
|
129
|
}
|
130
|
));
|
131
|
}
|
132
|
|
133
|
public modalOpen() {
|
134
|
this.modal.okButton = true;
|
135
|
this.modal.alertTitle = 'Your request has been successfully submitted';
|
136
|
this.modal.alertMessage = false;
|
137
|
this.modal.cancelButton = false;
|
138
|
this.modal.okButtonLeft = false;
|
139
|
this.modal.okButtonText = 'OK';
|
140
|
this.modal.open();
|
141
|
}
|
142
|
|
143
|
handleError(message: string, error) {
|
144
|
this.errorMessage = message;
|
145
|
console.log('Server responded: ' + error);
|
146
|
this.showLoading = false;
|
147
|
}
|
148
|
|
149
|
public goToHome() {
|
150
|
this._router.navigate(['/']);
|
151
|
}
|
152
|
|
153
|
private updateDescription(description: string) {
|
154
|
this._meta.updateTag({content: description}, "name='description'");
|
155
|
this._meta.updateTag({content: description}, "property='og:description'");
|
156
|
}
|
157
|
|
158
|
private updateTitle(title: string) {
|
159
|
var _title = ((title.length > 50) ? title.substring(0, 50) : title);
|
160
|
this._title.setTitle(_title);
|
161
|
this._meta.updateTag({content: _title}, "property='og:title'");
|
162
|
}
|
163
|
|
164
|
private updateUrl(url: string) {
|
165
|
this._meta.updateTag({content: url}, "property='og:url'");
|
166
|
}
|
167
|
}
|