]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-edit/video-update.component.ts
Update translations
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / video-update.component.ts
index 774772e148085c6fe5521e6145eef041ff1b067b..75b11f46c7bd02c9430eb9538a66ded6eada4cb3 100644 (file)
@@ -24,11 +24,13 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
   video: VideoEdit
 
   isUpdatingVideo = false
-  videoPrivacies: VideoConstant<string>[] = []
+  videoPrivacies: VideoConstant<VideoPrivacy>[] = []
   userVideoChannels: { id: number, label: string, support: string }[] = []
   schedulePublicationPossible = false
   videoCaptions: VideoCaptionEdit[] = []
 
+  private updateDone = false
+
   constructor (
     protected formValidatorService: FormValidatorService,
     private route: ActivatedRoute,
@@ -60,12 +62,14 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
 
           // We cannot set private a video that was not private
           if (this.video.privacy !== VideoPrivacy.PRIVATE) {
-            this.videoPrivacies = this.videoPrivacies.filter(p => p.id.toString() !== VideoPrivacy.PRIVATE.toString())
+            this.videoPrivacies = this.videoPrivacies.filter(p => p.id !== VideoPrivacy.PRIVATE)
           } else { // We can schedule video publication only if it it is private
             this.schedulePublicationPossible = this.video.privacy === VideoPrivacy.PRIVATE
           }
 
-          // FIXME: Angular does not detec
+          this.videoPrivacies = this.videoService.explainedPrivacyLabels(this.videoPrivacies)
+
+          // FIXME: Angular does not detect the change inside this subscription, so use the patched setTimeout
           setTimeout(() => this.hydrateFormFromVideo())
         },
 
@@ -76,6 +80,16 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
       )
   }
 
+  canDeactivate () {
+    if (this.updateDone === true) return { canDeactivate: true }
+
+    for (const caption of this.videoCaptions) {
+      if (caption.action) return { canDeactivate: false }
+    }
+
+    return { canDeactivate: this.formChanged === false }
+  }
+
   checkForm () {
     this.forceCheck()
 
@@ -100,6 +114,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
         )
         .subscribe(
           () => {
+            this.updateDone = true
             this.isUpdatingVideo = false
             this.loadingBar.complete()
             this.notificationsService.success(this.i18n('Success'), this.i18n('Video updated.'))
@@ -107,12 +122,12 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
           },
 
           err => {
+            this.loadingBar.complete()
             this.isUpdatingVideo = false
             this.notificationsService.error(this.i18n('Error'), err.message)
             console.error(err)
           }
         )
-
   }
 
   private hydrateFormFromVideo () {