1 import { Injectable } from '@angular/core'
2 import { AbstractControl, Validators } from '@angular/forms'
3 import { VideoPlaylistPrivacy } from '@shared/models'
4 import { BuildFormValidator } from './form-validator.service'
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
14 this.VIDEO_PLAYLIST_DISPLAY_NAME = {
17 Validators.minLength(1),
18 Validators.maxLength(120)
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.`
27 this.VIDEO_PLAYLIST_PRIVACY = {
32 'required': $localize`Privacy is required.`
36 this.VIDEO_PLAYLIST_DESCRIPTION = {
38 Validators.minLength(3),
39 Validators.maxLength(1000)
42 'minlength': $localize`Description must be at least 3 characters long.`,
43 'maxlength': $localize`Description cannot be more than 1000 characters long.`
47 this.VIDEO_PLAYLIST_CHANNEL_ID = {
50 'required': $localize`The channel is required when the playlist is public.`
55 setChannelValidator (channelControl: AbstractControl, privacy: VideoPlaylistPrivacy) {
56 if (privacy.toString() === VideoPlaylistPrivacy.PUBLIC.toString()) {
57 channelControl.setValidators([ Validators.required ])
59 channelControl.setValidators(null)
62 channelControl.markAsDirty()
63 channelControl.updateValueAndValidity()