connect/src/app/contact/contact.component.ts

177 lines
4.6 KiB
TypeScript
Raw Normal View History

import {Component, OnInit, Input, ElementRef, ViewChild} from '@angular/core';
import {FormGroup, FormBuilder, Validators} from '@angular/forms';
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";
@Component({
selector: 'contact',
templateUrl: './contact.component.html',
})
export class ContactComponent implements OnInit{
@Input('group')
myForm: FormGroup;
public showLoading = true;
public errorMessage = '';
public updateErrorMessage = '';
public successfulSaveMessage = '';
public successfulResetMessage = '';
public hasChanged = false;
public res = [];
public email: Email;
public emailToInform: Email;
public note = '';
public properties: EnvProperties = null;
public name = '';
public surname = '';
public sender = '';
public affiliation = '';
public community = '';
public message = '';
public recaptcha: any = null;
constructor (private element: ElementRef,
private route: ActivatedRoute,
private _router: Router,
public _fb: FormBuilder,
private _emailService: EmailService) { }
ngOnInit() {
this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.email = {body: '', subject: '', recipients: []};
this.emailToInform = {body: '', subject: '', recipients: []};
this.scroll();
this.showLoading = false;
});
}
public scroll() {
if (typeof document !== 'undefined') {
this.element.nativeElement.scrollIntoView();
}
}
public resetForm() {
}
public send() {
console.log(this.recaptcha);
}
/* private sendMailToNewManagers(managers: any) {
this._emailService.sendEmail(this.properties.adminToolsAPIURL + '/sendMail/',
Composer.composeEmailForNewManager(this.communityId,
this.community.title, managers)).subscribe(
res => {
// console.log("The email has been sent successfully!")
},
error => console.log(error)
);
}*/
private getNonEmptyItems(data: string[]): string[] {
const length = data.length;
const arrayNonEmpty = new Array<string>();
let j = 0;
for (let i = 0; i < length; i++) {
if (this.isEmpty(data[i])) {
// console.log(data[i]);
} else if (this.isNonEmpty(data[i])) {
arrayNonEmpty[j] = data[i];
j++;
// console.log(data[i]);
}
}
return arrayNonEmpty;
}
private hasFilled(data: any): boolean {
if (this.isNonEmpty(data) && !this.isEmpty(data)) {
return true;
}
return false;
}
private isEmpty(data: string): boolean {
if (data !== undefined && !data.replace(/\s/g, '').length) {
return true;
} else {
return false;
}
}
private isNonEmpty(data: string): boolean {
if (data !== undefined && data != null) {
return true;
} else {
return false;
}
}
private change() {
this.hasChanged = true;
this.successfulSaveMessage = '';
this.successfulResetMessage = '';
}
private resetChange() {
this.hasChanged = false;
}
public get form() {
return this._fb.group({
_id : '',
name : ['', Validators.required]
});
}
public reset() {
this.myForm.patchValue({
name : '',
_id : ''
});
}
handleUpdateError(message: string, error) {
this.updateErrorMessage = message;
console.log('Server responded: ' + error);
this.showLoading = false;
}
handleError(message: string, error) {
this.errorMessage = message;
console.log('Server responded: ' + error);
this.showLoading = false;
}
handleSuccessfulSend(message) {
this.showLoading = false;
this.successfulSaveMessage = message;
}
handleSuccessfulReset(message) {
this.showLoading = false;
this.successfulResetMessage = message;
}
trackByFn(index: any, item: any) {
return index;
}
}