]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { Observable } from 'rxjs' |
529479f9 | 2 | import { Injectable } from '@angular/core' |
67ed6552 | 3 | import { ConfirmService } from '@app/core/confirm' |
529479f9 | 4 | |
c199c427 C |
5 | export type CanComponentDeactivateResult = { text?: string, canDeactivate: Observable<boolean> | boolean } |
6 | ||
529479f9 | 7 | export interface CanComponentDeactivate { |
c199c427 | 8 | canDeactivate: () => CanComponentDeactivateResult |
529479f9 DG |
9 | } |
10 | ||
11 | @Injectable() | |
52798aa5 | 12 | export class CanDeactivateGuard { |
66357162 C |
13 | |
14 | constructor (private confirmService: ConfirmService) { } | |
529479f9 | 15 | |
23db998f | 16 | canDeactivate (component: CanComponentDeactivate) { |
f6a043df | 17 | const result = component.canDeactivate() |
66357162 | 18 | const text = result.text || $localize`All unsaved data will be lost, are you sure you want to leave this page?` |
f6a043df C |
19 | |
20 | return result.canDeactivate || this.confirmService.confirm( | |
21 | text, | |
66357162 | 22 | $localize`Warning` |
529479f9 DG |
23 | ) |
24 | } | |
25 | ||
26 | } |