]>
Commit | Line | Data |
---|---|---|
830b4faf C |
1 | import { Component, OnInit } from '@angular/core' |
2 | import { Router } from '@angular/router' | |
3 | import { AuthService, Notifier, ServerService } from '@app/core' | |
9556ce48 | 4 | import { listUserChannels } from '@app/helpers' |
7ed1edbb C |
5 | import { |
6 | setPlaylistChannelValidator, | |
7 | VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR, | |
8 | VIDEO_PLAYLIST_DESCRIPTION_VALIDATOR, | |
9 | VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR, | |
10 | VIDEO_PLAYLIST_PRIVACY_VALIDATOR | |
11 | } from '@app/shared/form-validators/video-playlist-validators' | |
12 | import { FormValidatorService } from '@app/shared/shared-forms' | |
67ed6552 | 13 | import { VideoPlaylistService } from '@app/shared/shared-video-playlist' |
830b4faf | 14 | import { VideoPlaylistCreate } from '@shared/models/videos/playlist/video-playlist-create.model' |
830b4faf | 15 | import { VideoPlaylistPrivacy } from '@shared/models/videos/playlist/video-playlist-privacy.model' |
17119e4a | 16 | import { MyVideoPlaylistEdit } from './my-video-playlist-edit' |
830b4faf C |
17 | |
18 | @Component({ | |
17119e4a C |
19 | templateUrl: './my-video-playlist-edit.component.html', |
20 | styleUrls: [ './my-video-playlist-edit.component.scss' ] | |
830b4faf | 21 | }) |
17119e4a | 22 | export class MyVideoPlaylistCreateComponent extends MyVideoPlaylistEdit implements OnInit { |
830b4faf | 23 | error: string |
830b4faf C |
24 | |
25 | constructor ( | |
26 | protected formValidatorService: FormValidatorService, | |
27 | private authService: AuthService, | |
830b4faf C |
28 | private notifier: Notifier, |
29 | private router: Router, | |
30 | private videoPlaylistService: VideoPlaylistService, | |
66357162 C |
31 | private serverService: ServerService |
32 | ) { | |
830b4faf C |
33 | super() |
34 | } | |
35 | ||
36 | ngOnInit () { | |
37 | this.buildForm({ | |
7ed1edbb C |
38 | displayName: VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR, |
39 | privacy: VIDEO_PLAYLIST_PRIVACY_VALIDATOR, | |
40 | description: VIDEO_PLAYLIST_DESCRIPTION_VALIDATOR, | |
41 | videoChannelId: VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR, | |
830b4faf C |
42 | thumbnailfile: null |
43 | }) | |
44 | ||
978c9d49 | 45 | this.form.get('privacy').valueChanges.subscribe(privacy => { |
7ed1edbb | 46 | setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy) |
978c9d49 C |
47 | }) |
48 | ||
9556ce48 C |
49 | listUserChannels(this.authService) |
50 | .subscribe(channels => this.userVideoChannels = channels) | |
830b4faf | 51 | |
ba430d75 C |
52 | this.serverService.getVideoPlaylistPrivacies() |
53 | .subscribe(videoPlaylistPrivacies => { | |
54 | this.videoPlaylistPrivacies = videoPlaylistPrivacies | |
830b4faf | 55 | |
ba430d75 C |
56 | this.form.patchValue({ |
57 | privacy: VideoPlaylistPrivacy.PRIVATE | |
58 | }) | |
830b4faf | 59 | }) |
830b4faf C |
60 | } |
61 | ||
62 | formValidated () { | |
63 | this.error = undefined | |
64 | ||
65 | const body = this.form.value | |
66 | const videoPlaylistCreate: VideoPlaylistCreate = { | |
978c9d49 | 67 | displayName: body.displayName, |
830b4faf C |
68 | privacy: body.privacy, |
69 | description: body.description || null, | |
70 | videoChannelId: body.videoChannelId || null, | |
71 | thumbnailfile: body.thumbnailfile || null | |
72 | } | |
73 | ||
74 | this.videoPlaylistService.createVideoPlaylist(videoPlaylistCreate).subscribe( | |
75 | () => { | |
66357162 | 76 | this.notifier.success($localize`Playlist ${videoPlaylistCreate.displayName} created.`) |
17119e4a | 77 | this.router.navigate([ '/my-library', 'video-playlists' ]) |
830b4faf C |
78 | }, |
79 | ||
80 | err => this.error = err.message | |
81 | ) | |
82 | } | |
83 | ||
84 | isCreation () { | |
85 | return true | |
86 | } | |
87 | ||
88 | getFormButtonTitle () { | |
66357162 | 89 | return $localize`Create` |
830b4faf C |
90 | } |
91 | } |