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