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