1 import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2 import { FormReactive } from '@app/shared'
3 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
4 import { VideoCaptionsValidatorsService } from '@app/shared/forms/form-validators/video-captions-validators.service'
5 import { ServerService } from '@app/core'
6 import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
7 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
8 import { VideoConstant } from '../../../../../../shared'
11 selector: 'my-video-caption-add-modal',
12 styleUrls: [ './video-caption-add-modal.component.scss' ],
13 templateUrl: './video-caption-add-modal.component.html'
16 export class VideoCaptionAddModalComponent extends FormReactive implements OnInit {
17 @Input() existingCaptions: string[]
19 @Output() captionAdded = new EventEmitter<VideoCaptionEdit>()
21 @ViewChild('modal') modal: ElementRef
23 videoCaptionLanguages: VideoConstant<string>[] = []
25 private openedModal: NgbModalRef
26 private closingModal = false
29 protected formValidatorService: FormValidatorService,
30 private modalService: NgbModal,
31 private serverService: ServerService,
32 private videoCaptionsValidatorsService: VideoCaptionsValidatorsService
37 get videoCaptionExtensions () {
38 return this.serverService.getConfig().videoCaption.file.extensions
41 get videoCaptionMaxSize () {
42 return this.serverService.getConfig().videoCaption.file.size.max
46 this.videoCaptionLanguages = this.serverService.getVideoLanguages()
49 language: this.videoCaptionsValidatorsService.VIDEO_CAPTION_LANGUAGE,
50 captionfile: this.videoCaptionsValidatorsService.VIDEO_CAPTION_FILE
55 this.closingModal = false
57 this.openedModal = this.modalService.open(this.modal, { keyboard: false })
61 this.closingModal = true
62 this.openedModal.close()
66 isReplacingExistingCaption () {
67 if (this.closingModal === true) return false
69 const languageId = this.form.value[ 'language' ]
71 return languageId && this.existingCaptions.indexOf(languageId) !== -1
77 const languageId = this.form.value[ 'language' ]
78 const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId)
80 this.captionAdded.emit({
81 language: languageObject,
82 captionfile: this.form.value[ 'captionfile' ]