diff options
Diffstat (limited to 'client/src/app/core/confirm/confirm.component.ts')
-rw-r--r-- | client/src/app/core/confirm/confirm.component.ts | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/client/src/app/core/confirm/confirm.component.ts b/client/src/app/core/confirm/confirm.component.ts index a13152496..0d18c38e8 100644 --- a/client/src/app/core/confirm/confirm.component.ts +++ b/client/src/app/core/confirm/confirm.component.ts | |||
@@ -1,9 +1,8 @@ | |||
1 | import { Component, HostListener, OnInit, ViewChild } from '@angular/core' | 1 | import { Component, ElementRef, HostListener, OnInit, ViewChild } from '@angular/core' |
2 | |||
3 | import { ModalDirective } from 'ngx-bootstrap/modal' | ||
4 | |||
5 | import { ConfirmService } from './confirm.service' | 2 | import { ConfirmService } from './confirm.service' |
6 | import { I18n } from '@ngx-translate/i18n-polyfill' | 3 | import { I18n } from '@ngx-translate/i18n-polyfill' |
4 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
5 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | ||
7 | 6 | ||
8 | @Component({ | 7 | @Component({ |
9 | selector: 'my-confirm', | 8 | selector: 'my-confirm', |
@@ -11,7 +10,7 @@ import { I18n } from '@ngx-translate/i18n-polyfill' | |||
11 | styleUrls: [ './confirm.component.scss' ] | 10 | styleUrls: [ './confirm.component.scss' ] |
12 | }) | 11 | }) |
13 | export class ConfirmComponent implements OnInit { | 12 | export class ConfirmComponent implements OnInit { |
14 | @ViewChild('confirmModal') confirmModal: ModalDirective | 13 | @ViewChild('confirmModal') confirmModal: ElementRef |
15 | 14 | ||
16 | title = '' | 15 | title = '' |
17 | message = '' | 16 | message = '' |
@@ -21,7 +20,10 @@ export class ConfirmComponent implements OnInit { | |||
21 | inputValue = '' | 20 | inputValue = '' |
22 | confirmButtonText = '' | 21 | confirmButtonText = '' |
23 | 22 | ||
23 | private openedModal: NgbModalRef | ||
24 | |||
24 | constructor ( | 25 | constructor ( |
26 | private modalService: NgbModal, | ||
25 | private confirmService: ConfirmService, | 27 | private confirmService: ConfirmService, |
26 | private i18n: I18n | 28 | private i18n: I18n |
27 | ) { | 29 | ) { |
@@ -29,11 +31,6 @@ export class ConfirmComponent implements OnInit { | |||
29 | } | 31 | } |
30 | 32 | ||
31 | ngOnInit () { | 33 | ngOnInit () { |
32 | this.confirmModal.config = { | ||
33 | backdrop: 'static', | ||
34 | keyboard: false | ||
35 | } | ||
36 | |||
37 | this.confirmService.showConfirm.subscribe( | 34 | this.confirmService.showConfirm.subscribe( |
38 | ({ title, message, expectedInputValue, inputLabel, confirmButtonText }) => { | 35 | ({ title, message, expectedInputValue, inputLabel, confirmButtonText }) => { |
39 | this.title = title | 36 | this.title = title |
@@ -49,16 +46,9 @@ export class ConfirmComponent implements OnInit { | |||
49 | ) | 46 | ) |
50 | } | 47 | } |
51 | 48 | ||
52 | @HostListener('keydown.enter') | 49 | @HostListener('document:keydown.enter') |
53 | confirm () { | 50 | confirm () { |
54 | this.confirmService.confirmResponse.next(true) | 51 | if (this.openedModal) this.openedModal.close() |
55 | this.hideModal() | ||
56 | } | ||
57 | |||
58 | @HostListener('keydown.esc') | ||
59 | cancel () { | ||
60 | this.confirmService.confirmResponse.next(false) | ||
61 | this.hideModal() | ||
62 | } | 52 | } |
63 | 53 | ||
64 | isConfirmationDisabled () { | 54 | isConfirmationDisabled () { |
@@ -70,10 +60,11 @@ export class ConfirmComponent implements OnInit { | |||
70 | 60 | ||
71 | showModal () { | 61 | showModal () { |
72 | this.inputValue = '' | 62 | this.inputValue = '' |
73 | this.confirmModal.show() | ||
74 | } | ||
75 | 63 | ||
76 | hideModal () { | 64 | this.openedModal = this.modalService.open(this.confirmModal) |
77 | this.confirmModal.hide() | 65 | |
66 | this.openedModal.result | ||
67 | .then(() => this.confirmService.confirmResponse.next(true)) | ||
68 | .catch(() => this.confirmService.confirmResponse.next(false)) | ||
78 | } | 69 | } |
79 | } | 70 | } |