]>
Commit | Line | Data |
---|---|---|
63347a0f | 1 | import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' |
40e87e9e C |
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' | |
63347a0f | 7 | import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap' |
c199c427 | 8 | import { VideoConstant } from '../../../../../../shared' |
40e87e9e C |
9 | |
10 | @Component({ | |
11 | selector: 'my-video-caption-add-modal', | |
12 | styleUrls: [ './video-caption-add-modal.component.scss' ], | |
13 | templateUrl: './video-caption-add-modal.component.html' | |
14 | }) | |
15 | ||
16 | export class VideoCaptionAddModalComponent extends FormReactive implements OnInit { | |
17 | @Input() existingCaptions: string[] | |
18 | ||
19 | @Output() captionAdded = new EventEmitter<VideoCaptionEdit>() | |
20 | ||
63347a0f | 21 | @ViewChild('modal') modal: ElementRef |
40e87e9e | 22 | |
c199c427 | 23 | videoCaptionLanguages: VideoConstant<string>[] = [] |
40e87e9e | 24 | |
63347a0f | 25 | private openedModal: NgbModalRef |
40e87e9e C |
26 | private closingModal = false |
27 | ||
28 | constructor ( | |
29 | protected formValidatorService: FormValidatorService, | |
63347a0f | 30 | private modalService: NgbModal, |
40e87e9e C |
31 | private serverService: ServerService, |
32 | private videoCaptionsValidatorsService: VideoCaptionsValidatorsService | |
33 | ) { | |
34 | super() | |
35 | } | |
36 | ||
37 | get videoCaptionExtensions () { | |
38 | return this.serverService.getConfig().videoCaption.file.extensions | |
39 | } | |
40 | ||
41 | get videoCaptionMaxSize () { | |
42 | return this.serverService.getConfig().videoCaption.file.size.max | |
43 | } | |
44 | ||
45 | ngOnInit () { | |
46 | this.videoCaptionLanguages = this.serverService.getVideoLanguages() | |
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 | ||
63347a0f | 57 | this.openedModal = this.modalService.open(this.modal, { 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 | } |