]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts
register: hide channel step if upload quota is 0
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / +my-video-channels / my-video-channel-create.component.ts
CommitLineData
08c1efbe
C
1import { Component, OnInit } from '@angular/core'
2import { Router } from '@angular/router'
f8b2c1b4 3import { AuthService, Notifier } from '@app/core'
7ed1edbb
C
4import {
5 VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
6 VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
7 VIDEO_CHANNEL_NAME_VALIDATOR,
8 VIDEO_CHANNEL_SUPPORT_VALIDATOR
9} from '@app/shared/form-validators/video-channel-validators'
10import { FormValidatorService } from '@app/shared/shared-forms'
67ed6552 11import { VideoChannelService } from '@app/shared/shared-main'
67ed6552 12import { VideoChannelCreate } from '@shared/models'
17119e4a 13import { MyVideoChannelEdit } from './my-video-channel-edit'
08c1efbe
C
14
15@Component({
17119e4a
C
16 templateUrl: './my-video-channel-edit.component.html',
17 styleUrls: [ './my-video-channel-edit.component.scss' ]
08c1efbe 18})
17119e4a 19export class MyVideoChannelCreateComponent extends MyVideoChannelEdit implements OnInit {
08c1efbe
C
20 error: string
21
08c1efbe 22 constructor (
d18d6478 23 protected formValidatorService: FormValidatorService,
95166f9a 24 private authService: AuthService,
f8b2c1b4 25 private notifier: Notifier,
08c1efbe 26 private router: Router,
66357162
C
27 private videoChannelService: VideoChannelService
28 ) {
08c1efbe
C
29 super()
30 }
31
08c1efbe 32 ngOnInit () {
d18d6478 33 this.buildForm({
7ed1edbb
C
34 name: VIDEO_CHANNEL_NAME_VALIDATOR,
35 'display-name': VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
36 description: VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
37 support: VIDEO_CHANNEL_SUPPORT_VALIDATOR
d18d6478 38 })
08c1efbe
C
39 }
40
41 formValidated () {
42 this.error = undefined
43
44 const body = this.form.value
45 const videoChannelCreate: VideoChannelCreate = {
8a19bee1 46 name: body.name,
08c1efbe 47 displayName: body['display-name'],
360329cc
C
48 description: body.description || null,
49 support: body.support || null
08c1efbe
C
50 }
51
52 this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe(
53 () => {
95166f9a 54 this.authService.refreshUserInformation()
f8b2c1b4 55
66357162 56 this.notifier.success($localize`Video channel ${videoChannelCreate.displayName} created.`)
17119e4a 57 this.router.navigate([ '/my-library', 'video-channels' ])
08c1efbe
C
58 },
59
601527d7
C
60 err => {
61 if (err.status === 409) {
66357162 62 this.error = $localize`This name already exists on this instance.`
601527d7
C
63 return
64 }
65
66 this.error = err.message
67 }
08c1efbe
C
68 )
69 }
70
71 isCreation () {
72 return true
73 }
74
75 getFormButtonTitle () {
66357162 76 return $localize`Create`
08c1efbe
C
77 }
78}