2019-11-22 09:51:17 +01:00
|
|
|
import {Component, ViewEncapsulation, ElementRef, EventEmitter, Output, Input, ViewChild} from '@angular/core';
|
|
|
|
|
|
|
|
declare var UIkit: any;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'modal-alert',
|
|
|
|
template: `
|
2019-11-22 09:51:17 +01:00
|
|
|
<div #element class="uk-modal" uk-modal
|
|
|
|
id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
|
2019-11-24 17:28:25 +01:00
|
|
|
<div class="uk-modal-dialog uk-modal-body uk-animation-slide-bottom-small uk-margin-medium-bottom uk-text-left"
|
|
|
|
[ngClass]="classBody" role="">
|
2019-07-30 15:26:31 +02:00
|
|
|
<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>
|
2019-12-18 16:14:21 +01:00
|
|
|
<button *ngIf="okDisabled" class="uk-button md-btn disabled uk-button-default ignoreCommunityPanelBackground" disabled>{{okButtonText}}</button>
|
|
|
|
<button *ngIf="!okDisabled"
|
|
|
|
class="uk-button md-btn md-btn-primary portal-button ignoreCommunityPanelBackground"
|
|
|
|
(click)="ok()">{{okButtonText}}</button>
|
2019-07-30 15:26:31 +02:00
|
|
|
</span>
|
|
|
|
<span [hidden]=!cancelButton>
|
2019-11-19 15:23:17 +01:00
|
|
|
<button class="uk-button md-btn uk-button-default uk-margin-small-left"
|
2019-07-30 15:26:31 +02:00
|
|
|
(click)="cancel()">{{cancelButtonText}}</button>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div *ngIf="!okButtonLeft" class="uk-text-right" [hidden]=!alertFooter>
|
|
|
|
<span [hidden]=!cancelButton>
|
2019-11-19 15:23:17 +01:00
|
|
|
<button class="uk-button md-btn uk-button-default uk-margin-small-right"
|
2019-07-30 15:26:31 +02:00
|
|
|
(click)="cancel()">{{cancelButtonText}}</button>
|
|
|
|
</span>
|
|
|
|
<span [hidden]=!okButton>
|
2019-11-26 18:53:05 +01:00
|
|
|
<button *ngIf="okDisabled" class="uk-button md-btn disabled uk-button-default ignoreCommunityPanelBackground"
|
2019-11-22 09:51:17 +01:00
|
|
|
disabled>{{okButtonText}}</button>
|
|
|
|
<button *ngIf="!okDisabled"
|
|
|
|
class="uk-button md-btn md-btn-primary portal-button ignoreCommunityPanelBackground"
|
|
|
|
(click)="ok()">{{okButtonText}}</button>
|
2019-07-30 15:26:31 +02:00
|
|
|
</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 {
|
2019-11-22 09:51:17 +01:00
|
|
|
@Input() classBody: string = "";
|
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
|
|
|
|
*/
|
|
|
|
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;
|
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
|
|
|
|
*/
|
2019-07-30 15:26:31 +02:00
|
|
|
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();
|
|
|
|
|
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
|
|
|
}
|