aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/confirm/confirm.service.ts
blob: f30feb9d0b2e9c3dc991e226e1fd32c1acaa878b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { Injectable } from '@angular/core'
import { Subject } from 'rxjs/Subject'
import 'rxjs/add/operator/first'
import 'rxjs/add/operator/toPromise'

@Injectable()
export class ConfirmService {
  showConfirm = new Subject<{ title: string, message: string, inputLabel?: string, expectedInputValue?: string }>()
  confirmResponse = new Subject<boolean>()

  confirm (message: string, title = '') {
    this.showConfirm.next({ title, message })

    return this.confirmResponse.asObservable().first().toPromise()
  }

  confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '') {
    this.showConfirm.next({ title, message, inputLabel, expectedInputValue })

    return this.confirmResponse.asObservable().first().toPromise()
  }
}