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