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