aboutsummaryrefslogtreecommitdiffstats
path: root/webapp/src/app/pages/confirm/confirm-modal/confirm-modal.component.ts
blob: 3de903525724dbe07439a97616ce314861cb986c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* @license
* Copyright (C) 2017-2018 "IoT.bzh"
* Author Sebastien Douheret <sebastien@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Component, OnInit, Input } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';

export enum EType {
  YesNo = 1,
  OKCancel,
  OK,
  Cancel,
}

@Component({
  selector: 'xds-confirm-modal',
  template: `
  <div tabindex="-1">
    <div class="modal-header">
      {{ title }}
    </div>

    <div class="modal-body row">
      <div class="col-12 text-center">
        <div [innerHtml]="question"></div>
      </div>
      <div class="col-12 text-center" style="margin-top: 2em;">
        <button *ngIf="textBtn[0] != ''"
                type="button"
                class="btn btn-md btn-primary"
                tabindex="2"
                (click)="onClick(textBtn[0])"> {{textBtn[0]}}
        </button>

        <button *ngIf="textBtn[1] != ''"
                type="button"
                class="btn btn-md btn-secondary"
                tabindex="1"
                (click)="onClick(textBtn[1])"> {{textBtn[1]}}
        </button>
      </div>
    </div>

    <div *ngIf="footer!=''" class="modal-footer">
      <div class="col-12 text-center">
        <div [innerHtml]="footer"></div>
      </div>
    </div>
  </div>
  `,
})

export class ConfirmModalComponent implements OnInit {
  @Input() title;
  @Input() footer = '';
  @Input() type;
  @Input() question;

  bodyQuestion = '';
  textBtn: Array<string> = ['', ''];

  constructor(
    private modalRef: NgbActiveModal,
  ) { }


  ngOnInit() {
    switch (this.type) {
      case EType.OK:
        this.textBtn = [ 'OK', '' ];
        break;

      case EType.Cancel:
        this.textBtn = [ '', 'Cancel' ];
      break;

      case EType.OKCancel:
        this.textBtn = [ 'OK', 'Cancel' ];
      break;

      default:
      case EType.YesNo:
        this.textBtn = [ 'Yes', 'No' ];
        break;
    }
  }

  onClick(txt: string): void {
    this.modalRef.close(txt.toLowerCase());
  }
}