mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-02 05:23:14 +00:00
0.2.5 initial commit
Makefile incomplete
This commit is contained in:
26
ui/src/app/guards/deactivate.guard.ts
Normal file
26
ui/src/app/guards/deactivate.guard.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Injectable, Directive } from '@angular/core'
|
||||
import { CanDeactivate } from '@angular/router'
|
||||
import { HostListener } from '@angular/core'
|
||||
|
||||
@Directive()
|
||||
export abstract class PageCanDeactivate {
|
||||
abstract canDeactivate (): boolean
|
||||
|
||||
@HostListener('window:beforeunload', ['$event'])
|
||||
unloadNotification (e: any) {
|
||||
console.log(e)
|
||||
if (!this.canDeactivate()) {
|
||||
e.returnValue = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CanDeactivateGuard implements CanDeactivate<PageCanDeactivate> {
|
||||
|
||||
canDeactivate (page: PageCanDeactivate): boolean {
|
||||
return page.canDeactivate() || confirm('You have unsaved changes. Are you sure you want to leave the page?')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user