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