diff options
author | Chocobozzz <me@florianbigard.com> | 2019-01-14 14:55:43 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-01-14 15:01:08 +0100 |
commit | 674a66bbda7ceb7aed3c2e6aefddc2793207d94b (patch) | |
tree | 9ed3ce63e70f7b2842f2f3f8b98da0e81a7f052f /client/src/app/videos/+video-edit/video-update.component.ts | |
parent | 699b059e2d6cdd09685a69261f2ca5cf63053a71 (diff) | |
download | PeerTube-674a66bbda7ceb7aed3c2e6aefddc2793207d94b.tar.gz PeerTube-674a66bbda7ceb7aed3c2e6aefddc2793207d94b.tar.zst PeerTube-674a66bbda7ceb7aed3c2e6aefddc2793207d94b.zip |
Add unload listener on video upload/update
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.ts | 20 |
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 @@ | |||
1 | import { map, switchMap } from 'rxjs/operators' | 1 | import { map, switchMap } from 'rxjs/operators' |
2 | import { Component, OnInit } from '@angular/core' | 2 | import { Component, HostListener, OnInit } from '@angular/core' |
3 | import { ActivatedRoute, Router } from '@angular/router' | 3 | import { ActivatedRoute, Router } from '@angular/router' |
4 | import { LoadingBarService } from '@ngx-loading-bar/core' | 4 | import { LoadingBarService } from '@ngx-loading-bar/core' |
5 | import { Notifier } from '@app/core' | 5 | import { 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 () { |