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