| 
									
										
										
										
											2016-08-09 17:38:25 +01:00
										 |  |  | // #docregion
 | 
					
						
							|  |  |  | import { Injectable }           from '@angular/core'; | 
					
						
							|  |  |  | import { CanDeactivate, | 
					
						
							|  |  |  |          ActivatedRouteSnapshot, | 
					
						
							|  |  |  |          RouterStateSnapshot }  from '@angular/router'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { CrisisDetailComponent } from './crisis-center/crisis-detail.component'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Injectable() | 
					
						
							|  |  |  | export class CanDeactivateGuard implements CanDeactivate<CrisisDetailComponent> { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   canDeactivate( | 
					
						
							|  |  |  |     component: CrisisDetailComponent, | 
					
						
							|  |  |  |     route: ActivatedRouteSnapshot, | 
					
						
							|  |  |  |     state: RouterStateSnapshot | 
					
						
							| 
									
										
										
										
											2016-08-26 23:19:27 -05:00
										 |  |  |   ): Promise<boolean> | boolean { | 
					
						
							| 
									
										
										
										
											2016-08-09 17:38:25 +01:00
										 |  |  |     // Get the Crisis Center ID
 | 
					
						
							|  |  |  |     console.log(route.params['id']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Get the current URL
 | 
					
						
							|  |  |  |     console.log(state.url); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Allow synchronous navigation (`true`) if no crisis or the crisis is unchanged
 | 
					
						
							|  |  |  |     if (!component.crisis || component.crisis.name === component.editName) { | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     // Otherwise ask the user with the dialog service and return its
 | 
					
						
							|  |  |  |     // promise which resolves to true or false when the user decides
 | 
					
						
							|  |  |  |     return component.dialogService.confirm('Discard changes?'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |