1 import { I18n } from '@ngx-translate/i18n-polyfill'
2 import { AbstractControl, FormControl, Validators } from '@angular/forms'
3 import { Injectable } from '@angular/core'
4 import { BuildFormValidator } from '@app/shared'
5 import { VideoPlaylistPrivacy } from '@shared/models'
8 export class VideoPlaylistValidatorsService {
9 readonly VIDEO_PLAYLIST_DISPLAY_NAME: BuildFormValidator
10 readonly VIDEO_PLAYLIST_PRIVACY: BuildFormValidator
11 readonly VIDEO_PLAYLIST_DESCRIPTION: BuildFormValidator
12 readonly VIDEO_PLAYLIST_CHANNEL_ID: BuildFormValidator
14 constructor (private i18n: I18n) {
15 this.VIDEO_PLAYLIST_DISPLAY_NAME = {
18 Validators.minLength(1),
19 Validators.maxLength(120)
22 'required': this.i18n('Display name is required.'),
23 'minlength': this.i18n('Display name must be at least 1 character long.'),
24 'maxlength': this.i18n('Display name cannot be more than 120 characters long.')
28 this.VIDEO_PLAYLIST_PRIVACY = {
33 'required': this.i18n('Privacy is required.')
37 this.VIDEO_PLAYLIST_DESCRIPTION = {
39 Validators.minLength(3),
40 Validators.maxLength(1000)
43 'minlength': i18n('Description must be at least 3 characters long.'),
44 'maxlength': i18n('Description cannot be more than 1000 characters long.')
48 this.VIDEO_PLAYLIST_CHANNEL_ID = {
51 'required': this.i18n('The channel is required when the playlist is public.')
56 setChannelValidator (channelControl: AbstractControl, privacy: VideoPlaylistPrivacy) {
57 if (privacy.toString() === VideoPlaylistPrivacy.PUBLIC.toString()) {
58 channelControl.setValidators([ Validators.required ])
60 channelControl.setValidators(null)
63 channelControl.markAsDirty()
64 channelControl.updateValueAndValidity()