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