]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-edit/shared/video-edit.component.ts
Design modals
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / shared / video-edit.component.ts
CommitLineData
ff249f49
C
1import { Component, Input, OnInit } from '@angular/core'
2import { FormBuilder, FormControl, FormGroup } from '@angular/forms'
3import { ActivatedRoute, Router } from '@angular/router'
4import { NotificationsService } from 'angular2-notifications'
ff249f49 5import 'rxjs/add/observable/forkJoin'
63c4db6d 6import { ServerService } from '../../../core/server'
15a7387d 7import { VIDEO_CHANNEL } from '../../../shared/forms/form-validators'
63c4db6d 8import { ValidatorMessage } from '../../../shared/forms/form-validators/validator-message'
ff249f49 9import {
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'
18import { 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
26export 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
C
32
33 tags: string[] = []
34 videoCategories = []
35 videoLicences = []
36 videoLanguages = []
37 video: VideoEdit
38
39 tagValidators = VIDEO_TAGS.VALIDATORS
40 tagValidatorsMessages = VIDEO_TAGS.MESSAGES
41
42 error: string = null
43
44 constructor (
45 private formBuilder: FormBuilder,
46 private route: ActivatedRoute,
47 private router: Router,
48 private notificationsService: NotificationsService,
49 private serverService: ServerService
50 ) { }
51
52 updateForm () {
53 this.formErrors['name'] = ''
54 this.formErrors['privacy'] = ''
15a7387d 55 this.formErrors['channelId'] = ''
ff249f49
C
56 this.formErrors['category'] = ''
57 this.formErrors['licence'] = ''
58 this.formErrors['language'] = ''
59 this.formErrors['description'] = ''
60
61 this.validationMessages['name'] = VIDEO_NAME.MESSAGES
62 this.validationMessages['privacy'] = VIDEO_PRIVACY.MESSAGES
15a7387d 63 this.validationMessages['channelId'] = VIDEO_CHANNEL.MESSAGES
ff249f49
C
64 this.validationMessages['category'] = VIDEO_CATEGORY.MESSAGES
65 this.validationMessages['licence'] = VIDEO_LICENCE.MESSAGES
66 this.validationMessages['language'] = VIDEO_LANGUAGE.MESSAGES
67 this.validationMessages['description'] = VIDEO_DESCRIPTION.MESSAGES
68
69 this.form.addControl('name', new FormControl('', VIDEO_NAME.VALIDATORS))
70 this.form.addControl('privacy', new FormControl('', VIDEO_PRIVACY.VALIDATORS))
15a7387d 71 this.form.addControl('channelId', new FormControl({ value: '', disabled: true }))
ff249f49
C
72 this.form.addControl('nsfw', new FormControl(false))
73 this.form.addControl('category', new FormControl('', VIDEO_CATEGORY.VALIDATORS))
74 this.form.addControl('licence', new FormControl('', VIDEO_LICENCE.VALIDATORS))
75 this.form.addControl('language', new FormControl('', VIDEO_LANGUAGE.VALIDATORS))
76 this.form.addControl('description', new FormControl('', VIDEO_DESCRIPTION.VALIDATORS))
77 this.form.addControl('tags', new FormControl(''))
78 }
79
80 ngOnInit () {
81 this.updateForm()
82
83 this.videoCategories = this.serverService.getVideoCategories()
84 this.videoLicences = this.serverService.getVideoLicences()
85 this.videoLanguages = this.serverService.getVideoLanguages()
86 }
87}