1 import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2 import { ModalDirective } from 'ngx-bootstrap/modal'
3 import { FormReactive } from '@app/shared'
4 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
5 import { VideoCaptionsValidatorsService } from '@app/shared/forms/form-validators/video-captions-validators.service'
6 import { ServerService } from '@app/core'
7 import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
10 selector: 'my-video-caption-add-modal',
11 styleUrls: [ './video-caption-add-modal.component.scss' ],
12 templateUrl: './video-caption-add-modal.component.html'
15 export class VideoCaptionAddModalComponent extends FormReactive implements OnInit {
16 @Input() existingCaptions: string[]
18 @Output() captionAdded = new EventEmitter<VideoCaptionEdit>()
20 @ViewChild('modal') modal: ModalDirective
22 videoCaptionLanguages = []
24 private closingModal = false
27 protected formValidatorService: FormValidatorService,
28 private serverService: ServerService,
29 private videoCaptionsValidatorsService: VideoCaptionsValidatorsService
34 get videoCaptionExtensions () {
35 return this.serverService.getConfig().videoCaption.file.extensions
38 get videoCaptionMaxSize () {
39 return this.serverService.getConfig().videoCaption.file.size.max
43 this.videoCaptionLanguages = this.serverService.getVideoLanguages()
46 language: this.videoCaptionsValidatorsService.VIDEO_CAPTION_LANGUAGE,
47 captionfile: this.videoCaptionsValidatorsService.VIDEO_CAPTION_FILE
59 isReplacingExistingCaption () {
60 if (this.closingModal === true) return false
62 const languageId = this.form.value[ 'language' ]
64 return languageId && this.existingCaptions.indexOf(languageId) !== -1
68 this.closingModal = true
70 const languageId = this.form.value[ 'language' ]
71 const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId)
73 this.captionAdded.emit({
74 language: languageObject,
75 captionfile: this.form.value['captionfile']