]>
Commit | Line | Data |
---|---|---|
ff249f49 C |
1 | import { Component, Input, OnInit } from '@angular/core' |
2 | import { FormBuilder, FormControl, FormGroup } from '@angular/forms' | |
3 | import { ActivatedRoute, Router } from '@angular/router' | |
07fa4c97 | 4 | import { VIDEO_IMAGE, VIDEO_SUPPORT } from '@app/shared' |
ff249f49 | 5 | import { NotificationsService } from 'angular2-notifications' |
ff249f49 | 6 | import 'rxjs/add/observable/forkJoin' |
63c4db6d | 7 | import { ServerService } from '../../../core/server' |
15a7387d | 8 | import { VIDEO_CHANNEL } from '../../../shared/forms/form-validators' |
63c4db6d | 9 | import { ValidatorMessage } from '../../../shared/forms/form-validators/validator-message' |
ff249f49 | 10 | import { |
ff249f49 C |
11 | VIDEO_CATEGORY, |
12 | VIDEO_DESCRIPTION, | |
13 | VIDEO_LANGUAGE, | |
14 | VIDEO_LICENCE, | |
15 | VIDEO_NAME, | |
16 | VIDEO_PRIVACY, | |
17 | VIDEO_TAGS | |
63c4db6d C |
18 | } from '../../../shared/forms/form-validators/video' |
19 | import { VideoEdit } from '../../../shared/video/video-edit.model' | |
ff249f49 C |
20 | |
21 | @Component({ | |
22 | selector: 'my-video-edit', | |
23 | styleUrls: [ './video-edit.component.scss' ], | |
24 | templateUrl: './video-edit.component.html' | |
25 | }) | |
26 | ||
27 | export class VideoEditComponent implements OnInit { | |
28 | @Input() form: FormGroup | |
29 | @Input() formErrors: { [ id: string ]: string } = {} | |
30 | @Input() validationMessages: ValidatorMessage = {} | |
31 | @Input() videoPrivacies = [] | |
15a7387d | 32 | @Input() userVideoChannels = [] |
ff249f49 C |
33 | |
34 | tags: string[] = [] | |
35 | videoCategories = [] | |
36 | videoLicences = [] | |
37 | videoLanguages = [] | |
38 | video: VideoEdit | |
39 | ||
40 | tagValidators = VIDEO_TAGS.VALIDATORS | |
41 | tagValidatorsMessages = VIDEO_TAGS.MESSAGES | |
42 | ||
43 | error: string = null | |
44 | ||
45 | constructor ( | |
46 | private formBuilder: FormBuilder, | |
47 | private route: ActivatedRoute, | |
48 | private router: Router, | |
49 | private notificationsService: NotificationsService, | |
50 | private serverService: ServerService | |
51 | ) { } | |
52 | ||
53 | updateForm () { | |
54 | this.formErrors['name'] = '' | |
55 | this.formErrors['privacy'] = '' | |
15a7387d | 56 | this.formErrors['channelId'] = '' |
ff249f49 C |
57 | this.formErrors['category'] = '' |
58 | this.formErrors['licence'] = '' | |
59 | this.formErrors['language'] = '' | |
60 | this.formErrors['description'] = '' | |
6de36768 C |
61 | this.formErrors['thumbnailfile'] = '' |
62 | this.formErrors['previewfile'] = '' | |
07fa4c97 | 63 | this.formErrors['support'] = '' |
ff249f49 C |
64 | |
65 | this.validationMessages['name'] = VIDEO_NAME.MESSAGES | |
66 | this.validationMessages['privacy'] = VIDEO_PRIVACY.MESSAGES | |
15a7387d | 67 | this.validationMessages['channelId'] = VIDEO_CHANNEL.MESSAGES |
ff249f49 C |
68 | this.validationMessages['category'] = VIDEO_CATEGORY.MESSAGES |
69 | this.validationMessages['licence'] = VIDEO_LICENCE.MESSAGES | |
70 | this.validationMessages['language'] = VIDEO_LANGUAGE.MESSAGES | |
71 | this.validationMessages['description'] = VIDEO_DESCRIPTION.MESSAGES | |
6de36768 C |
72 | this.validationMessages['thumbnailfile'] = VIDEO_IMAGE.MESSAGES |
73 | this.validationMessages['previewfile'] = VIDEO_IMAGE.MESSAGES | |
07fa4c97 | 74 | this.validationMessages['support'] = VIDEO_SUPPORT.MESSAGES |
ff249f49 C |
75 | |
76 | this.form.addControl('name', new FormControl('', VIDEO_NAME.VALIDATORS)) | |
77 | this.form.addControl('privacy', new FormControl('', VIDEO_PRIVACY.VALIDATORS)) | |
15a7387d | 78 | this.form.addControl('channelId', new FormControl({ value: '', disabled: true })) |
ff249f49 | 79 | this.form.addControl('nsfw', new FormControl(false)) |
47564bbe | 80 | this.form.addControl('commentsEnabled', new FormControl(true)) |
ff249f49 C |
81 | this.form.addControl('category', new FormControl('', VIDEO_CATEGORY.VALIDATORS)) |
82 | this.form.addControl('licence', new FormControl('', VIDEO_LICENCE.VALIDATORS)) | |
83 | this.form.addControl('language', new FormControl('', VIDEO_LANGUAGE.VALIDATORS)) | |
84 | this.form.addControl('description', new FormControl('', VIDEO_DESCRIPTION.VALIDATORS)) | |
85 | this.form.addControl('tags', new FormControl('')) | |
6de36768 C |
86 | this.form.addControl('thumbnailfile', new FormControl('')) |
87 | this.form.addControl('previewfile', new FormControl('')) | |
9f4183c9 | 88 | this.form.addControl('support', new FormControl('', VIDEO_SUPPORT.VALIDATORS)) |
ff249f49 C |
89 | } |
90 | ||
91 | ngOnInit () { | |
92 | this.updateForm() | |
93 | ||
94 | this.videoCategories = this.serverService.getVideoCategories() | |
95 | this.videoLicences = this.serverService.getVideoLicences() | |
96 | this.videoLanguages = this.serverService.getVideoLanguages() | |
97 | } | |
98 | } |