2019-11-22 09:51:17 +01:00
|
|
|
import {Component, ViewEncapsulation, ElementRef, EventEmitter, Output, Input, ViewChild} from '@angular/core';
|
2020-10-29 15:20:41 +01:00
|
|
|
import {properties} from "../../../../environments/environment";
|
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: `
|
2020-10-19 11:06:23 +02:00
|
|
|
<div #element class="uk-modal" [class.uk-modal-container]="large" [id]="id" uk-modal>
|
2020-05-25 12:50:17 +02:00
|
|
|
<div class="uk-modal-dialog uk-modal-body uk-animation-fast uk-margin-medium-bottom uk-text-left"
|
|
|
|
[ngClass]="classBody">
|
2020-05-20 18:45:50 +02:00
|
|
|
<div [ngClass]="classTitle" class="uk-modal-title" [hidden]=!alertHeader>
|
2022-04-07 00:09:49 +02:00
|
|
|
<button class="uk-close uk-icon uk-modal-close-default uk-float-right" (click)='cancel()'>
|
|
|
|
<icon name="close" ratio="1.5"></icon>
|
|
|
|
</button>
|
|
|
|
<h5>{{alertTitle}}</h5>
|
2017-12-19 13:53:46 +01:00
|
|
|
</div>
|
2019-07-30 15:26:31 +02:00
|
|
|
<div class="uk-margin">
|
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>
|
2019-07-30 15:26:31 +02:00
|
|
|
<div class="uk-grid uk-flex uk-flex-middle">
|
2022-04-07 00:09:49 +02:00
|
|
|
<label *ngIf="choice" class="uk-width-1-2">
|
2019-07-30 15:26:31 +02:00
|
|
|
<input type="checkbox" [(ngModel)]="select">
|
2022-04-07 00:09:49 +02:00
|
|
|
<span class="uk-margin-small-left">Don't show this message again</span>
|
2019-07-30 15:26:31 +02:00
|
|
|
</label>
|
|
|
|
<div [ngClass]="(choice)?'uk-width-1-2':'uk-width-1-1'">
|
2022-01-12 13:12:30 +01:00
|
|
|
<div *ngIf="alertFooter" class="uk-flex-right uk-grid uk-grid-small" uk-grid>
|
|
|
|
<span *ngIf="okButton" [class.uk-flex-last]="!okButtonLeft">
|
2022-03-02 22:48:21 +01:00
|
|
|
<button class="uk-button uk-button-primary" [disabled]="okDisabled"
|
2022-01-12 13:12:30 +01:00
|
|
|
[class.uk-disabled]="okDisabled" (click)="ok()">{{okButtonText}}</button>
|
2019-07-30 15:26:31 +02:00
|
|
|
</span>
|
2022-01-12 13:12:30 +01:00
|
|
|
<span *ngIf="cancelButton">
|
|
|
|
<button class="uk-button uk-button-default uk-margin-small-left"
|
2019-07-30 15:26:31 +02:00
|
|
|
(click)="cancel()">{{cancelButtonText}}</button>
|
|
|
|
</span>
|
|
|
|
</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.
|
|
|
|
*/
|
|
|
|
export class AlertModal {
|
2020-09-29 16:24:38 +02:00
|
|
|
@Input() id: string = "modal";
|
2020-05-20 18:45:50 +02:00
|
|
|
@Input() classTitle: string = "";
|
2019-11-22 09:51:17 +01:00
|
|
|
@Input() classBody: string = "";
|
2020-10-19 11:06:23 +02:00
|
|
|
@Input() large: boolean = false;
|
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.
|
|
|
|
*/
|
|
|
|
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
|
|
|
/**
|
2019-07-30 15:26:31 +02:00
|
|
|
* Emitted when a ok button was clicked
|
|
|
|
* or when Ok method is called.
|
|
|
|
*/
|
|
|
|
@Output() public alertOutput: EventEmitter<any> = new EventEmitter();
|
|
|
|
|
2019-11-22 09:51:17 +01:00
|
|
|
@ViewChild('element') element: ElementRef;
|
|
|
|
|
2019-11-27 11:08:04 +01:00
|
|
|
constructor() {
|
2019-07-30 15:26:31 +02:00
|
|
|
}
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
/**
|
2019-07-30 15:26:31 +02:00
|
|
|
* Opens a alert window creating backdrop.
|
|
|
|
*/
|
|
|
|
open() {
|
2019-11-22 09:51:17 +01:00
|
|
|
UIkit.modal(this.element.nativeElement).show();
|
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() {
|
2019-12-18 16:14:21 +01:00
|
|
|
if (!this.stayOpen) {
|
2019-11-27 11:08:04 +01:00
|
|
|
this.cancel();
|
|
|
|
}
|
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() {
|
2019-11-22 09:51:17 +01:00
|
|
|
UIkit.modal(this.element.nativeElement).hide();
|
2019-10-04 10:45:51 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|