2019-06-02 20:52:26 +02:00
|
|
|
import {Component, ViewEncapsulation, ElementRef, EventEmitter, Output, Input} from '@angular/core';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'modal-alert',
|
|
|
|
template: `
|
2019-07-30 15:26:31 +02:00
|
|
|
<div [class]="(!isOpen)?'uk-modal ':'uk-modal uk-open'" uk-modal [open]="!isOpen" id="myModal"
|
|
|
|
tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
|
|
|
|
<div class="uk-modal-dialog uk-modal-body uk-animation-slide-bottom-small uk-text-left" role="">
|
|
|
|
<div class="uk-modal-title" [hidden]=!alertHeader>
|
|
|
|
<button class="uk-modal-close-default uk-float-right" (click)='cancel()' uk-close></button>
|
|
|
|
<h4 class="modal-title" id="myModalLabel">{{alertTitle}}</h4>
|
2017-12-19 13:53:46 +01:00
|
|
|
</div>
|
2019-07-30 15:26:31 +02:00
|
|
|
<div class="uk-margin">
|
2017-12-19 13:53:46 +01:00
|
|
|
<div [hidden]=!alertMessage>
|
2019-07-30 15:26:31 +02:00
|
|
|
{{message}}
|
2017-12-19 13:53:46 +01:00
|
|
|
</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">
|
|
|
|
<label *ngIf="choice" class="uk-width-1-2 checkbox">
|
|
|
|
<input type="checkbox" [(ngModel)]="select">
|
|
|
|
<span class="uk-margin-small-left" style="font-weight: normal;">Don't show this message again</span>
|
|
|
|
</label>
|
|
|
|
<div [ngClass]="(choice)?'uk-width-1-2':'uk-width-1-1'">
|
|
|
|
<div *ngIf="okButtonLeft" class="uk-text-right" [hidden]=!alertFooter>
|
|
|
|
<span [hidden]=!okButton>
|
|
|
|
<button class="uk-button uk-button-default" (click)="ok()">{{okButtonText}}</button>
|
|
|
|
</span>
|
|
|
|
<span [hidden]=!cancelButton>
|
|
|
|
<button class="uk-button uk-button-default uk-margin-small-left"
|
|
|
|
(click)="cancel()">{{cancelButtonText}}</button>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div *ngIf="!okButtonLeft" class="uk-text-right" [hidden]=!alertFooter>
|
|
|
|
<span [hidden]=!cancelButton>
|
|
|
|
<button class="uk-button uk-button-default uk-margin-small-right"
|
|
|
|
(click)="cancel()">{{cancelButtonText}}</button>
|
|
|
|
</span>
|
|
|
|
<span [hidden]=!okButton>
|
|
|
|
<button *ngIf="okDisabled" class="uk-button uk-button-default" disabled>{{okButtonText}}</button>
|
|
|
|
<button *ngIf="!okDisabled" class="uk-button portal-button" (click)="ok()">{{okButtonText}}</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 {
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
public okButtonText: string = 'Ok';
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
/**
|
|
|
|
* if the value is true alert will be visible or else it will be hidden.
|
|
|
|
*/
|
|
|
|
public isOpen: boolean = false;
|
2019-04-05 19:21:23 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
@Input()
|
|
|
|
public choice: boolean = false;
|
|
|
|
|
|
|
|
public select: boolean = false;
|
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();
|
|
|
|
|
|
|
|
constructor(public _elementRef: ElementRef) {
|
|
|
|
}
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
/**
|
2019-07-30 15:26:31 +02:00
|
|
|
* Opens a alert window creating backdrop.
|
|
|
|
*/
|
|
|
|
open() {
|
|
|
|
this.isOpen = true;
|
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() {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.isOpen = false;
|
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-07-30 15:26:31 +02:00
|
|
|
* cancel method closes the moda.
|
|
|
|
*/
|
|
|
|
cancel() {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.isOpen = false;
|
|
|
|
}
|
|
|
|
}
|