aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/confirm/confirm.service.ts
blob: d99226f053496f6bf6058b278d1ff5723705c689 (plain) (blame)
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
import { Injectable } from '@angular/core'
import { Subject } from 'rxjs/Subject'
import 'rxjs/add/operator/first'
import 'rxjs/add/operator/toPromise'

type ConfirmOptions = {
  title: string
  message: string
  inputLabel?: string
  expectedInputValue?: string
  confirmButtonText?: string
}

@Injectable()
export class ConfirmService {
  showConfirm = new Subject<ConfirmOptions>()
  confirmResponse = new Subject<boolean>()

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

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

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

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