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