]>
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' |
40e87e9e C |
8 | |
9 | @Component({ | |
10 | selector: 'my-video-caption-add-modal', | |
11 | styleUrls: [ './video-caption-add-modal.component.scss' ], | |
12 | templateUrl: './video-caption-add-modal.component.html' | |
13 | }) | |
14 | ||
15 | export class VideoCaptionAddModalComponent extends FormReactive implements OnInit { | |
16 | @Input() existingCaptions: string[] | |
17 | ||
18 | @Output() captionAdded = new EventEmitter<VideoCaptionEdit>() | |
19 | ||
63347a0f | 20 | @ViewChild('modal') modal: ElementRef |
40e87e9e C |
21 | |
22 | videoCaptionLanguages = [] | |
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 () { | |
37 | return this.serverService.getConfig().videoCaption.file.extensions | |
38 | } | |
39 | ||
40 | get videoCaptionMaxSize () { | |
41 | return this.serverService.getConfig().videoCaption.file.size.max | |
42 | } | |
43 | ||
44 | ngOnInit () { | |
45 | this.videoCaptionLanguages = this.serverService.getVideoLanguages() | |
46 | ||
47 | this.buildForm({ | |
48 | language: this.videoCaptionsValidatorsService.VIDEO_CAPTION_LANGUAGE, | |
49 | captionfile: this.videoCaptionsValidatorsService.VIDEO_CAPTION_FILE | |
50 | }) | |
51 | } | |
52 | ||
53 | show () { | |
f4001cf4 C |
54 | this.closingModal = false |
55 | ||
63347a0f | 56 | this.openedModal = this.modalService.open(this.modal, { keyboard: false }) |
40e87e9e C |
57 | } |
58 | ||
59 | hide () { | |
f4001cf4 | 60 | this.closingModal = true |
63347a0f | 61 | this.openedModal.close() |
40e87e9e C |
62 | } |
63 | ||
64 | isReplacingExistingCaption () { | |
65 | if (this.closingModal === true) return false | |
66 | ||
67 | const languageId = this.form.value[ 'language' ] | |
68 | ||
69 | return languageId && this.existingCaptions.indexOf(languageId) !== -1 | |
70 | } | |
71 | ||
72 | async addCaption () { | |
f4001cf4 | 73 | this.hide() |
40e87e9e C |
74 | |
75 | const languageId = this.form.value[ 'language' ] | |
76 | const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId) | |
77 | ||
78 | this.captionAdded.emit({ | |
79 | language: languageObject, | |
337ba64e | 80 | captionfile: this.form.value[ 'captionfile' ] |
40e87e9e C |
81 | }) |
82 | ||
f4001cf4 | 83 | this.form.reset() |
40e87e9e C |
84 | } |
85 | } |