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