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'
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: ElementRef
22 videoCaptionLanguages = []
24 private openedModal: NgbModalRef
25 private closingModal = false
28 protected formValidatorService: FormValidatorService,
29 private modalService: NgbModal,
30 private serverService: ServerService,
31 private videoCaptionsValidatorsService: VideoCaptionsValidatorsService
36 get videoCaptionExtensions () {
37 return this.serverService.getConfig().videoCaption.file.extensions
40 get videoCaptionMaxSize () {
41 return this.serverService.getConfig().videoCaption.file.size.max
45 this.videoCaptionLanguages = this.serverService.getVideoLanguages()
48 language: this.videoCaptionsValidatorsService.VIDEO_CAPTION_LANGUAGE,
49 captionfile: this.videoCaptionsValidatorsService.VIDEO_CAPTION_FILE
54 this.closingModal = false
56 this.openedModal = this.modalService.open(this.modal, { keyboard: false })
60 this.closingModal = true
61 this.openedModal.close()
64 isReplacingExistingCaption () {
65 if (this.closingModal === true) return false
67 const languageId = this.form.value[ 'language' ]
69 return languageId && this.existingCaptions.indexOf(languageId) !== -1
75 const languageId = this.form.value[ 'language' ]
76 const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId)
78 this.captionAdded.emit({
79 language: languageObject,
80 captionfile: this.form.value[ 'captionfile' ]