]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-edit/shared/video-caption-add-modal.component.ts
Use ng select for multiselect
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / shared / video-caption-add-modal.component.ts
CommitLineData
63347a0f 1import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
40e87e9e 2import { ServerService } from '@app/core'
67ed6552
C
3import { FormReactive, FormValidatorService, VideoCaptionsValidatorsService } from '@app/shared/shared-forms'
4import { VideoCaptionEdit } from '@app/shared/shared-main'
63347a0f 5import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
67ed6552 6import { ServerConfig, VideoConstant } from '@shared/models'
40e87e9e
C
7
8@Component({
9 selector: 'my-video-caption-add-modal',
10 styleUrls: [ './video-caption-add-modal.component.scss' ],
11 templateUrl: './video-caption-add-modal.component.html'
12})
13
14export class VideoCaptionAddModalComponent extends FormReactive implements OnInit {
15 @Input() existingCaptions: string[]
ba430d75 16 @Input() serverConfig: ServerConfig
40e87e9e
C
17
18 @Output() captionAdded = new EventEmitter<VideoCaptionEdit>()
19
f36da21e 20 @ViewChild('modal', { static: true }) modal: ElementRef
40e87e9e 21
c199c427 22 videoCaptionLanguages: VideoConstant<string>[] = []
40e87e9e 23
63347a0f 24 private openedModal: NgbModalRef
40e87e9e
C
25 private closingModal = false
26
27 constructor (
28 protected formValidatorService: FormValidatorService,
63347a0f 29 private modalService: NgbModal,
40e87e9e
C
30 private serverService: ServerService,
31 private videoCaptionsValidatorsService: VideoCaptionsValidatorsService
32 ) {
33 super()
34 }
35
36 get videoCaptionExtensions () {
ba430d75 37 return this.serverConfig.videoCaption.file.extensions
40e87e9e
C
38 }
39
40 get videoCaptionMaxSize () {
ba430d75 41 return this.serverConfig.videoCaption.file.size.max
40e87e9e
C
42 }
43
44 ngOnInit () {
ba430d75
C
45 this.serverService.getVideoLanguages()
46 .subscribe(languages => this.videoCaptionLanguages = languages)
40e87e9e
C
47
48 this.buildForm({
49 language: this.videoCaptionsValidatorsService.VIDEO_CAPTION_LANGUAGE,
50 captionfile: this.videoCaptionsValidatorsService.VIDEO_CAPTION_FILE
51 })
52 }
53
54 show () {
f4001cf4
C
55 this.closingModal = false
56
24e7916c 57 this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
40e87e9e
C
58 }
59
60 hide () {
f4001cf4 61 this.closingModal = true
63347a0f 62 this.openedModal.close()
d8c9996c 63 this.form.reset()
40e87e9e
C
64 }
65
66 isReplacingExistingCaption () {
67 if (this.closingModal === true) return false
68
69 const languageId = this.form.value[ 'language' ]
70
71 return languageId && this.existingCaptions.indexOf(languageId) !== -1
72 }
73
74 async addCaption () {
40e87e9e 75 const languageId = this.form.value[ 'language' ]
c199c427 76 const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId)
40e87e9e
C
77
78 this.captionAdded.emit({
79 language: languageObject,
337ba64e 80 captionfile: this.form.value[ 'captionfile' ]
40e87e9e
C
81 })
82
259dd796 83 this.hide()
40e87e9e
C
84 }
85}