]>
Commit | Line | Data |
---|---|---|
df98563e C |
1 | import { Injectable } from '@angular/core' |
2 | import { Subject } from 'rxjs/Subject' | |
3 | import 'rxjs/add/operator/first' | |
1f30a185 | 4 | import 'rxjs/add/operator/toPromise' |
5769e1db | 5 | |
22b59e80 C |
6 | type ConfirmOptions = { |
7 | title: string | |
8 | message: string | |
9 | inputLabel?: string | |
10 | expectedInputValue?: string | |
11 | confirmButtonText?: string | |
12 | } | |
13 | ||
5769e1db C |
14 | @Injectable() |
15 | export class ConfirmService { | |
22b59e80 | 16 | showConfirm = new Subject<ConfirmOptions>() |
df98563e | 17 | confirmResponse = new Subject<boolean>() |
5769e1db | 18 | |
22b59e80 C |
19 | confirm (message: string, title = '', confirmButtonText?: string) { |
20 | this.showConfirm.next({ title, message, confirmButtonText }) | |
5769e1db | 21 | |
1f30a185 C |
22 | return this.confirmResponse.asObservable().first().toPromise() |
23 | } | |
24 | ||
22b59e80 C |
25 | confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) { |
26 | this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText }) | |
1f30a185 C |
27 | |
28 | return this.confirmResponse.asObservable().first().toPromise() | |
5769e1db C |
29 | } |
30 | } |