diff options
Diffstat (limited to 'client/src/app/videos/+video-edit/shared')
-rw-r--r-- | client/src/app/videos/+video-edit/shared/video-edit.component.ts | 71 |
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 @@ | |||
1 | import { Component, Input, OnInit } from '@angular/core' | 1 | import { Component, Input, OnInit } from '@angular/core' |
2 | import { FormBuilder, FormControl, FormGroup } from '@angular/forms' | 2 | import { FormGroup } from '@angular/forms' |
3 | import { ActivatedRoute, Router } from '@angular/router' | 3 | import { ActivatedRoute, Router } from '@angular/router' |
4 | import { VIDEO_IMAGE, VIDEO_SUPPORT } from '@app/shared' | 4 | import { VIDEO_SUPPORT } from '@app/shared' |
5 | import { NotificationsService } from 'angular2-notifications' | 5 | import { NotificationsService } from 'angular2-notifications' |
6 | import { ServerService } from '../../../core/server' | 6 | import { ServerService } from '../../../core/server' |
7 | import { VIDEO_CHANNEL } from '../../../shared/forms/form-validators' | 7 | import { 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' |
18 | import { VideoEdit } from '../../../shared/video/video-edit.model' | 18 | import { VideoEdit } from '../../../shared/video/video-edit.model' |
19 | import { map } from 'rxjs/operators' | 19 | import { map } from 'rxjs/operators' |
20 | import { 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) |