2019-12-03 13:51:28 +01:00
|
|
|
import {Component, OnInit, ViewChild} from '@angular/core';
|
2019-04-10 00:09:38 +02:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {EmailService} from "../openaireLibrary/utils/email/email.service";
|
|
|
|
import {Email} from "../openaireLibrary/utils/email/email";
|
|
|
|
import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties";
|
2019-04-10 20:53:39 +02:00
|
|
|
import {Composer} from "../openaireLibrary/utils/email/composer";
|
2019-08-02 16:56:03 +02:00
|
|
|
import {Meta, Title} from "@angular/platform-browser";
|
2019-04-12 13:54:49 +02:00
|
|
|
import {PiwikService} from "../openaireLibrary/utils/piwik/piwik.service";
|
2019-04-24 14:02:11 +02:00
|
|
|
import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class";
|
2019-07-18 13:36:05 +02:00
|
|
|
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
|
2019-08-02 16:56:03 +02:00
|
|
|
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
|
2019-12-03 13:51:28 +01:00
|
|
|
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
|
2019-04-10 00:09:38 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'contact',
|
|
|
|
templateUrl: './contact.component.html',
|
|
|
|
})
|
|
|
|
|
2019-04-10 20:53:39 +02:00
|
|
|
export class ContactComponent implements OnInit {
|
2019-12-03 13:51:28 +01:00
|
|
|
public url: string = null;
|
|
|
|
public pageTitle: string = "OpenAIRE - Connect | Contact Us";
|
|
|
|
public piwiksub: any;
|
|
|
|
public showLoading = true;
|
|
|
|
public errorMessage = '';
|
|
|
|
public email: Email;
|
|
|
|
public properties: EnvProperties = null;
|
|
|
|
public pageContents = null;
|
|
|
|
public divContents = null;
|
|
|
|
|
|
|
|
public contactForm: FormGroup;
|
|
|
|
@ViewChild('AlertModal') modal;
|
|
|
|
@ViewChild('recaptcha') recaptcha;
|
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute,
|
|
|
|
private _router: Router,
|
|
|
|
private _emailService: EmailService,
|
|
|
|
private _meta: Meta,
|
|
|
|
private _title: Title,
|
|
|
|
private seoService: SEOService,
|
|
|
|
private _piwikService: PiwikService,
|
|
|
|
private fb: FormBuilder,
|
|
|
|
private helper: HelperService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this._title.setTitle('OpenAIRE-Connect | Contact Us');
|
|
|
|
this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
this.email = {body: '', subject: '', recipients: []};
|
|
|
|
|
|
|
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
|
|
|
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.properties.piwikSiteId).subscribe();
|
|
|
|
}
|
|
|
|
this.url = this.properties.baseLink + this._router.url;
|
|
|
|
this.seoService.createLinkForCanonicalURL(this.url);
|
|
|
|
this.updateUrl(this.url);
|
|
|
|
this.updateTitle(this.pageTitle);
|
|
|
|
this.updateDescription("OpenAIRE - Connect, Community Gateway, research community");
|
|
|
|
this.reset();
|
|
|
|
//this.getDivContents();
|
|
|
|
this.getPageContents();
|
|
|
|
HelperFunctions.scroll();
|
|
|
|
this.showLoading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private getPageContents() {
|
2020-04-07 18:52:19 +02:00
|
|
|
this.helper.getPageHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => {
|
2019-12-03 13:51:28 +01:00
|
|
|
this.pageContents = contents;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
private getDivContents() {
|
2020-04-07 18:52:19 +02:00
|
|
|
this.helper.getDivHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => {
|
2019-12-03 13:51:28 +01:00
|
|
|
this.divContents = contents;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
public send(event) {
|
|
|
|
HelperFunctions.scroll();
|
|
|
|
if(event.valid === true) {
|
|
|
|
this.sendMail(this.properties.admins);
|
|
|
|
} else {
|
|
|
|
this.errorMessage = 'Please fill in all the required fields!';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public reset() {
|
|
|
|
this.contactForm = this.fb.group( {
|
|
|
|
name: this.fb.control('', Validators.required),
|
|
|
|
surname: this.fb.control('', Validators.required),
|
|
|
|
email: this.fb.control('', [Validators.required, Validators.email]),
|
|
|
|
affiliation: this.fb.control('', Validators.required),
|
|
|
|
community: this.fb.control('', Validators.required),
|
|
|
|
message: this.fb.control('', Validators.required),
|
|
|
|
recaptcha: this.fb.control('', Validators.required),
|
|
|
|
});
|
|
|
|
this.errorMessage = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
private sendMail(admins: any) {
|
|
|
|
this.showLoading = true;
|
2020-04-07 18:52:19 +02:00
|
|
|
this._emailService.contact(this.properties,
|
2019-12-03 13:51:28 +01:00
|
|
|
Composer.composeEmailForNewCommunity(this.contactForm.value, admins),
|
|
|
|
this.contactForm.value.recaptcha).subscribe(
|
|
|
|
res => {
|
2020-03-26 11:27:50 +01:00
|
|
|
this.showLoading = false;
|
2019-12-03 13:51:28 +01:00
|
|
|
if (res) {
|
|
|
|
this.reset();
|
|
|
|
this.modalOpen();
|
2020-03-26 11:27:50 +01:00
|
|
|
} else {
|
2019-12-03 13:51:28 +01:00
|
|
|
this.showLoading = false;
|
2020-03-26 11:27:50 +01:00
|
|
|
this.errorMessage = 'Email sent failed! Please try again.';
|
|
|
|
this.contactForm.get('recaptcha').setValue('');
|
2019-12-03 13:51:28 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.handleError('Email sent failed! Please try again.', error);
|
|
|
|
this.showLoading = false;
|
|
|
|
this.contactForm.get('recaptcha').setValue('');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public modalOpen() {
|
|
|
|
this.modal.okButton = true;
|
|
|
|
this.modal.alertTitle = 'Your request has been successfully submitted';
|
|
|
|
this.modal.alertMessage = false;
|
|
|
|
this.modal.cancelButton = false;
|
|
|
|
this.modal.okButtonLeft = false;
|
|
|
|
this.modal.okButtonText = 'OK';
|
|
|
|
this.modal.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleError(message: string, error) {
|
|
|
|
this.errorMessage = message;
|
|
|
|
console.log('Server responded: ' + error);
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public goToHome() {
|
|
|
|
this._router.navigate(['/']);
|
|
|
|
}
|
|
|
|
|
|
|
|
private updateDescription(description: string) {
|
|
|
|
this._meta.updateTag({content: description}, "name='description'");
|
|
|
|
this._meta.updateTag({content: description}, "property='og:description'");
|
|
|
|
}
|
|
|
|
|
|
|
|
private updateTitle(title: string) {
|
|
|
|
var _title = ((title.length > 50) ? title.substring(0, 50) : title);
|
|
|
|
this._title.setTitle(_title);
|
|
|
|
this._meta.updateTag({content: _title}, "property='og:title'");
|
|
|
|
}
|
|
|
|
|
|
|
|
private updateUrl(url: string) {
|
|
|
|
this._meta.updateTag({content: url}, "property='og:url'");
|
|
|
|
}
|
2019-04-10 00:09:38 +02:00
|
|
|
}
|