2023-03-21 13:00:47 +01:00
|
|
|
import {
|
|
|
|
AfterViewInit,
|
|
|
|
Component,
|
|
|
|
ElementRef,
|
|
|
|
EventEmitter,
|
|
|
|
Input, OnDestroy,
|
|
|
|
OnInit,
|
|
|
|
Output,
|
|
|
|
ViewChild,
|
|
|
|
ViewEncapsulation
|
|
|
|
} from '@angular/core';
|
2019-11-22 09:51:17 +01:00
|
|
|
|
|
|
|
declare var UIkit: any;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'modal-alert',
|
|
|
|
template: `
|
2022-06-20 12:02:23 +02:00
|
|
|
<div #element class="uk-modal" [class.uk-modal-container]="large" [id]="id" uk-modal="container: #modal-container">
|
2022-04-20 16:40:18 +02:00
|
|
|
<div class="uk-modal-dialog">
|
2022-07-04 10:32:24 +02:00
|
|
|
<div class="uk-modal-header uk-flex uk-flex-middle uk-flex-between" [ngClass]="classTitle">
|
|
|
|
<div [class.uk-invisible]="!alertHeader">
|
2023-08-24 17:20:49 +02:00
|
|
|
<h6 class="uk-margin-remove">{{alertTitle}}</h6>
|
2022-04-20 16:40:18 +02:00
|
|
|
</div>
|
2022-07-04 10:32:24 +02:00
|
|
|
<button class="uk-close uk-icon uk-margin-left" (click)="cancel()">
|
2023-08-24 17:20:49 +02:00
|
|
|
<icon name="close" ratio="1.4"></icon>
|
2022-04-07 00:09:49 +02:00
|
|
|
</button>
|
2017-12-19 13:53:46 +01:00
|
|
|
</div>
|
2023-02-20 15:34:12 +01:00
|
|
|
<div #bodyElement class="uk-modal-body uk-animation-fast uk-text-left"
|
2022-06-02 16:27:45 +02:00
|
|
|
[ngClass]="classBody" [attr.uk-overflow-auto]="overflowBody?'':null">
|
2021-03-01 18:32:21 +01:00
|
|
|
<div *ngIf="message" [hidden]=!alertMessage [innerHTML]="message | safeHtml"></div>
|
2018-04-04 18:01:57 +02:00
|
|
|
<ng-content></ng-content>
|
2017-12-19 13:53:46 +01:00
|
|
|
</div>
|
2022-09-14 15:31:55 +02:00
|
|
|
<div *ngIf="(choice || okButton || cancelButton) && alertFooter" class="uk-modal-footer">
|
2022-06-02 17:12:27 +02:00
|
|
|
<div class="uk-grid uk-flex uk-flex-middle" uk-grid>
|
|
|
|
<label *ngIf="choice" class="uk-width-expand">
|
2022-04-20 16:40:18 +02:00
|
|
|
<input type="checkbox" [(ngModel)]="select">
|
|
|
|
<span class="uk-margin-small-left">Don't show this message again</span>
|
|
|
|
</label>
|
2022-06-02 17:12:27 +02:00
|
|
|
<div [ngClass]="(choice)?'uk-width-auto':'uk-width-1-1'">
|
2023-02-18 09:52:24 +01:00
|
|
|
<div class="uk-width-1-1" [ngClass]="(previousButton && (cancelButton || okButton)) ? 'uk-flex uk-flex-between uk-grid' : ''">
|
|
|
|
<div *ngIf="previousButton" class="uk-flex-left">
|
2022-06-20 15:20:03 +02:00
|
|
|
<button class="uk-button uk-button-default uk-margin-small-left"
|
2023-02-18 09:52:24 +01:00
|
|
|
(click)="previous()">{{previousButtonText}}</button>
|
|
|
|
</div>
|
|
|
|
<div class="uk-flex-right uk-grid uk-grid-small" uk-grid>
|
|
|
|
<span *ngIf="okButton" [class.uk-flex-last]="!okButtonLeft">
|
|
|
|
<button class="uk-button uk-button-primary" [disabled]="okDisabled"
|
|
|
|
[class.uk-disabled]="okDisabled" (click)="ok()">{{okButtonText}}</button>
|
|
|
|
</span>
|
|
|
|
<span *ngIf="cancelButton">
|
|
|
|
<button class="uk-button uk-button-default uk-margin-small-left"
|
|
|
|
(click)="cancel()">{{cancelButtonText}}</button>
|
|
|
|
</span>
|
|
|
|
</div>
|
2022-04-20 16:40:18 +02:00
|
|
|
</div>
|
2019-07-30 15:26:31 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
</div>
|
2019-07-30 15:26:31 +02:00
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
encapsulation: ViewEncapsulation.None,
|
|
|
|
})
|
|
|
|
/**
|
2019-07-30 15:26:31 +02:00
|
|
|
* API to an open alert window.
|
|
|
|
*/
|
2023-03-21 13:00:47 +01:00
|
|
|
export class AlertModal implements OnInit, AfterViewInit, OnDestroy {
|
2022-07-11 16:27:44 +02:00
|
|
|
private static MODAL_COUNTER: number = 0;
|
|
|
|
|
|
|
|
id: string = "modal";
|
2022-04-20 16:40:18 +02:00
|
|
|
@Input() classTitle: string = "uk-background-primary-opacity";
|
2019-11-22 09:51:17 +01:00
|
|
|
@Input() classBody: string = "";
|
2020-10-19 11:06:23 +02:00
|
|
|
@Input() large: boolean = false;
|
2022-04-20 16:40:18 +02:00
|
|
|
@Input() overflowBody: boolean = true;
|
2023-02-20 15:34:12 +01:00
|
|
|
@ViewChild("bodyElement") bodyElement: ElementRef;
|
2019-07-30 15:26:31 +02:00
|
|
|
/**
|
|
|
|
* Caption for the title.
|
|
|
|
*/
|
|
|
|
public alertTitle: string;
|
|
|
|
/**
|
|
|
|
* Describes if the alert contains Ok Button.
|
|
|
|
* The default Ok button will close the alert and emit the callback.
|
|
|
|
* Defaults to true.
|
|
|
|
*/
|
|
|
|
public okButton: boolean = true;
|
|
|
|
/**
|
|
|
|
* Caption for the OK button.
|
|
|
|
* Default: Ok
|
|
|
|
*/
|
2020-10-29 15:20:41 +01:00
|
|
|
public okButtonText: string = 'OK';
|
2019-07-30 15:26:31 +02:00
|
|
|
/**
|
|
|
|
* Describes if the alert contains cancel Button.
|
|
|
|
* The default Cancelbutton will close the alert.
|
|
|
|
* Defaults to true.
|
|
|
|
*/
|
|
|
|
public cancelButton: boolean = true;
|
|
|
|
/**
|
|
|
|
* Caption for the Cancel button.
|
|
|
|
* Default: Cancel
|
|
|
|
*/
|
|
|
|
public cancelButtonText: string = 'Cancel';
|
|
|
|
/**
|
|
|
|
* if the alertMessage is true it will show the contentString inside alert body.
|
|
|
|
*/
|
2023-02-18 09:52:24 +01:00
|
|
|
/**
|
|
|
|
* Describes if the alert contains Previous Button.
|
|
|
|
* The default Previous button will emit the callback.
|
|
|
|
* Defaults to false.
|
|
|
|
*/
|
|
|
|
public previousButton: boolean = false;
|
|
|
|
/**
|
|
|
|
* Caption for the Previous button.
|
|
|
|
* Default: Previous
|
|
|
|
*/
|
|
|
|
public previousButtonText: string = 'Previous';
|
2019-07-30 15:26:31 +02:00
|
|
|
public alertMessage: boolean = true;
|
|
|
|
/**
|
|
|
|
* Some message/content can be set in message which will be shown in alert body.
|
|
|
|
*/
|
|
|
|
public message: string;
|
|
|
|
/**
|
|
|
|
* if the value is true alert footer will be visible or else it will be hidden.
|
|
|
|
*/
|
|
|
|
public alertFooter: boolean = true;
|
|
|
|
/**
|
|
|
|
* shows alert header if the value is true.
|
|
|
|
*/
|
|
|
|
public alertHeader: boolean = true;
|
2019-06-02 20:52:26 +02:00
|
|
|
/**
|
|
|
|
* if the value is true ok button align on the left, else on the right
|
|
|
|
*/
|
2019-04-05 19:21:23 +02:00
|
|
|
public okButtonLeft: boolean = true;
|
2019-06-02 20:52:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* if the value is true ok button is disabled
|
|
|
|
*/
|
|
|
|
@Input()
|
|
|
|
public okDisabled: boolean = false;
|
2019-07-30 15:26:31 +02:00
|
|
|
|
2019-11-27 11:08:04 +01:00
|
|
|
/**
|
|
|
|
* If the value is true, a checkbox option will be appeared on the right side of footer
|
|
|
|
*/
|
2019-07-30 15:26:31 +02:00
|
|
|
@Input()
|
|
|
|
public choice: boolean = false;
|
|
|
|
|
2019-11-27 11:08:04 +01:00
|
|
|
/**
|
|
|
|
* if the value is true then on ok clicked, modal will stay open.
|
|
|
|
*/
|
|
|
|
public stayOpen: boolean = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Value will be emitted if @choice is true
|
|
|
|
*/
|
2022-03-03 11:40:14 +01:00
|
|
|
public select: boolean = true;
|
2017-12-19 13:53:46 +01:00
|
|
|
/**
|
2022-06-20 15:17:26 +02:00
|
|
|
* Emitted when ok button was clicked
|
2019-07-30 15:26:31 +02:00
|
|
|
* or when Ok method is called.
|
|
|
|
*/
|
|
|
|
@Output() public alertOutput: EventEmitter<any> = new EventEmitter();
|
2022-06-20 15:17:26 +02:00
|
|
|
/**
|
|
|
|
* Emitted when cancel button was clicked
|
|
|
|
* or when cancel method is called.
|
|
|
|
*/
|
|
|
|
@Output() public cancelOutput: EventEmitter<any> = new EventEmitter();
|
2022-05-25 11:52:00 +02:00
|
|
|
|
2019-11-22 09:51:17 +01:00
|
|
|
@ViewChild('element') element: ElementRef;
|
2023-03-21 13:00:47 +01:00
|
|
|
private subscriptions: any[] = [];
|
2019-11-22 09:51:17 +01:00
|
|
|
|
2019-11-27 11:08:04 +01:00
|
|
|
constructor() {
|
2019-07-30 15:26:31 +02:00
|
|
|
}
|
2022-07-11 16:27:44 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
AlertModal.MODAL_COUNTER++;
|
|
|
|
this.id = 'modal-' + AlertModal.MODAL_COUNTER;
|
|
|
|
}
|
|
|
|
|
2023-03-21 13:00:47 +01:00
|
|
|
ngAfterViewInit() {
|
2023-03-23 08:18:19 +01:00
|
|
|
if(this.element && typeof document !== "undefined") {
|
2023-03-21 13:00:47 +01:00
|
|
|
this.subscriptions.push(UIkit.util.on(document, 'hide', '#' + this.id, () => {
|
|
|
|
this.cancelOutput.emit(true);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 16:27:44 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
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-03-21 13:00:47 +01:00
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if(subscription instanceof Function) {
|
|
|
|
subscription();
|
|
|
|
}
|
|
|
|
});
|
2022-07-11 16:27:44 +02:00
|
|
|
}
|
2022-05-25 11:52:00 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
/**
|
2022-06-20 15:17:26 +02:00
|
|
|
* Opens an alert window creating backdrop.
|
2019-07-30 15:26:31 +02:00
|
|
|
*/
|
|
|
|
open() {
|
2023-05-11 12:04:09 +02:00
|
|
|
if(typeof UIkit !== "undefined") {
|
|
|
|
UIkit.modal(this.element.nativeElement).show();
|
2023-07-18 14:27:02 +02:00
|
|
|
if(this.overflowBody) {
|
|
|
|
this.bodyElement.nativeElement.scrollTo(0, 0);
|
|
|
|
}
|
2023-05-11 12:04:09 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-30 15:26:31 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
/**
|
2019-07-30 15:26:31 +02:00
|
|
|
* ok method closes the modal and emits modalOutput.
|
|
|
|
*/
|
|
|
|
ok() {
|
2023-05-11 12:04:09 +02:00
|
|
|
if (!this.stayOpen && typeof UIkit !== "undefined") {
|
2022-07-19 14:18:56 +02:00
|
|
|
UIkit.modal(this.element.nativeElement).hide();
|
2019-11-27 11:08:04 +01:00
|
|
|
}
|
2019-07-30 15:26:31 +02:00
|
|
|
if (!this.choice) {
|
|
|
|
this.alertOutput.emit(true);
|
|
|
|
} else {
|
|
|
|
this.alertOutput.emit({
|
|
|
|
value: true,
|
|
|
|
choice: this.select
|
|
|
|
});
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-30 15:26:31 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
/**
|
2019-10-10 14:13:01 +02:00
|
|
|
* cancel method closes the modal.
|
2019-07-30 15:26:31 +02:00
|
|
|
*/
|
|
|
|
cancel() {
|
2023-05-11 12:04:09 +02:00
|
|
|
if(typeof UIkit !== "undefined") {
|
|
|
|
UIkit.modal(this.element.nativeElement).hide();
|
|
|
|
}
|
2019-10-04 10:45:51 +02:00
|
|
|
}
|
2023-02-18 09:52:24 +01:00
|
|
|
|
|
|
|
previous() {
|
|
|
|
this.cancelOutput.emit();
|
|
|
|
}
|
2023-02-20 15:34:12 +01:00
|
|
|
|
|
|
|
get bodyHeight() {
|
|
|
|
return (this.bodyElement) ? this.bodyElement.nativeElement.offsetHeight : 0;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|