aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-edit/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-05 10:58:45 +0200
committerChocobozzz <me@florianbigard.com>2018-06-05 10:58:45 +0200
commitd18d64787b3ea174f7dc2740c8c8c9555625047e (patch)
treee65089e0ca81117c1ada981b9b8a524afa8d70f5 /client/src/app/videos/+video-edit/shared
parent25acef90a85c1584880dec96aa402f896af8364a (diff)
downloadPeerTube-d18d64787b3ea174f7dc2740c8c8c9555625047e.tar.gz
PeerTube-d18d64787b3ea174f7dc2740c8c8c9555625047e.tar.zst
PeerTube-d18d64787b3ea174f7dc2740c8c8c9555625047e.zip
Form validators refractoring
Diffstat (limited to 'client/src/app/videos/+video-edit/shared')
-rw-r--r--client/src/app/videos/+video-edit/shared/video-edit.component.ts71
1 files changed, 33 insertions, 38 deletions
diff --git a/client/src/app/videos/+video-edit/shared/video-edit.component.ts b/client/src/app/videos/+video-edit/shared/video-edit.component.ts
index ccfae5fcc..cd2a26ae3 100644
--- a/client/src/app/videos/+video-edit/shared/video-edit.component.ts
+++ b/client/src/app/videos/+video-edit/shared/video-edit.component.ts
@@ -1,7 +1,7 @@
1import { Component, Input, OnInit } from '@angular/core' 1import { Component, Input, OnInit } from '@angular/core'
2import { FormBuilder, FormControl, FormGroup } from '@angular/forms' 2import { FormGroup } from '@angular/forms'
3import { ActivatedRoute, Router } from '@angular/router' 3import { ActivatedRoute, Router } from '@angular/router'
4import { VIDEO_IMAGE, VIDEO_SUPPORT } from '@app/shared' 4import { VIDEO_SUPPORT } from '@app/shared'
5import { NotificationsService } from 'angular2-notifications' 5import { NotificationsService } from 'angular2-notifications'
6import { ServerService } from '../../../core/server' 6import { ServerService } from '../../../core/server'
7import { VIDEO_CHANNEL } from '../../../shared/forms/form-validators' 7import { VIDEO_CHANNEL } from '../../../shared/forms/form-validators'
@@ -17,6 +17,7 @@ import {
17} from '../../../shared/forms/form-validators/video' 17} from '../../../shared/forms/form-validators/video'
18import { VideoEdit } from '../../../shared/video/video-edit.model' 18import { VideoEdit } from '../../../shared/video/video-edit.model'
19import { map } from 'rxjs/operators' 19import { map } from 'rxjs/operators'
20import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
20 21
21@Component({ 22@Component({
22 selector: 'my-video-edit', 23 selector: 'my-video-edit',
@@ -42,7 +43,7 @@ export class VideoEditComponent implements OnInit {
42 error: string = null 43 error: string = null
43 44
44 constructor ( 45 constructor (
45 private formBuilder: FormBuilder, 46 private formValidatorService: FormValidatorService,
46 private route: ActivatedRoute, 47 private route: ActivatedRoute,
47 private router: Router, 48 private router: Router,
48 private notificationsService: NotificationsService, 49 private notificationsService: NotificationsService,
@@ -50,41 +51,34 @@ export class VideoEditComponent implements OnInit {
50 ) { } 51 ) { }
51 52
52 updateForm () { 53 updateForm () {
53 this.formErrors['name'] = '' 54 const defaultValues = {
54 this.formErrors['privacy'] = '' 55 nsfw: 'false',
55 this.formErrors['channelId'] = '' 56 commentsEnabled: 'true',
56 this.formErrors['category'] = '' 57 tags: []
57 this.formErrors['licence'] = '' 58 }
58 this.formErrors['language'] = '' 59 const obj = {
59 this.formErrors['description'] = '' 60 name: VIDEO_NAME,
60 this.formErrors['thumbnailfile'] = '' 61 privacy: VIDEO_PRIVACY,
61 this.formErrors['previewfile'] = '' 62 channelId: VIDEO_CHANNEL,
62 this.formErrors['support'] = '' 63 nsfw: null,
63 64 commentsEnabled: null,
64 this.validationMessages['name'] = VIDEO_NAME.MESSAGES 65 category: VIDEO_CATEGORY,
65 this.validationMessages['privacy'] = VIDEO_PRIVACY.MESSAGES 66 licence: VIDEO_LICENCE,
66 this.validationMessages['channelId'] = VIDEO_CHANNEL.MESSAGES 67 language: VIDEO_LANGUAGE,
67 this.validationMessages['category'] = VIDEO_CATEGORY.MESSAGES 68 description: VIDEO_DESCRIPTION,
68 this.validationMessages['licence'] = VIDEO_LICENCE.MESSAGES 69 tags: null,
69 this.validationMessages['language'] = VIDEO_LANGUAGE.MESSAGES 70 thumbnailfile: null,
70 this.validationMessages['description'] = VIDEO_DESCRIPTION.MESSAGES 71 previewfile: null,
71 this.validationMessages['thumbnailfile'] = VIDEO_IMAGE.MESSAGES 72 support: VIDEO_SUPPORT
72 this.validationMessages['previewfile'] = VIDEO_IMAGE.MESSAGES 73 }
73 this.validationMessages['support'] = VIDEO_SUPPORT.MESSAGES 74
74 75 this.formValidatorService.updateForm(
75 this.form.addControl('name', new FormControl('', VIDEO_NAME.VALIDATORS)) 76 this.form,
76 this.form.addControl('privacy', new FormControl('', VIDEO_PRIVACY.VALIDATORS)) 77 this.formErrors,
77 this.form.addControl('channelId', new FormControl('', VIDEO_CHANNEL.VALIDATORS)) 78 this.validationMessages,
78 this.form.addControl('nsfw', new FormControl(false)) 79 obj,
79 this.form.addControl('commentsEnabled', new FormControl(true)) 80 defaultValues
80 this.form.addControl('category', new FormControl('', VIDEO_CATEGORY.VALIDATORS)) 81 )
81 this.form.addControl('licence', new FormControl('', VIDEO_LICENCE.VALIDATORS))
82 this.form.addControl('language', new FormControl('', VIDEO_LANGUAGE.VALIDATORS))
83 this.form.addControl('description', new FormControl('', VIDEO_DESCRIPTION.VALIDATORS))
84 this.form.addControl('tags', new FormControl([]))
85 this.form.addControl('thumbnailfile', new FormControl(''))
86 this.form.addControl('previewfile', new FormControl(''))
87 this.form.addControl('support', new FormControl('', VIDEO_SUPPORT.VALIDATORS))
88 82
89 // We will update the "support" field depending on the channel 83 // We will update the "support" field depending on the channel
90 this.form.controls['channelId'] 84 this.form.controls['channelId']
@@ -98,6 +92,7 @@ export class VideoEditComponent implements OnInit {
98 // Not initialized yet 92 // Not initialized yet
99 if (isNaN(newChannelId)) return 93 if (isNaN(newChannelId)) return
100 const newChannel = this.userVideoChannels.find(c => c.id === newChannelId) 94 const newChannel = this.userVideoChannels.find(c => c.id === newChannelId)
95 if (!newChannel) return
101 96
102 // First time we set the channel? 97 // First time we set the channel?
103 if (isNaN(oldChannelId)) return this.updateSupportField(newChannel.support) 98 if (isNaN(oldChannelId)) return this.updateSupportField(newChannel.support)