diff options
Diffstat (limited to 'client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.ts')
-rw-r--r-- | client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.ts | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.ts b/client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.ts new file mode 100644 index 000000000..45b8c71f8 --- /dev/null +++ b/client/src/app/videos/+video-edit/shared/video-caption-add-modal.component.ts | |||
@@ -0,0 +1,80 @@ | |||
1 | import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' | ||
2 | import { ModalDirective } from 'ngx-bootstrap/modal' | ||
3 | import { FormReactive } from '@app/shared' | ||
4 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | ||
5 | import { VideoCaptionsValidatorsService } from '@app/shared/forms/form-validators/video-captions-validators.service' | ||
6 | import { ServerService } from '@app/core' | ||
7 | import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model' | ||
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 | |||
20 | @ViewChild('modal') modal: ModalDirective | ||
21 | |||
22 | videoCaptionLanguages = [] | ||
23 | |||
24 | private closingModal = false | ||
25 | |||
26 | constructor ( | ||
27 | protected formValidatorService: FormValidatorService, | ||
28 | private serverService: ServerService, | ||
29 | private videoCaptionsValidatorsService: VideoCaptionsValidatorsService | ||
30 | ) { | ||
31 | super() | ||
32 | } | ||
33 | |||
34 | get videoCaptionExtensions () { | ||
35 | return this.serverService.getConfig().videoCaption.file.extensions | ||
36 | } | ||
37 | |||
38 | get videoCaptionMaxSize () { | ||
39 | return this.serverService.getConfig().videoCaption.file.size.max | ||
40 | } | ||
41 | |||
42 | ngOnInit () { | ||
43 | this.videoCaptionLanguages = this.serverService.getVideoLanguages() | ||
44 | |||
45 | this.buildForm({ | ||
46 | language: this.videoCaptionsValidatorsService.VIDEO_CAPTION_LANGUAGE, | ||
47 | captionfile: this.videoCaptionsValidatorsService.VIDEO_CAPTION_FILE | ||
48 | }) | ||
49 | } | ||
50 | |||
51 | show () { | ||
52 | this.modal.show() | ||
53 | } | ||
54 | |||
55 | hide () { | ||
56 | this.modal.hide() | ||
57 | } | ||
58 | |||
59 | isReplacingExistingCaption () { | ||
60 | if (this.closingModal === true) return false | ||
61 | |||
62 | const languageId = this.form.value[ 'language' ] | ||
63 | |||
64 | return languageId && this.existingCaptions.indexOf(languageId) !== -1 | ||
65 | } | ||
66 | |||
67 | async addCaption () { | ||
68 | this.closingModal = true | ||
69 | |||
70 | const languageId = this.form.value[ 'language' ] | ||
71 | const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId) | ||
72 | |||
73 | this.captionAdded.emit({ | ||
74 | language: languageObject, | ||
75 | captionfile: this.form.value['captionfile'] | ||
76 | }) | ||
77 | |||
78 | this.hide() | ||
79 | } | ||
80 | } | ||