diff options
Diffstat (limited to 'client/src/app/shared/guards')
-rw-r--r-- | client/src/app/shared/guards/can-deactivate-guard.service.ts | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/client/src/app/shared/guards/can-deactivate-guard.service.ts b/client/src/app/shared/guards/can-deactivate-guard.service.ts index 550dd656e..c038a5c0e 100644 --- a/client/src/app/shared/guards/can-deactivate-guard.service.ts +++ b/client/src/app/shared/guards/can-deactivate-guard.service.ts | |||
@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core' | |||
2 | import { ActivatedRouteSnapshot, CanDeactivate, RouterStateSnapshot } from '@angular/router' | 2 | import { ActivatedRouteSnapshot, CanDeactivate, RouterStateSnapshot } from '@angular/router' |
3 | import { Observable } from 'rxjs' | 3 | import { Observable } from 'rxjs' |
4 | import { ConfirmService } from '../../core/index' | 4 | import { ConfirmService } from '../../core/index' |
5 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
5 | 6 | ||
6 | export interface CanComponentDeactivate { | 7 | export interface CanComponentDeactivate { |
7 | canDeactivate: () => { text?: string, canDeactivate: Observable<boolean> | boolean } | 8 | canDeactivate: () => { text?: string, canDeactivate: Observable<boolean> | boolean } |
@@ -9,7 +10,10 @@ export interface CanComponentDeactivate { | |||
9 | 10 | ||
10 | @Injectable() | 11 | @Injectable() |
11 | export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> { | 12 | export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> { |
12 | constructor (private confirmService: ConfirmService) { } | 13 | constructor ( |
14 | private confirmService: ConfirmService, | ||
15 | private i18n: I18n | ||
16 | ) { } | ||
13 | 17 | ||
14 | canDeactivate (component: CanComponentDeactivate, | 18 | canDeactivate (component: CanComponentDeactivate, |
15 | currentRoute: ActivatedRouteSnapshot, | 19 | currentRoute: ActivatedRouteSnapshot, |
@@ -17,11 +21,11 @@ export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> | |||
17 | nextState: RouterStateSnapshot | 21 | nextState: RouterStateSnapshot |
18 | ) { | 22 | ) { |
19 | const result = component.canDeactivate() | 23 | const result = component.canDeactivate() |
20 | const text = result.text || 'All unsaved data will be lost, are you sure you want to leave this page?' | 24 | const text = result.text || this.i18n('All unsaved data will be lost, are you sure you want to leave this page?') |
21 | 25 | ||
22 | return result.canDeactivate || this.confirmService.confirm( | 26 | return result.canDeactivate || this.confirmService.confirm( |
23 | text, | 27 | text, |
24 | 'Warning' | 28 | this.i18n('Warning') |
25 | ) | 29 | ) |
26 | } | 30 | } |
27 | 31 | ||