Project

General

Profile

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
          <ng-content></ng-content>
20
        </div>
21
        <div class="  uk-text-right" [hidden]=!alertFooter>
22
        <span [hidden]=!okButton >
23
          <button class=" uk-button uk-button-default  " (click)="ok()">{{okButtonText}}</button>
24
          </span>
25
          <span [hidden]=!cancelButton>
26
          <button class=" uk-button uk-button-default" (click)="cancel()">{{cancelButtonText}}</button>
27
          </span>
28
        </div>
29

    
30
    </div>
31
  </div>
32

    
33

    
34
  `,
35
  encapsulation: ViewEncapsulation.None,
36
})
37
/**
38
  * API to an open alert window.
39
  */
40
export class AlertModal{
41
  /**
42
     * Caption for the title.
43
     */
44
  public alertTitle:string;
45
  /**
46
     * Describes if the alert contains Ok Button.
47
     * The default Ok button will close the alert and emit the callback.
48
     * Defaults to true.
49
     */
50
  public okButton:boolean = true;
51
  /**
52
     * Caption for the OK button.
53
     * Default: Ok
54
     */
55
  public okButtonText:string= 'Ok';
56
  /**
57
     * Describes if the alert contains cancel Button.
58
     * The default Cancelbutton will close the alert.
59
     * Defaults to true.
60
     */
61
  public cancelButton:boolean = true;
62
  /**
63
     * Caption for the Cancel button.
64
     * Default: Cancel
65
     */
66
  public cancelButtonText:string = 'Cancel';
67
  /**
68
     * if the alertMessage is true it will show the contentString inside alert body.
69
     */
70
  public alertMessage:boolean = true;
71
  /**
72
     * Some message/content can be set in message which will be shown in alert body.
73
     */
74
  public message:string;
75
  /**
76
    * if the value is true alert footer will be visible or else it will be hidden.
77
    */
78
  public alertFooter:boolean= true;
79
  /**
80
    * shows alert header if the value is true.
81
    */
82
  public alertHeader:boolean = true;
83
  /**
84
    * if the value is true alert will be visible or else it will be hidden.
85
    */
86
  public isOpen:boolean=false;
87
  /**
88
    * Emitted when a ok button was clicked
89
    * or when Ok method is called.
90
    */
91
  @Output() public alertOutput:EventEmitter<any> = new EventEmitter();
92
  constructor( public _elementRef: ElementRef){}
93
  /**
94
       * Opens a alert window creating backdrop.
95
       */
96
  open(){
97
    this.isOpen= true;
98
  }
99
  /**
100
     *  ok method closes the modal and emits modalOutput.
101
     */
102
  ok(){
103
    this.isOpen = false;
104
    this.alertOutput.emit(true);
105
  }
106
  /**
107
     *  cancel method closes the moda.
108
     */
109
  cancel(){
110
    this.isOpen = false;
111
  }
112
}
(1-1/8)