Project

General

Profile

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 57665 k.triantaf
    <div #element class="uk-modal" uk-modal
9
         id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
10 57672 k.triantaf
      <div class="uk-modal-dialog uk-modal-body uk-animation-slide-bottom-small uk-margin-medium-bottom uk-text-left"
11
           [ngClass]="classBody" role="">
12 56808 k.triantaf
        <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 50169 argiro.kok
        </div>
16 56808 k.triantaf
        <div class="uk-margin">
17 50169 argiro.kok
          <div [hidden]=!alertMessage>
18 56808 k.triantaf
            {{message}}
19 50169 argiro.kok
          </div>
20 51672 konstantin
          <ng-content></ng-content>
21 50169 argiro.kok
        </div>
22 56808 k.triantaf
        <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 57638 k.triantaf
                <button class="uk-button md-btn uk-button-default" (click)="ok()">{{okButtonText}}</button>
31 56808 k.triantaf
              </span>
32
              <span [hidden]=!cancelButton>
33 57638 k.triantaf
                <button class="uk-button md-btn uk-button-default uk-margin-small-left"
34 56808 k.triantaf
                        (click)="cancel()">{{cancelButtonText}}</button>
35
              </span>
36
            </div>
37
            <div *ngIf="!okButtonLeft" class="uk-text-right" [hidden]=!alertFooter>
38
               <span [hidden]=!cancelButton>
39 57638 k.triantaf
                  <button class="uk-button md-btn uk-button-default uk-margin-small-right"
40 56808 k.triantaf
                          (click)="cancel()">{{cancelButtonText}}</button>
41
              </span>
42
              <span [hidden]=!okButton>
43 57665 k.triantaf
              <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 56808 k.triantaf
            </span>
49
            </div>
50
          </div>
51 50169 argiro.kok
        </div>
52 56808 k.triantaf
      </div>
53 50169 argiro.kok
    </div>
54
  `,
55
  encapsulation: ViewEncapsulation.None,
56
})
57
/**
58 56808 k.triantaf
 * API to an open alert window.
59
 */
60
export class AlertModal {
61 57665 k.triantaf
  @Input() classBody: string = "";
62 50169 argiro.kok
  /**
63 56808 k.triantaf
   * Caption for the title.
64
   */
65
  public alertTitle: string;
66 50169 argiro.kok
  /**
67 56808 k.triantaf
   * 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 50169 argiro.kok
  /**
73 56808 k.triantaf
   * Caption for the OK button.
74
   * Default: Ok
75
   */
76
  public okButtonText: string = 'Ok';
77 50169 argiro.kok
  /**
78 56808 k.triantaf
   * 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 50169 argiro.kok
  /**
84 56808 k.triantaf
   * Caption for the Cancel button.
85
   * Default: Cancel
86
   */
87
  public cancelButtonText: string = 'Cancel';
88 50169 argiro.kok
  /**
89 56808 k.triantaf
   * if the alertMessage is true it will show the contentString inside alert body.
90
   */
91
  public alertMessage: boolean = true;
92 50169 argiro.kok
  /**
93 56808 k.triantaf
   * Some message/content can be set in message which will be shown in alert body.
94
   */
95
  public message: string;
96 50169 argiro.kok
  /**
97 56808 k.triantaf
   * if the value is true alert footer will be visible or else it will be hidden.
98
   */
99
  public alertFooter: boolean = true;
100 50169 argiro.kok
  /**
101 56808 k.triantaf
   * shows alert header if the value is true.
102
   */
103
  public alertHeader: boolean = true;
104 50169 argiro.kok
  /**
105 55945 k.triantaf
   *  if the value is true ok button align on the left, else on the right
106
   */
107 55209 k.triantaf
  public okButtonLeft: boolean = true;
108 55945 k.triantaf
109 50169 argiro.kok
  /**
110 55945 k.triantaf
   *  if the value is true ok button is disabled
111
   */
112
  @Input()
113
  public okDisabled: boolean = false;
114 56808 k.triantaf
115
  @Input()
116
  public choice: boolean = false;
117
118
  public select: boolean = false;
119 55945 k.triantaf
  /**
120 56808 k.triantaf
   * Emitted when a ok button was clicked
121
   * or when Ok method is called.
122
   */
123
  @Output() public alertOutput: EventEmitter<any> = new EventEmitter();
124 57261 k.triantaf
  @Output() public clickOutsideOutput: EventEmitter<any> = new EventEmitter();
125 56808 k.triantaf
126 57665 k.triantaf
  @ViewChild('element') element: ElementRef;
127
128 56808 k.triantaf
  constructor(public _elementRef: ElementRef) {
129
  }
130
131 50169 argiro.kok
  /**
132 56808 k.triantaf
   * Opens a alert window creating backdrop.
133
   */
134
  open() {
135 57665 k.triantaf
    UIkit.modal(this.element.nativeElement).show();
136 50169 argiro.kok
  }
137 56808 k.triantaf
138 50169 argiro.kok
  /**
139 56808 k.triantaf
   *  ok method closes the modal and emits modalOutput.
140
   */
141
  ok() {
142 57665 k.triantaf
    this.cancel();
143 56808 k.triantaf
    if (!this.choice) {
144
      this.alertOutput.emit(true);
145
    } else {
146
      this.alertOutput.emit({
147
        value: true,
148
        choice: this.select
149
      });
150
    }
151 50169 argiro.kok
  }
152 56808 k.triantaf
153 50169 argiro.kok
  /**
154 57336 k.triantaf
   *  cancel method closes the modal.
155 56808 k.triantaf
   */
156
  cancel() {
157 57665 k.triantaf
    UIkit.modal(this.element.nativeElement).hide();
158 50169 argiro.kok
  }
159
}