]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - 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
1 import { Component, OnInit } from '@angular/core'
2 import { Router } from '@angular/router'
3 import { AuthService, Notifier } from '@app/core'
4 import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit'
5 import { VideoChannelCreate } from '../../../../../shared/models/videos'
6 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
9 import { VideoChannelValidatorsService } from '@app/shared/forms/form-validators/video-channel-validators.service'
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 })
16 export class MyAccountVideoChannelCreateComponent extends MyAccountVideoChannelEdit implements OnInit {
17 error: string
18
19 constructor (
20 protected formValidatorService: FormValidatorService,
21 private authService: AuthService,
22 private videoChannelValidatorsService: VideoChannelValidatorsService,
23 private notifier: Notifier,
24 private router: Router,
25 private videoChannelService: VideoChannelService,
26 private i18n: I18n
27 ) {
28 super()
29 }
30
31 get instanceHost () {
32 return window.location.host
33 }
34
35 ngOnInit () {
36 this.buildForm({
37 name: this.videoChannelValidatorsService.VIDEO_CHANNEL_NAME,
38 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
39 description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION,
40 support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT
41 })
42 }
43
44 formValidated () {
45 this.error = undefined
46
47 const body = this.form.value
48 const videoChannelCreate: VideoChannelCreate = {
49 name: body.name,
50 displayName: body['display-name'],
51 description: body.description || null,
52 support: body.support || null
53 }
54
55 this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe(
56 () => {
57 this.authService.refreshUserInformation()
58
59 this.notifier.success(
60 this.i18n('Video channel {{videoChannelName}} created.', { videoChannelName: videoChannelCreate.displayName })
61 )
62 this.router.navigate([ '/my-account', 'video-channels' ])
63 },
64
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 }
73 )
74 }
75
76 isCreation () {
77 return true
78 }
79
80 getFormButtonTitle () {
81 return this.i18n('Create')
82 }
83 }