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>
|
2022-04-20 16:40:18 +02:00
|
|
|
<div class="uk-modal-dialog">
|
|
|
|
<div class="uk-modal-header uk-flex uk-flex-middle uk-flex-between" [ngClass]="classTitle">
|
|
|
|
<div class="uk-modal-title" [hidden]=!alertHeader>
|
|
|
|
<h5 class="uk-margin-remove">{{alertTitle}}</h5>
|
|
|
|
</div>
|
|
|
|
<button class="uk-close uk-icon uk-margin-left" (click)='cancel()'>
|
2022-04-07 00:09:49 +02:00
|
|
|
<icon name="close" ratio="1.5"></icon>
|
|
|
|
</button>
|
2017-12-19 13:53:46 +01:00
|
|
|
</div>
|
2022-04-20 16:40:18 +02:00
|
|
|
<div 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-04-20 16:40:18 +02:00
|
|
|
<div *ngIf="choice || okButton || cancelButton" 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'">
|
2022-04-20 16:40:18 +02:00
|
|
|
<div *ngIf="alertFooter" 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 uk-box-no-shadow" [disabled]="okDisabled"
|
|
|
|
[class.uk-disabled]="okDisabled" (click)="ok()">{{okButtonText}}</button>
|
|
|
|
</span>
|
|
|
|
<span *ngIf="cancelButton">
|
|
|
|
<button class="uk-button uk-button-default uk-box-no-shadow uk-margin-small-left"
|
|
|
|
(click)="cancel()">{{cancelButtonText}}</button>
|
|
|
|
</span>
|
|
|
|
</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.
|
|
|
|
*/
|
|
|
|
export class AlertModal {
|
2020-09-29 16:24:38 +02:00
|
|
|
@Input() 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;
|
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();
|
2022-05-30 12:56:14 +02:00
|
|
|
|
2022-05-25 11:52:00 +02:00
|
|
|
|
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
|
|
|
}
|
2022-05-30 12:56:14 +02:00
|
|
|
|
2022-05-25 11:52:00 +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
|
|
|
}
|