diff options
author | Chocobozzz <me@florianbigard.com> | 2019-03-14 14:55:10 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-03-18 11:17:59 +0100 |
commit | 978c9d497b36e52196eb7e755406571e5d57cbc7 (patch) | |
tree | 6984ab06e2c64542221f7329f7560d9e8025e660 /client/src/app/shared | |
parent | c5e4e36d2a1ad777233177c11f7f742df717a8e8 (diff) | |
download | PeerTube-978c9d497b36e52196eb7e755406571e5d57cbc7.tar.gz PeerTube-978c9d497b36e52196eb7e755406571e5d57cbc7.tar.zst PeerTube-978c9d497b36e52196eb7e755406571e5d57cbc7.zip |
Add playlist channel validator when playlist is public
Diffstat (limited to 'client/src/app/shared')
3 files changed, 24 insertions, 10 deletions
diff --git a/client/src/app/shared/forms/form-validators/video-playlist-validators.service.ts b/client/src/app/shared/forms/form-validators/video-playlist-validators.service.ts index 726084b47..a2c9a5368 100644 --- a/client/src/app/shared/forms/form-validators/video-playlist-validators.service.ts +++ b/client/src/app/shared/forms/form-validators/video-playlist-validators.service.ts | |||
@@ -1,7 +1,8 @@ | |||
1 | import { I18n } from '@ngx-translate/i18n-polyfill' | 1 | import { I18n } from '@ngx-translate/i18n-polyfill' |
2 | import { Validators } from '@angular/forms' | 2 | import { AbstractControl, FormControl, Validators } from '@angular/forms' |
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { BuildFormValidator } from '@app/shared' | 4 | import { BuildFormValidator } from '@app/shared' |
5 | import { VideoPlaylistPrivacy } from '@shared/models' | ||
5 | 6 | ||
6 | @Injectable() | 7 | @Injectable() |
7 | export class VideoPlaylistValidatorsService { | 8 | export class VideoPlaylistValidatorsService { |
@@ -46,7 +47,20 @@ export class VideoPlaylistValidatorsService { | |||
46 | 47 | ||
47 | this.VIDEO_PLAYLIST_CHANNEL_ID = { | 48 | this.VIDEO_PLAYLIST_CHANNEL_ID = { |
48 | VALIDATORS: [ ], | 49 | VALIDATORS: [ ], |
49 | MESSAGES: { } | 50 | MESSAGES: { |
51 | 'required': this.i18n('The channel is required when the playlist is public.') | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | |||
56 | setChannelValidator (channelControl: AbstractControl, privacy: VideoPlaylistPrivacy) { | ||
57 | if (privacy.toString() === VideoPlaylistPrivacy.PUBLIC.toString()) { | ||
58 | channelControl.setValidators([ Validators.required ]) | ||
59 | } else { | ||
60 | channelControl.setValidators(null) | ||
50 | } | 61 | } |
62 | |||
63 | channelControl.markAsDirty() | ||
64 | channelControl.updateValueAndValidity() | ||
51 | } | 65 | } |
52 | } | 66 | } |
diff --git a/client/src/app/shared/video-playlist/video-add-to-playlist.component.html b/client/src/app/shared/video-playlist/video-add-to-playlist.component.html index f85e50d6d..19b326206 100644 --- a/client/src/app/shared/video-playlist/video-add-to-playlist.component.html +++ b/client/src/app/shared/video-playlist/video-add-to-playlist.component.html | |||
@@ -60,13 +60,13 @@ | |||
60 | 60 | ||
61 | <form class="new-playlist-block dropdown-item" *ngIf="isNewPlaylistBlockOpened" (ngSubmit)="createPlaylist()" [formGroup]="form"> | 61 | <form class="new-playlist-block dropdown-item" *ngIf="isNewPlaylistBlockOpened" (ngSubmit)="createPlaylist()" [formGroup]="form"> |
62 | <div class="form-group"> | 62 | <div class="form-group"> |
63 | <label i18n for="display-name">Display name</label> | 63 | <label i18n for="displayName">Display name</label> |
64 | <input | 64 | <input |
65 | type="text" id="display-name" | 65 | type="text" id="displayName" |
66 | formControlName="display-name" [ngClass]="{ 'input-error': formErrors['display-name'] }" | 66 | formControlName="displayName" [ngClass]="{ 'input-error': formErrors['displayName'] }" |
67 | > | 67 | > |
68 | <div *ngIf="formErrors['display-name']" class="form-error"> | 68 | <div *ngIf="formErrors['displayName']" class="form-error"> |
69 | {{ formErrors['display-name'] }} | 69 | {{ formErrors['displayName'] }} |
70 | </div> | 70 | </div> |
71 | </div> | 71 | </div> |
72 | 72 | ||
diff --git a/client/src/app/shared/video-playlist/video-add-to-playlist.component.ts b/client/src/app/shared/video-playlist/video-add-to-playlist.component.ts index c6fb6dbed..705f62404 100644 --- a/client/src/app/shared/video-playlist/video-add-to-playlist.component.ts +++ b/client/src/app/shared/video-playlist/video-add-to-playlist.component.ts | |||
@@ -5,7 +5,7 @@ import { forkJoin } from 'rxjs' | |||
5 | import { Video, VideoPlaylistCreate, VideoPlaylistElementCreate, VideoPlaylistPrivacy } from '@shared/models' | 5 | import { Video, VideoPlaylistCreate, VideoPlaylistElementCreate, VideoPlaylistPrivacy } from '@shared/models' |
6 | import { FormReactive, FormValidatorService, VideoPlaylistValidatorsService } from '@app/shared/forms' | 6 | import { FormReactive, FormValidatorService, VideoPlaylistValidatorsService } from '@app/shared/forms' |
7 | import { I18n } from '@ngx-translate/i18n-polyfill' | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
8 | import { secondsToTime, timeToInt } from '../../../assets/player/utils' | 8 | import { secondsToTime } from '../../../assets/player/utils' |
9 | 9 | ||
10 | type PlaylistSummary = { | 10 | type PlaylistSummary = { |
11 | id: number | 11 | id: number |
@@ -54,7 +54,7 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit | |||
54 | this.resetOptions(true) | 54 | this.resetOptions(true) |
55 | 55 | ||
56 | this.buildForm({ | 56 | this.buildForm({ |
57 | 'display-name': this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME | 57 | displayName: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME |
58 | }) | 58 | }) |
59 | 59 | ||
60 | forkJoin([ | 60 | forkJoin([ |
@@ -105,7 +105,7 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit | |||
105 | } | 105 | } |
106 | 106 | ||
107 | createPlaylist () { | 107 | createPlaylist () { |
108 | const displayName = this.form.value[ 'display-name' ] | 108 | const displayName = this.form.value[ 'displayName' ] |
109 | 109 | ||
110 | const videoPlaylistCreate: VideoPlaylistCreate = { | 110 | const videoPlaylistCreate: VideoPlaylistCreate = { |
111 | displayName, | 111 | displayName, |