You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.8 KiB
TypeScript
117 lines
3.8 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
import { ValidationErrorModel } from '../../../common/forms/validation/error-model/validation-error-model';
|
|
import { BaseComponent } from '../../../core/common/base/base.component';
|
|
import { ContactEmailFormModel } from '../../../core/model/contact/contact-email-form-model';
|
|
import { ContactSupportService } from '../../../core/services/contact-support/contact-support.service';
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '../../../core/services/notification/ui-notification-service';
|
|
import { ContactDialogComponent } from '../../../library/contact-dialog/contact-dialog.component';
|
|
import { FaqDialogComponent } from './faq/faq-dialog.component';
|
|
import { GlossaryDialogComponent } from './glossary/glossary-dialog.component';
|
|
|
|
@Component({
|
|
selector: 'app-sidebar-footer',
|
|
templateUrl: './sidebar-footer.component.html',
|
|
styleUrls: ['./sidebar-footer.component.css']
|
|
})
|
|
export class SidebarFooterComponent extends BaseComponent implements OnInit {
|
|
|
|
private contactEmailFormModel: ContactEmailFormModel;
|
|
private formGroup: FormGroup;
|
|
|
|
constructor(
|
|
private dialog: MatDialog,
|
|
private language: TranslateService,
|
|
private contactSupportService: ContactSupportService,
|
|
private uiNotificationService: UiNotificationService
|
|
) {
|
|
super();
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.contactEmailFormModel = new ContactEmailFormModel();
|
|
this.formGroup = this.contactEmailFormModel.buildForm();
|
|
}
|
|
|
|
openContactDialog() {
|
|
if (this.dialog.openDialogs.length > 0) {
|
|
this.dialog.closeAll();
|
|
}
|
|
else {
|
|
const dialogRef = this.dialog.open(ContactDialogComponent, {
|
|
width: '400px',
|
|
disableClose: true,
|
|
data: this.formGroup
|
|
});
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(data => {
|
|
if (data) {
|
|
this.contactSupportService.postEmail(data.value)
|
|
.pipe(takeUntil(this._destroyed))
|
|
.subscribe(
|
|
complete => this.onCallbackSuccess(),
|
|
error => this.onCallbackError(error)
|
|
);
|
|
this.formGroup.reset();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
openGlossaryDialog() {
|
|
if (this.dialog.openDialogs.length > 0) {
|
|
this.dialog.closeAll();
|
|
}
|
|
else {
|
|
const dialogRef = this.dialog.open(GlossaryDialogComponent, {
|
|
disableClose: true,
|
|
});
|
|
}
|
|
}
|
|
|
|
openFaqDialog() {
|
|
if (this.dialog.openDialogs.length > 0) {
|
|
this.dialog.closeAll();
|
|
}
|
|
else {
|
|
const dialogRef = this.dialog.open(FaqDialogComponent, {
|
|
disableClose: true,
|
|
});
|
|
}
|
|
}
|
|
|
|
onCallbackSuccess(): void {
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-EMAIL-SEND'), SnackBarNotificationLevel.Success);
|
|
}
|
|
|
|
onCallbackError(errorResponse: any) {
|
|
this.setErrorModel(errorResponse.error);
|
|
this.validateAllFormFields(this.formGroup);
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-EMAIL-SEND'), SnackBarNotificationLevel.Error);
|
|
}
|
|
|
|
public setErrorModel(validationErrorModel: ValidationErrorModel) {
|
|
Object.keys(validationErrorModel).forEach(item => {
|
|
(<any>this.contactEmailFormModel.validationErrorModel)[item] = (<any>validationErrorModel)[item];
|
|
});
|
|
}
|
|
|
|
public validateAllFormFields(formControl: AbstractControl) {
|
|
if (formControl instanceof FormControl) {
|
|
formControl.updateValueAndValidity({ emitEvent: false });
|
|
} else if (formControl instanceof FormGroup) {
|
|
Object.keys(formControl.controls).forEach(item => {
|
|
const control = formControl.get(item);
|
|
this.validateAllFormFields(control);
|
|
});
|
|
} else if (formControl instanceof FormArray) {
|
|
formControl.controls.forEach(item => {
|
|
this.validateAllFormFields(item);
|
|
});
|
|
}
|
|
}
|
|
|
|
}
|