]>
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' | |
66357162 | 4 | import { populateAsyncUserVideoChannels } 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' |
67ed6552 | 16 | import { MyAccountVideoPlaylistEdit } from './my-account-video-playlist-edit' |
830b4faf C |
17 | |
18 | @Component({ | |
19 | selector: 'my-account-video-playlist-create', | |
20 | templateUrl: './my-account-video-playlist-edit.component.html', | |
21 | styleUrls: [ './my-account-video-playlist-edit.component.scss' ] | |
22 | }) | |
23 | export class MyAccountVideoPlaylistCreateComponent extends MyAccountVideoPlaylistEdit implements OnInit { | |
24 | error: string | |
830b4faf C |
25 | |
26 | constructor ( | |
27 | protected formValidatorService: FormValidatorService, | |
28 | private authService: AuthService, | |
830b4faf C |
29 | private notifier: Notifier, |
30 | private router: Router, | |
31 | private videoPlaylistService: VideoPlaylistService, | |
66357162 C |
32 | private serverService: ServerService |
33 | ) { | |
830b4faf C |
34 | super() |
35 | } | |
36 | ||
37 | ngOnInit () { | |
38 | this.buildForm({ | |
7ed1edbb C |
39 | displayName: VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR, |
40 | privacy: VIDEO_PLAYLIST_PRIVACY_VALIDATOR, | |
41 | description: VIDEO_PLAYLIST_DESCRIPTION_VALIDATOR, | |
42 | videoChannelId: VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR, | |
830b4faf C |
43 | thumbnailfile: null |
44 | }) | |
45 | ||
978c9d49 | 46 | this.form.get('privacy').valueChanges.subscribe(privacy => { |
7ed1edbb | 47 | setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy) |
978c9d49 C |
48 | }) |
49 | ||
830b4faf | 50 | populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) |
851f5daa | 51 | .catch(err => console.error('Cannot populate user video channels.', err)) |
830b4faf | 52 | |
ba430d75 C |
53 | this.serverService.getVideoPlaylistPrivacies() |
54 | .subscribe(videoPlaylistPrivacies => { | |
55 | this.videoPlaylistPrivacies = videoPlaylistPrivacies | |
830b4faf | 56 | |
ba430d75 C |
57 | this.form.patchValue({ |
58 | privacy: VideoPlaylistPrivacy.PRIVATE | |
59 | }) | |
830b4faf | 60 | }) |
830b4faf C |
61 | } |
62 | ||
63 | formValidated () { | |
64 | this.error = undefined | |
65 | ||
66 | const body = this.form.value | |
67 | const videoPlaylistCreate: VideoPlaylistCreate = { | |
978c9d49 | 68 | displayName: body.displayName, |
830b4faf C |
69 | privacy: body.privacy, |
70 | description: body.description || null, | |
71 | videoChannelId: body.videoChannelId || null, | |
72 | thumbnailfile: body.thumbnailfile || null | |
73 | } | |
74 | ||
75 | this.videoPlaylistService.createVideoPlaylist(videoPlaylistCreate).subscribe( | |
76 | () => { | |
66357162 | 77 | this.notifier.success($localize`Playlist ${videoPlaylistCreate.displayName} created.`) |
830b4faf C |
78 | this.router.navigate([ '/my-account', 'video-playlists' ]) |
79 | }, | |
80 | ||
81 | err => this.error = err.message | |
82 | ) | |
83 | } | |
84 | ||
85 | isCreation () { | |
86 | return true | |
87 | } | |
88 | ||
89 | getFormButtonTitle () { | |
66357162 | 90 | return $localize`Create` |
830b4faf C |
91 | } |
92 | } |