]>
Commit | Line | Data |
---|---|---|
830b4faf | 1 | import { Injectable } from '@angular/core' |
66357162 | 2 | import { AbstractControl, Validators } from '@angular/forms' |
978c9d49 | 3 | import { VideoPlaylistPrivacy } from '@shared/models' |
66357162 | 4 | import { BuildFormValidator } from './form-validator.service' |
830b4faf C |
5 | |
6 | @Injectable() | |
7 | export class VideoPlaylistValidatorsService { | |
8 | readonly VIDEO_PLAYLIST_DISPLAY_NAME: BuildFormValidator | |
9 | readonly VIDEO_PLAYLIST_PRIVACY: BuildFormValidator | |
10 | readonly VIDEO_PLAYLIST_DESCRIPTION: BuildFormValidator | |
11 | readonly VIDEO_PLAYLIST_CHANNEL_ID: BuildFormValidator | |
12 | ||
66357162 | 13 | constructor () { |
830b4faf C |
14 | this.VIDEO_PLAYLIST_DISPLAY_NAME = { |
15 | VALIDATORS: [ | |
16 | Validators.required, | |
17 | Validators.minLength(1), | |
18 | Validators.maxLength(120) | |
19 | ], | |
20 | MESSAGES: { | |
66357162 C |
21 | 'required': $localize`Display name is required.`, |
22 | 'minlength': $localize`Display name must be at least 1 character long.`, | |
23 | 'maxlength': $localize`Display name cannot be more than 120 characters long.` | |
830b4faf C |
24 | } |
25 | } | |
26 | ||
27 | this.VIDEO_PLAYLIST_PRIVACY = { | |
28 | VALIDATORS: [ | |
29 | Validators.required | |
30 | ], | |
31 | MESSAGES: { | |
66357162 | 32 | 'required': $localize`Privacy is required.` |
830b4faf C |
33 | } |
34 | } | |
35 | ||
36 | this.VIDEO_PLAYLIST_DESCRIPTION = { | |
37 | VALIDATORS: [ | |
38 | Validators.minLength(3), | |
39 | Validators.maxLength(1000) | |
40 | ], | |
41 | MESSAGES: { | |
66357162 C |
42 | 'minlength': $localize`Description must be at least 3 characters long.`, |
43 | 'maxlength': $localize`Description cannot be more than 1000 characters long.` | |
830b4faf C |
44 | } |
45 | } | |
46 | ||
47 | this.VIDEO_PLAYLIST_CHANNEL_ID = { | |
48 | VALIDATORS: [ ], | |
978c9d49 | 49 | MESSAGES: { |
66357162 | 50 | 'required': $localize`The channel is required when the playlist is public.` |
978c9d49 C |
51 | } |
52 | } | |
53 | } | |
54 | ||
55 | setChannelValidator (channelControl: AbstractControl, privacy: VideoPlaylistPrivacy) { | |
56 | if (privacy.toString() === VideoPlaylistPrivacy.PUBLIC.toString()) { | |
57 | channelControl.setValidators([ Validators.required ]) | |
58 | } else { | |
59 | channelControl.setValidators(null) | |
830b4faf | 60 | } |
978c9d49 C |
61 | |
62 | channelControl.markAsDirty() | |
63 | channelControl.updateValueAndValidity() | |
830b4faf C |
64 | } |
65 | } |