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