openaire-library/sharedComponents/quick-contact/quick-contact.component.ts

58 lines
1.6 KiB
TypeScript

import {Component, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild} from '@angular/core';
import {FormGroup} from "@angular/forms";
import {Subscriber} from "rxjs";
declare var UIkit;
@Component({
selector: 'quick-contact',
templateUrl: 'quick-contact.component.html',
styleUrls: ['quick-contact.component.css']
})
export class QuickContactComponent implements OnInit, OnDestroy {
public showDrop: boolean = false;
@Input()
public contactForm: FormGroup;
@Input()
public sending = false;
@Input()
public organizationTypes: string[] = [];
@Output() sendEmitter: EventEmitter<any> = new EventEmitter<any>();
private subscriptions: any[] = [];
@ViewChild('drop') drop: ElementRef;
ngOnInit() {
if (typeof document !== 'undefined') {
this.subscriptions.push(UIkit.util.on(document, 'beforehide', '#quick-contact', (event) => {
if(this.sending) {
event.preventDefault();
}
}));
this.subscriptions.push(UIkit.util.on(document, 'show', '#quick-contact', (event) => {
this.showDrop = true;
}));
this.subscriptions.push(UIkit.util.on(document, 'hide', '#quick-contact', (event) => {
this.showDrop = false;
}));
}
}
ngOnDestroy() {
this.subscriptions.forEach(value => {
if (value instanceof Subscriber) {
value.unsubscribe();
} else if (value instanceof Function) {
value();
}
});
}
public close() {
UIkit.drop(this.drop.nativeElement).hide();
}
public send(event) {
this.sendEmitter.emit(event);
}
}