aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-edit/video-update.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/videos/+video-edit/video-update.component.ts')
-rw-r--r--client/src/app/videos/+video-edit/video-update.component.ts20
1 files changed, 16 insertions, 4 deletions
diff --git a/client/src/app/videos/+video-edit/video-update.component.ts b/client/src/app/videos/+video-edit/video-update.component.ts
index d22ee540a..9e849014e 100644
--- a/client/src/app/videos/+video-edit/video-update.component.ts
+++ b/client/src/app/videos/+video-edit/video-update.component.ts
@@ -1,5 +1,5 @@
1import { map, switchMap } from 'rxjs/operators' 1import { map, switchMap } from 'rxjs/operators'
2import { Component, OnInit } from '@angular/core' 2import { Component, HostListener, OnInit } from '@angular/core'
3import { ActivatedRoute, Router } from '@angular/router' 3import { ActivatedRoute, Router } from '@angular/router'
4import { LoadingBarService } from '@ngx-loading-bar/core' 4import { LoadingBarService } from '@ngx-loading-bar/core'
5import { Notifier } from '@app/core' 5import { Notifier } from '@app/core'
@@ -83,14 +83,26 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
83 ) 83 )
84 } 84 }
85 85
86 canDeactivate () { 86 @HostListener('window:beforeunload', [ '$event' ])
87 onUnload (event: any) {
88 const { text, canDeactivate } = this.canDeactivate()
89
90 if (canDeactivate) return
91
92 event.returnValue = text
93 return text
94 }
95
96 canDeactivate (): { canDeactivate: boolean, text?: string } {
87 if (this.updateDone === true) return { canDeactivate: true } 97 if (this.updateDone === true) return { canDeactivate: true }
88 98
99 const text = this.i18n('You have unsaved changes! If you leave, your changes will be lost.')
100
89 for (const caption of this.videoCaptions) { 101 for (const caption of this.videoCaptions) {
90 if (caption.action) return { canDeactivate: false } 102 if (caption.action) return { canDeactivate: false, text }
91 } 103 }
92 104
93 return { canDeactivate: this.formChanged === false } 105 return { canDeactivate: this.formChanged === false, text }
94 } 106 }
95 107
96 checkForm () { 108 checkForm () {