2022-07-04 17:00:10 +02:00
|
|
|
import {
|
2023-07-04 10:08:39 +02:00
|
|
|
AfterViewInit,
|
|
|
|
ChangeDetectorRef,
|
2022-07-04 17:00:10 +02:00
|
|
|
Component,
|
|
|
|
ElementRef,
|
2023-07-04 10:08:39 +02:00
|
|
|
EventEmitter,
|
|
|
|
HostListener,
|
2022-07-04 17:00:10 +02:00
|
|
|
Input,
|
|
|
|
OnDestroy,
|
|
|
|
Output,
|
|
|
|
ViewChild
|
|
|
|
} from "@angular/core";
|
2023-07-04 10:08:39 +02:00
|
|
|
import {Subscription} from 'rxjs';
|
2022-07-04 10:32:24 +02:00
|
|
|
import {HelperFunctions} from "../../HelperFunctions.class";
|
2023-02-21 14:14:25 +01:00
|
|
|
import {LayoutService} from "../../../dashboard/sharedComponents/sidebar/layout.service";
|
2021-03-05 14:31:54 +01:00
|
|
|
|
2022-05-30 16:56:47 +02:00
|
|
|
declare var UIkit;
|
2022-07-04 17:00:10 +02:00
|
|
|
declare var ResizeObserver;
|
|
|
|
|
2021-03-05 14:31:54 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'fs-modal',
|
|
|
|
template: `
|
2022-07-04 17:00:10 +02:00
|
|
|
<div #modal class="uk-modal-full" [id]="id" uk-modal="container: #modal-container">
|
2022-07-04 10:32:24 +02:00
|
|
|
<div class="uk-modal-dialog">
|
2022-07-04 17:00:10 +02:00
|
|
|
<div #header class="uk-modal-header uk-flex uk-flex-middle" [ngClass]="classTitle">
|
2022-07-04 10:32:24 +02:00
|
|
|
<div [class.uk-invisible]="!back" class="uk-width-medium@l uk-width-auto uk-flex uk-flex-center">
|
2023-07-05 10:40:43 +02:00
|
|
|
<button class="uk-button uk-button-link" [class.uk-disabled]="!back" [disabled]="!back" (click)="backClicked()">
|
2023-02-21 14:14:25 +01:00
|
|
|
<icon name="west" [flex]="true" [ratio]="isMobile?2:3"></icon>
|
2022-07-04 10:32:24 +02:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div [class.uk-invisible]="!title"
|
|
|
|
class="uk-width-expand uk-padding-small uk-padding-remove-vertical uk-flex uk-flex-center">
|
2023-02-21 14:14:25 +01:00
|
|
|
<h4 *ngIf="isMobile" class="uk-margin-remove">{{title}}</h4>
|
|
|
|
<h2 *ngIf="!isMobile" class="uk-margin-remove">{{title}}</h2>
|
2022-07-04 10:32:24 +02:00
|
|
|
</div>
|
2023-05-16 15:36:43 +02:00
|
|
|
<div class="uk-width-medium@l uk-width-auto uk-flex"
|
2023-06-22 15:48:10 +02:00
|
|
|
[class.uk-flex-center]="okButton" [class.uk-flex-right]="!okButton">
|
2022-07-04 10:32:24 +02:00
|
|
|
<button *ngIf="okButton" class="uk-button uk-button-default" [disabled]="okButtonDisabled"
|
|
|
|
[class.uk-disabled]="okButtonDisabled" (click)="ok()">
|
|
|
|
{{okButtonText}}
|
|
|
|
</button>
|
2023-05-16 15:36:43 +02:00
|
|
|
<button *ngIf="!okButton && cancelButton" class="uk-close uk-icon" (click)="cancel()">
|
2022-07-13 09:13:29 +02:00
|
|
|
<icon name="close" ratio="2"></icon>
|
2022-07-04 10:32:24 +02:00
|
|
|
</button>
|
2021-03-17 16:42:43 +01:00
|
|
|
</div>
|
2021-03-05 14:31:54 +01:00
|
|
|
</div>
|
2023-07-04 10:08:39 +02:00
|
|
|
<div #body class="uk-modal-body uk-overflow-auto uk-border-box" [ngStyle]="{'height.px': bodyHeight}">
|
2023-07-11 15:03:08 +02:00
|
|
|
<div class="uk-container" style="min-height: 100%" [ngClass]="classBody">
|
2022-07-04 10:32:24 +02:00
|
|
|
<ng-content></ng-content>
|
|
|
|
</div>
|
2021-03-05 14:31:54 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-07-04 10:32:24 +02:00
|
|
|
</div>
|
2021-03-05 14:31:54 +01:00
|
|
|
`
|
|
|
|
})
|
2022-07-04 17:00:10 +02:00
|
|
|
export class FullScreenModalComponent implements AfterViewInit, OnDestroy {
|
2022-07-11 16:27:44 +02:00
|
|
|
private static FS_MODAL_COUNTER: number = 0;
|
|
|
|
|
|
|
|
id: string = "fs-modal";
|
2022-07-04 10:32:24 +02:00
|
|
|
@Input() classTitle: string = "uk-background-primary uk-light";
|
|
|
|
@Input() classBody: string = 'uk-container-large';
|
|
|
|
back: boolean = false;
|
2023-02-20 16:56:02 +01:00
|
|
|
/**
|
|
|
|
* if the value is true then on ok clicked, modal will stay open.
|
|
|
|
*/
|
|
|
|
public stayOpenInBack: boolean = false;
|
2022-07-04 10:32:24 +02:00
|
|
|
title: string;
|
2023-05-16 15:36:43 +02:00
|
|
|
cancelButton: boolean = true;
|
2021-03-12 11:29:58 +01:00
|
|
|
okButton: boolean = false;
|
2022-07-04 10:32:24 +02:00
|
|
|
okButtonText = 'OK';
|
2023-02-21 14:14:25 +01:00
|
|
|
isMobile: boolean = false;
|
2021-03-12 11:00:56 +01:00
|
|
|
@Input()
|
|
|
|
okButtonDisabled = 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>();
|
2022-07-04 17:00:10 +02:00
|
|
|
@ViewChild('modal') modal: ElementRef;
|
|
|
|
@ViewChild('header') header: ElementRef;
|
|
|
|
@ViewChild('body') body: ElementRef;
|
|
|
|
bodyHeight: number;
|
2023-02-21 14:14:25 +01:00
|
|
|
private subscriptions: any[] = [];
|
2022-07-04 17:00:10 +02:00
|
|
|
|
2023-02-21 14:14:25 +01:00
|
|
|
constructor(private cdr: ChangeDetectorRef, private layoutService: LayoutService) {
|
2022-07-04 17:00:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@HostListener('window:resize', ['$event'])
|
|
|
|
onResize() {
|
|
|
|
this.changeHeight();
|
|
|
|
}
|
2022-07-11 16:27:44 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
FullScreenModalComponent.FS_MODAL_COUNTER++;
|
|
|
|
this.id = 'fs-modal-' + FullScreenModalComponent.FS_MODAL_COUNTER;
|
2023-02-21 14:14:25 +01:00
|
|
|
this.subscriptions.push(this.layoutService.isMobile.subscribe(isMobile => {
|
|
|
|
this.isMobile = isMobile;
|
|
|
|
}))
|
2022-07-11 16:27:44 +02:00
|
|
|
}
|
|
|
|
|
2022-07-04 17:00:10 +02:00
|
|
|
ngAfterViewInit() {
|
|
|
|
if(typeof window !== "undefined") {
|
2023-07-04 10:53:08 +02:00
|
|
|
let observer = new ResizeObserver(entries => {
|
2022-07-04 17:00:10 +02:00
|
|
|
for (let entry of entries) {
|
|
|
|
this.changeHeight();
|
|
|
|
}
|
|
|
|
});
|
2023-07-04 10:53:08 +02:00
|
|
|
observer.observe(this.header.nativeElement);
|
|
|
|
this.subscriptions.push(observer);
|
2022-07-04 17:00:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Height = Viewport - header - (Body padding) */
|
|
|
|
changeHeight() {
|
|
|
|
if(typeof window !== "undefined" && this.header) {
|
2023-07-04 10:08:39 +02:00
|
|
|
this.bodyHeight = window.innerHeight - this.header.nativeElement.offsetHeight;
|
2022-07-04 17:00:10 +02:00
|
|
|
this.cdr.detectChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
2022-07-11 16:27:44 +02:00
|
|
|
if(typeof document !== "undefined") {
|
|
|
|
const element = document.getElementById("modal-container");
|
|
|
|
for (let i = element.childNodes.length - 1; i >= 0; --i) {
|
|
|
|
let child: ChildNode = element.childNodes[i];
|
|
|
|
if (child['id'] == this.id) {
|
|
|
|
child.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-21 14:14:25 +01:00
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if(subscription instanceof Subscription) {
|
|
|
|
subscription.unsubscribe();
|
2023-07-04 10:53:08 +02:00
|
|
|
} else if(typeof ResizeObserver != 'undefined' && subscription instanceof ResizeObserver) {
|
|
|
|
subscription.disconnect();
|
2023-02-21 14:14:25 +01:00
|
|
|
}
|
2023-07-04 10:53:08 +02:00
|
|
|
});
|
2022-07-04 17:00:10 +02:00
|
|
|
}
|
2021-03-05 14:31:54 +01:00
|
|
|
|
2022-07-04 10:32:24 +02:00
|
|
|
get isOpen() {
|
2022-07-04 17:00:10 +02:00
|
|
|
return this.modal && UIkit.modal(this.modal.nativeElement).isToggled();
|
2021-03-05 14:31:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
open() {
|
2022-07-04 17:00:10 +02:00
|
|
|
UIkit.modal(this.modal.nativeElement).show();
|
2022-07-04 10:32:24 +02:00
|
|
|
HelperFunctions.scroll();
|
2021-03-05 14:31:54 +01:00
|
|
|
}
|
2023-02-20 16:56:02 +01:00
|
|
|
|
2022-07-04 10:32:24 +02:00
|
|
|
cancel() {
|
2022-07-04 17:00:10 +02:00
|
|
|
UIkit.modal(this.modal.nativeElement).hide();
|
2022-07-04 10:32:24 +02:00
|
|
|
HelperFunctions.scroll();
|
2022-05-30 16:56:47 +02:00
|
|
|
this.cancelEmitter.emit();
|
2021-03-05 14:31:54 +01:00
|
|
|
}
|
2023-02-20 16:56:02 +01:00
|
|
|
|
|
|
|
backClicked() {
|
|
|
|
if(this.stayOpenInBack) {
|
|
|
|
HelperFunctions.scroll();
|
|
|
|
this.cancelEmitter.emit();
|
|
|
|
} else {
|
|
|
|
this.cancel();
|
|
|
|
}
|
|
|
|
}
|
2021-03-05 14:31:54 +01:00
|
|
|
|
|
|
|
ok() {
|
2022-07-04 20:38:27 +02:00
|
|
|
UIkit.modal(this.modal.nativeElement).hide();
|
|
|
|
HelperFunctions.scroll();
|
2021-03-05 14:31:54 +01:00
|
|
|
this.okEmitter.emit(true);
|
|
|
|
}
|
|
|
|
}
|