]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+videos/+video-edit/shared/video-caption-add-modal.component.ts
Fix lint
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / shared / video-caption-add-modal.component.ts
index a90d04ce82fe39ee92165cb4283c838b554aac73..4ab2d42db2294c07309472efd84214bdecd5d35f 100644 (file)
@@ -1,9 +1,10 @@
 import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
 import { ServerService } from '@app/core'
-import { FormReactive, FormValidatorService, VideoCaptionsValidatorsService } from '@app/shared/shared-forms'
+import { VIDEO_CAPTION_FILE_VALIDATOR, VIDEO_CAPTION_LANGUAGE_VALIDATOR } from '@app/shared/form-validators/video-captions-validators'
+import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
 import { VideoCaptionEdit } from '@app/shared/shared-main'
 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
-import { ServerConfig, VideoConstant } from '@shared/models'
+import { HTMLServerConfig, VideoConstant } from '@shared/models'
 
 @Component({
   selector: 'my-video-caption-add-modal',
@@ -13,7 +14,7 @@ import { ServerConfig, VideoConstant } from '@shared/models'
 
 export class VideoCaptionAddModalComponent extends FormReactive implements OnInit {
   @Input() existingCaptions: string[]
-  @Input() serverConfig: ServerConfig
+  @Input() serverConfig: HTMLServerConfig
 
   @Output() captionAdded = new EventEmitter<VideoCaptionEdit>()
 
@@ -25,10 +26,9 @@ export class VideoCaptionAddModalComponent extends FormReactive implements OnIni
   private closingModal = false
 
   constructor (
-    protected formValidatorService: FormValidatorService,
+    protected formReactiveService: FormReactiveService,
     private modalService: NgbModal,
-    private serverService: ServerService,
-    private videoCaptionsValidatorsService: VideoCaptionsValidatorsService
+    private serverService: ServerService
   ) {
     super()
   }
@@ -41,13 +41,17 @@ export class VideoCaptionAddModalComponent extends FormReactive implements OnIni
     return this.serverConfig.videoCaption.file.size.max
   }
 
+  getReactiveFileButtonTooltip () {
+    return `(extensions: ${this.videoCaptionExtensions.join(', ')})`
+  }
+
   ngOnInit () {
     this.serverService.getVideoLanguages()
         .subscribe(languages => this.videoCaptionLanguages = languages)
 
     this.buildForm({
-      language: this.videoCaptionsValidatorsService.VIDEO_CAPTION_LANGUAGE,
-      captionfile: this.videoCaptionsValidatorsService.VIDEO_CAPTION_FILE
+      language: VIDEO_CAPTION_LANGUAGE_VALIDATOR,
+      captionfile: VIDEO_CAPTION_FILE_VALIDATOR
     })
   }
 
@@ -66,18 +70,19 @@ export class VideoCaptionAddModalComponent extends FormReactive implements OnIni
   isReplacingExistingCaption () {
     if (this.closingModal === true) return false
 
-    const languageId = this.form.value[ 'language' ]
+    const languageId = this.form.value['language']
 
-    return languageId && this.existingCaptions.indexOf(languageId) !== -1
+    return languageId && this.existingCaptions.includes(languageId)
   }
 
-  async addCaption () {
-    const languageId = this.form.value[ 'language' ]
+  addCaption () {
+    const languageId = this.form.value['language']
     const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId)
 
     this.captionAdded.emit({
       language: languageObject,
-      captionfile: this.form.value[ 'captionfile' ]
+      captionfile: this.form.value['captionfile'],
+      action: 'CREATE'
     })
 
     this.hide()