diff options
Diffstat (limited to 'client/src/app/videos/video-edit/video-update.component.ts')
-rw-r--r-- | client/src/app/videos/video-edit/video-update.component.ts | 60 |
1 files changed, 6 insertions, 54 deletions
diff --git a/client/src/app/videos/video-edit/video-update.component.ts b/client/src/app/videos/video-edit/video-update.component.ts index b45780a41..adb3d295c 100644 --- a/client/src/app/videos/video-edit/video-update.component.ts +++ b/client/src/app/videos/video-edit/video-update.component.ts | |||
@@ -30,6 +30,9 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { | |||
30 | videoLanguages = []; | 30 | videoLanguages = []; |
31 | video: Video; | 31 | video: Video; |
32 | 32 | ||
33 | tagValidators = VIDEO_TAGS.VALIDATORS; | ||
34 | tagValidatorsMessages = VIDEO_TAGS.MESSAGES; | ||
35 | |||
33 | error: string = null; | 36 | error: string = null; |
34 | form: FormGroup; | 37 | form: FormGroup; |
35 | formErrors = { | 38 | formErrors = { |
@@ -37,20 +40,16 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { | |||
37 | category: '', | 40 | category: '', |
38 | licence: '', | 41 | licence: '', |
39 | language: '', | 42 | language: '', |
40 | description: '', | 43 | description: '' |
41 | currentTag: '' | ||
42 | }; | 44 | }; |
43 | validationMessages = { | 45 | validationMessages = { |
44 | name: VIDEO_NAME.MESSAGES, | 46 | name: VIDEO_NAME.MESSAGES, |
45 | category: VIDEO_CATEGORY.MESSAGES, | 47 | category: VIDEO_CATEGORY.MESSAGES, |
46 | licence: VIDEO_LICENCE.MESSAGES, | 48 | licence: VIDEO_LICENCE.MESSAGES, |
47 | language: VIDEO_LANGUAGE.MESSAGES, | 49 | language: VIDEO_LANGUAGE.MESSAGES, |
48 | description: VIDEO_DESCRIPTION.MESSAGES, | 50 | description: VIDEO_DESCRIPTION.MESSAGES |
49 | currentTag: VIDEO_TAGS.MESSAGES | ||
50 | }; | 51 | }; |
51 | 52 | ||
52 | // Special error messages | ||
53 | tagsError = ''; | ||
54 | fileError = ''; | 53 | fileError = ''; |
55 | 54 | ||
56 | constructor( | 55 | constructor( |
@@ -73,7 +72,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { | |||
73 | licence: [ '', VIDEO_LICENCE.VALIDATORS ], | 72 | licence: [ '', VIDEO_LICENCE.VALIDATORS ], |
74 | language: [ '', VIDEO_LANGUAGE.VALIDATORS ], | 73 | language: [ '', VIDEO_LANGUAGE.VALIDATORS ], |
75 | description: [ '', VIDEO_DESCRIPTION.VALIDATORS ], | 74 | description: [ '', VIDEO_DESCRIPTION.VALIDATORS ], |
76 | currentTag: [ '', VIDEO_TAGS.VALIDATORS ] | 75 | tags: [ '' ] |
77 | }); | 76 | }); |
78 | 77 | ||
79 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)); | 78 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)); |
@@ -99,33 +98,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { | |||
99 | ); | 98 | ); |
100 | } | 99 | } |
101 | 100 | ||
102 | checkForm() { | ||
103 | this.forceCheck(); | ||
104 | |||
105 | return this.form.valid === true && this.tagsError === '' && this.fileError === ''; | ||
106 | } | ||
107 | |||
108 | |||
109 | onTagKeyPress(event: KeyboardEvent) { | ||
110 | // Enter press | ||
111 | if (event.keyCode === 13) { | ||
112 | this.addTagIfPossible(); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | removeTag(tag: string) { | ||
117 | this.tags.splice(this.tags.indexOf(tag), 1); | ||
118 | this.form.get('currentTag').enable(); | ||
119 | } | ||
120 | |||
121 | update() { | 101 | update() { |
122 | // Maybe the user forgot to press "enter" when he filled the field | ||
123 | this.addTagIfPossible(); | ||
124 | |||
125 | if (this.checkForm() === false) { | ||
126 | return; | ||
127 | } | ||
128 | |||
129 | this.video.patch(this.form.value); | 102 | this.video.patch(this.form.value); |
130 | 103 | ||
131 | this.videoService.updateVideo(this.video) | 104 | this.videoService.updateVideo(this.video) |
@@ -143,27 +116,6 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { | |||
143 | 116 | ||
144 | } | 117 | } |
145 | 118 | ||
146 | private addTagIfPossible() { | ||
147 | const currentTag = this.form.value['currentTag']; | ||
148 | if (currentTag === undefined) return; | ||
149 | |||
150 | // Check if the tag is valid and does not already exist | ||
151 | if ( | ||
152 | currentTag.length >= 2 && | ||
153 | this.form.controls['currentTag'].valid && | ||
154 | this.tags.indexOf(currentTag) === -1 | ||
155 | ) { | ||
156 | this.tags.push(currentTag); | ||
157 | this.form.patchValue({ currentTag: '' }); | ||
158 | |||
159 | if (this.tags.length >= 3) { | ||
160 | this.form.get('currentTag').disable(); | ||
161 | } | ||
162 | |||
163 | this.tagsError = ''; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | private hydrateFormFromVideo() { | 119 | private hydrateFormFromVideo() { |
168 | this.form.patchValue(this.video.toJSON()); | 120 | this.form.patchValue(this.video.toJSON()); |
169 | } | 121 | } |