1
|
import {Component, ViewEncapsulation, ElementRef, EventEmitter, Output, Input} from '@angular/core';
|
2
|
|
3
|
@Component({
|
4
|
selector: 'modal-alert',
|
5
|
template: `
|
6
|
<div [class]="(!isOpen)?'uk-modal ':'uk-modal uk-open uk-animation-fade'" uk-modal [open]="!isOpen" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
|
7
|
<div class="uk-modal-dialog uk-modal-body" role="">
|
8
|
<div class="uk-modal-title" [hidden]=!alertHeader>
|
9
|
<button class="uk-modal-close-default uk-float-right" (click)='cancel()' uk-close></button>
|
10
|
<h4 class="modal-title text-center" id="myModalLabel">{{alertTitle}}</h4>
|
11
|
</div>
|
12
|
<div class="uk-margin ">
|
13
|
<div [hidden]=!alertMessage>
|
14
|
{{message}}
|
15
|
</div>
|
16
|
<ng-content></ng-content>
|
17
|
</div>
|
18
|
<div *ngIf="okButtonLeft" class="uk-text-right" [hidden]=!alertFooter>
|
19
|
<span [hidden]=!okButton >
|
20
|
<button class="uk-button uk-button-default" (click)="ok()">{{okButtonText}}</button>
|
21
|
</span>
|
22
|
<span [hidden]=!cancelButton>
|
23
|
<button class="uk-button uk-button-default" (click)="cancel()">{{cancelButtonText}}</button>
|
24
|
</span>
|
25
|
</div>
|
26
|
<div *ngIf="!okButtonLeft" class="uk-text-right" [hidden]=!alertFooter>
|
27
|
<span [hidden]=!cancelButton>
|
28
|
<button class="uk-button uk-button-default" (click)="cancel()">{{cancelButtonText}}</button>
|
29
|
</span>
|
30
|
<span [hidden]=!okButton >
|
31
|
<button *ngIf="okDisabled" class="uk-button uk-button-default" disabled>{{okButtonText}}</button>
|
32
|
<button *ngIf="!okDisabled" class="uk-button portal-button" (click)="ok()">{{okButtonText}}</button>
|
33
|
</span>
|
34
|
</div>
|
35
|
|
36
|
</div>
|
37
|
</div>
|
38
|
|
39
|
|
40
|
`,
|
41
|
encapsulation: ViewEncapsulation.None,
|
42
|
})
|
43
|
/**
|
44
|
* API to an open alert window.
|
45
|
*/
|
46
|
export class AlertModal{
|
47
|
/**
|
48
|
* Caption for the title.
|
49
|
*/
|
50
|
public alertTitle:string;
|
51
|
/**
|
52
|
* Describes if the alert contains Ok Button.
|
53
|
* The default Ok button will close the alert and emit the callback.
|
54
|
* Defaults to true.
|
55
|
*/
|
56
|
public okButton:boolean = true;
|
57
|
/**
|
58
|
* Caption for the OK button.
|
59
|
* Default: Ok
|
60
|
*/
|
61
|
public okButtonText:string= 'Ok';
|
62
|
/**
|
63
|
* Describes if the alert contains cancel Button.
|
64
|
* The default Cancelbutton will close the alert.
|
65
|
* Defaults to true.
|
66
|
*/
|
67
|
public cancelButton:boolean = true;
|
68
|
/**
|
69
|
* Caption for the Cancel button.
|
70
|
* Default: Cancel
|
71
|
*/
|
72
|
public cancelButtonText:string = 'Cancel';
|
73
|
/**
|
74
|
* if the alertMessage is true it will show the contentString inside alert body.
|
75
|
*/
|
76
|
public alertMessage:boolean = true;
|
77
|
/**
|
78
|
* Some message/content can be set in message which will be shown in alert body.
|
79
|
*/
|
80
|
public message:string;
|
81
|
/**
|
82
|
* if the value is true alert footer will be visible or else it will be hidden.
|
83
|
*/
|
84
|
public alertFooter:boolean= true;
|
85
|
/**
|
86
|
* shows alert header if the value is true.
|
87
|
*/
|
88
|
public alertHeader:boolean = true;
|
89
|
/**
|
90
|
* if the value is true alert will be visible or else it will be hidden.
|
91
|
*/
|
92
|
public isOpen:boolean=false;
|
93
|
|
94
|
/**
|
95
|
* if the value is true ok button align on the left, else on the right
|
96
|
*/
|
97
|
public okButtonLeft: boolean = true;
|
98
|
|
99
|
/**
|
100
|
* if the value is true ok button is disabled
|
101
|
*/
|
102
|
@Input()
|
103
|
public okDisabled: boolean = false;
|
104
|
/**
|
105
|
* Emitted when a ok button was clicked
|
106
|
* or when Ok method is called.
|
107
|
*/
|
108
|
@Output() public alertOutput:EventEmitter<any> = new EventEmitter();
|
109
|
constructor( public _elementRef: ElementRef){}
|
110
|
/**
|
111
|
* Opens a alert window creating backdrop.
|
112
|
*/
|
113
|
open(){
|
114
|
this.isOpen= true;
|
115
|
}
|
116
|
/**
|
117
|
* ok method closes the modal and emits modalOutput.
|
118
|
*/
|
119
|
ok(){
|
120
|
this.isOpen = false;
|
121
|
this.alertOutput.emit(true);
|
122
|
}
|
123
|
/**
|
124
|
* cancel method closes the moda.
|
125
|
*/
|
126
|
cancel(){
|
127
|
this.isOpen = false;
|
128
|
}
|
129
|
}
|