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