2021-03-12 11:00:56 +01:00
|
|
|
import {Component, ElementRef, EventEmitter, Input, OnInit, Output} from "@angular/core";
|
2021-03-12 10:39:06 +01:00
|
|
|
import {fromEvent, Subscription} from 'rxjs';
|
|
|
|
import {delay} from "rxjs/operators";
|
2021-03-05 14:31:54 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'fs-modal',
|
|
|
|
template: `
|
2021-03-12 10:39:06 +01:00
|
|
|
<div class="fs-modal" (click)="close()">
|
|
|
|
<div id="fs-modal" (click)="$event.stopPropagation()" class="fs-modal-dialog">
|
|
|
|
<a class="close" (click)="close()">
|
|
|
|
<icon name="close"></icon>
|
|
|
|
</a>
|
|
|
|
<div class="header">
|
|
|
|
<h6 *ngIf="title">{{title}}</h6>
|
2021-03-05 14:31:54 +01:00
|
|
|
</div>
|
2021-03-12 11:29:58 +01:00
|
|
|
<div class="content" [class.hasFooter]="cancelButton || okButton">
|
2021-03-05 14:31:54 +01:00
|
|
|
<ng-content></ng-content>
|
|
|
|
</div>
|
2021-03-12 11:29:58 +01:00
|
|
|
<div *ngIf="cancelButton || okButton" class="footer uk-flex uk-flex-right">
|
|
|
|
<button *ngIf="cancelButton" class="uk-button uk-button-secondary outlined" [disabled]="cancelButtonDisabled" (click)="close()">{{cancelButtonText}}</button>
|
|
|
|
<button *ngIf="okButton" class="uk-button uk-button-secondary uk-margin-small-left" [disabled]="okButtonDisabled" (click)="ok()">{{okButtonText}}</button>
|
2021-03-12 10:39:06 +01:00
|
|
|
</div>
|
2021-03-05 14:31:54 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
export class FullScreenModalComponent implements OnInit {
|
|
|
|
okButtonText = 'OK';
|
|
|
|
cancelButtonText = 'Cancel';
|
2021-03-12 11:29:58 +01:00
|
|
|
cancelButton: boolean = false;
|
|
|
|
okButton: boolean = false;
|
2021-03-05 14:31:54 +01:00
|
|
|
title: string = null;
|
2021-03-12 11:00:56 +01:00
|
|
|
@Input()
|
|
|
|
okButtonDisabled = false;
|
|
|
|
@Input()
|
|
|
|
cancelButtonDisabled = false;
|
2021-03-05 14:31:54 +01:00
|
|
|
@Output()
|
|
|
|
okEmitter: EventEmitter<boolean> = new EventEmitter<boolean>();
|
2021-03-11 17:27:28 +01:00
|
|
|
@Output()
|
|
|
|
cancelEmitter: EventEmitter<boolean> = new EventEmitter<boolean>();
|
2021-03-05 14:31:54 +01:00
|
|
|
opened: boolean = false;
|
|
|
|
private readonly element: any;
|
2021-03-12 10:39:06 +01:00
|
|
|
private subscriptions: any[] = [];
|
2021-03-05 14:31:54 +01:00
|
|
|
|
|
|
|
constructor(private el: ElementRef) {
|
|
|
|
this.element = el.nativeElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-03-12 10:39:06 +01:00
|
|
|
if (typeof document !== "undefined") {
|
2021-03-05 14:31:54 +01:00
|
|
|
document.body.appendChild(this.element);
|
2021-03-12 10:39:06 +01:00
|
|
|
this.subscriptions.push(fromEvent(document, 'keydown').pipe(delay(1)).subscribe((event: KeyboardEvent) => {
|
2021-03-12 13:49:01 +01:00
|
|
|
if(event.keyCode === 27) {
|
|
|
|
this.close();
|
|
|
|
}
|
2021-03-12 10:39:06 +01:00
|
|
|
}));
|
2021-03-05 14:31:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.element.remove();
|
2021-03-12 10:39:06 +01:00
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscription) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
})
|
2021-03-05 14:31:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
open() {
|
2021-03-12 10:39:06 +01:00
|
|
|
if (typeof document !== "undefined") {
|
2021-03-05 14:31:54 +01:00
|
|
|
this.opened = true;
|
|
|
|
document.getElementsByTagName('html')[0].classList.add('fs-modal-open');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
2021-03-12 10:39:06 +01:00
|
|
|
if (typeof document !== "undefined") {
|
2021-03-05 14:31:54 +01:00
|
|
|
this.opened = false;
|
|
|
|
document.getElementsByTagName('html')[0].classList.remove('fs-modal-open');
|
2021-03-11 17:27:28 +01:00
|
|
|
this.cancelEmitter.emit();
|
2021-03-05 14:31:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ok() {
|
|
|
|
this.close();
|
|
|
|
this.okEmitter.emit(true);
|
|
|
|
}
|
|
|
|
}
|