]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.ts
NoImplicitAny flag true (#1157)
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / shared / video-caption-add-modal.component.ts
index 45b8c71f816fc5b053c83216e10d3ba7e4df669c..a2c9237ad2b6533ac3c3f00d5eaf46508cc35556 100644 (file)
@@ -1,10 +1,10 @@
-import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
-import { ModalDirective } from 'ngx-bootstrap/modal'
+import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
 import { FormReactive } from '@app/shared'
 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
 import { VideoCaptionsValidatorsService } from '@app/shared/forms/form-validators/video-captions-validators.service'
 import { ServerService } from '@app/core'
 import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
+import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
 
 @Component({
   selector: 'my-video-caption-add-modal',
@@ -17,14 +17,16 @@ export class VideoCaptionAddModalComponent extends FormReactive implements OnIni
 
   @Output() captionAdded = new EventEmitter<VideoCaptionEdit>()
 
-  @ViewChild('modal') modal: ModalDirective
+  @ViewChild('modal') modal: ElementRef
 
-  videoCaptionLanguages = []
+  videoCaptionLanguages: any = []
 
+  private openedModal: NgbModalRef
   private closingModal = false
 
   constructor (
     protected formValidatorService: FormValidatorService,
+    private modalService: NgbModal,
     private serverService: ServerService,
     private videoCaptionsValidatorsService: VideoCaptionsValidatorsService
   ) {
@@ -49,11 +51,14 @@ export class VideoCaptionAddModalComponent extends FormReactive implements OnIni
   }
 
   show () {
-    this.modal.show()
+    this.closingModal = false
+
+    this.openedModal = this.modalService.open(this.modal, { keyboard: false })
   }
 
   hide () {
-    this.modal.hide()
+    this.closingModal = true
+    this.openedModal.close()
   }
 
   isReplacingExistingCaption () {
@@ -65,16 +70,16 @@ export class VideoCaptionAddModalComponent extends FormReactive implements OnIni
   }
 
   async addCaption () {
-    this.closingModal = true
+    this.hide()
 
     const languageId = this.form.value[ 'language' ]
-    const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId)
+    const languageObject = this.videoCaptionLanguages.find((l: any) => l.id === languageId)
 
     this.captionAdded.emit({
       language: languageObject,
-      captionfile: this.form.value['captionfile']
+      captionfile: this.form.value[ 'captionfile' ]
     })
 
-    this.hide()
+    this.form.reset()
   }
 }