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