]>
Commit | Line | Data |
---|---|---|
5769e1db C |
1 | import { Component, HostListener, OnInit, ViewChild } from '@angular/core'; |
2 | ||
ad42bea3 | 3 | import { ModalDirective } from 'ngx-bootstrap/modal'; |
5769e1db C |
4 | |
5 | import { ConfirmService } from './confirm.service'; | |
6 | ||
7 | export interface ConfigChangedEvent { | |
8 | columns: { [id: string]: { isDisplayed: boolean }; }; | |
9 | config: { resultsPerPage: number }; | |
10 | } | |
11 | ||
12 | @Component({ | |
13 | selector: 'my-confirm', | |
14 | templateUrl: './confirm.component.html' | |
15 | }) | |
16 | export class ConfirmComponent implements OnInit { | |
17 | @ViewChild('confirmModal') confirmModal: ModalDirective; | |
18 | ||
19 | title = ''; | |
20 | message = ''; | |
21 | ||
22 | constructor (private confirmService: ConfirmService) { | |
23 | // Empty | |
24 | } | |
25 | ||
26 | ngOnInit() { | |
27 | this.confirmModal.config = { | |
28 | backdrop: 'static', | |
29 | keyboard: false | |
30 | }; | |
31 | ||
32 | this.confirmService.showConfirm.subscribe( | |
33 | ({ title, message }) => { | |
34 | this.title = title; | |
35 | this.message = message; | |
36 | ||
37 | this.showModal(); | |
38 | } | |
39 | ); | |
40 | } | |
41 | ||
42 | @HostListener('keydown.enter') | |
43 | confirm() { | |
44 | this.confirmService.confirmResponse.next(true); | |
45 | this.hideModal(); | |
46 | } | |
47 | ||
48 | @HostListener('keydown.esc') | |
49 | abort() { | |
50 | this.confirmService.confirmResponse.next(false); | |
51 | this.hideModal(); | |
52 | } | |
53 | ||
54 | showModal() { | |
55 | this.confirmModal.show(); | |
56 | } | |
57 | ||
58 | hideModal() { | |
59 | this.confirmModal.hide(); | |
60 | } | |
61 | } |