]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-video-channels/my-account-video-channel-create.component.ts
Refractor notification service
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-video-channels / my-account-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'
08c1efbe 4import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit'
08c1efbe 5import { VideoChannelCreate } from '../../../../../shared/models/videos'
08c1efbe 6import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
b1d40cff 7import { I18n } from '@ngx-translate/i18n-polyfill'
d18d6478 8import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
e309822b 9import { VideoChannelValidatorsService } from '@app/shared/forms/form-validators/video-channel-validators.service'
08c1efbe
C
10
11@Component({
12 selector: 'my-account-video-channel-create',
13 templateUrl: './my-account-video-channel-edit.component.html',
14 styleUrls: [ './my-account-video-channel-edit.component.scss' ]
15})
16export class MyAccountVideoChannelCreateComponent extends MyAccountVideoChannelEdit implements OnInit {
17 error: string
18
08c1efbe 19 constructor (
d18d6478 20 protected formValidatorService: FormValidatorService,
95166f9a 21 private authService: AuthService,
e309822b 22 private videoChannelValidatorsService: VideoChannelValidatorsService,
f8b2c1b4 23 private notifier: Notifier,
08c1efbe 24 private router: Router,
b1d40cff
C
25 private videoChannelService: VideoChannelService,
26 private i18n: I18n
08c1efbe
C
27 ) {
28 super()
29 }
30
8a19bee1
C
31 get instanceHost () {
32 return window.location.host
33 }
34
08c1efbe 35 ngOnInit () {
d18d6478 36 this.buildForm({
8a19bee1 37 name: this.videoChannelValidatorsService.VIDEO_CHANNEL_NAME,
e309822b
C
38 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
39 description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION,
40 support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT
d18d6478 41 })
08c1efbe
C
42 }
43
44 formValidated () {
45 this.error = undefined
46
47 const body = this.form.value
48 const videoChannelCreate: VideoChannelCreate = {
8a19bee1 49 name: body.name,
08c1efbe 50 displayName: body['display-name'],
360329cc
C
51 description: body.description || null,
52 support: body.support || null
08c1efbe
C
53 }
54
55 this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe(
56 () => {
95166f9a 57 this.authService.refreshUserInformation()
f8b2c1b4
C
58
59 this.notifier.success(
25acef90 60 this.i18n('Video channel {{videoChannelName}} created.', { videoChannelName: videoChannelCreate.displayName })
b1d40cff 61 )
08c1efbe
C
62 this.router.navigate([ '/my-account', 'video-channels' ])
63 },
64
601527d7
C
65 err => {
66 if (err.status === 409) {
67 this.error = this.i18n('This name already exists on this instance.')
68 return
69 }
70
71 this.error = err.message
72 }
08c1efbe
C
73 )
74 }
75
76 isCreation () {
77 return true
78 }
79
80 getFormButtonTitle () {
b1d40cff 81 return this.i18n('Create')
08c1efbe
C
82 }
83}