]>
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' |
ba430d75 | 8 | import { ServerConfig, 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[] | |
ba430d75 | 18 | @Input() serverConfig: ServerConfig |
40e87e9e C |
19 | |
20 | @Output() captionAdded = new EventEmitter<VideoCaptionEdit>() | |
21 | ||
f36da21e | 22 | @ViewChild('modal', { static: true }) modal: ElementRef |
40e87e9e | 23 | |
c199c427 | 24 | videoCaptionLanguages: VideoConstant<string>[] = [] |
40e87e9e | 25 | |
63347a0f | 26 | private openedModal: NgbModalRef |
40e87e9e C |
27 | private closingModal = false |
28 | ||
29 | constructor ( | |
30 | protected formValidatorService: FormValidatorService, | |
63347a0f | 31 | private modalService: NgbModal, |
40e87e9e C |
32 | private serverService: ServerService, |
33 | private videoCaptionsValidatorsService: VideoCaptionsValidatorsService | |
34 | ) { | |
35 | super() | |
36 | } | |
37 | ||
38 | get videoCaptionExtensions () { | |
ba430d75 | 39 | return this.serverConfig.videoCaption.file.extensions |
40e87e9e C |
40 | } |
41 | ||
42 | get videoCaptionMaxSize () { | |
ba430d75 | 43 | return this.serverConfig.videoCaption.file.size.max |
40e87e9e C |
44 | } |
45 | ||
46 | ngOnInit () { | |
ba430d75 C |
47 | this.serverService.getVideoLanguages() |
48 | .subscribe(languages => this.videoCaptionLanguages = languages) | |
40e87e9e C |
49 | |
50 | this.buildForm({ | |
51 | language: this.videoCaptionsValidatorsService.VIDEO_CAPTION_LANGUAGE, | |
52 | captionfile: this.videoCaptionsValidatorsService.VIDEO_CAPTION_FILE | |
53 | }) | |
54 | } | |
55 | ||
56 | show () { | |
f4001cf4 C |
57 | this.closingModal = false |
58 | ||
24e7916c | 59 | this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false }) |
40e87e9e C |
60 | } |
61 | ||
62 | hide () { | |
f4001cf4 | 63 | this.closingModal = true |
63347a0f | 64 | this.openedModal.close() |
d8c9996c | 65 | this.form.reset() |
40e87e9e C |
66 | } |
67 | ||
68 | isReplacingExistingCaption () { | |
69 | if (this.closingModal === true) return false | |
70 | ||
71 | const languageId = this.form.value[ 'language' ] | |
72 | ||
73 | return languageId && this.existingCaptions.indexOf(languageId) !== -1 | |
74 | } | |
75 | ||
76 | async addCaption () { | |
40e87e9e | 77 | const languageId = this.form.value[ 'language' ] |
c199c427 | 78 | const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId) |
40e87e9e C |
79 | |
80 | this.captionAdded.emit({ | |
81 | language: languageObject, | |
337ba64e | 82 | captionfile: this.form.value[ 'captionfile' ] |
40e87e9e C |
83 | }) |
84 | ||
259dd796 | 85 | this.hide() |
40e87e9e C |
86 | } |
87 | } |