]> 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
Fix i18n in components
[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'
3import { NotificationsService } from 'angular2-notifications'
08c1efbe
C
4import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit'
5import { FormBuilder, FormGroup } from '@angular/forms'
6import { VideoChannelCreate } from '../../../../../shared/models/videos'
7import {
8 VIDEO_CHANNEL_DESCRIPTION,
9 VIDEO_CHANNEL_DISPLAY_NAME,
10 VIDEO_CHANNEL_SUPPORT
11} from '@app/shared/forms/form-validators/video-channel'
12import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
95166f9a 13import { AuthService } from '@app/core'
b1d40cff 14import { I18n } from '@ngx-translate/i18n-polyfill'
08c1efbe
C
15
16@Component({
17 selector: 'my-account-video-channel-create',
18 templateUrl: './my-account-video-channel-edit.component.html',
19 styleUrls: [ './my-account-video-channel-edit.component.scss' ]
20})
21export class MyAccountVideoChannelCreateComponent extends MyAccountVideoChannelEdit implements OnInit {
22 error: string
23
24 form: FormGroup
25 formErrors = {
26 'display-name': '',
27 'description': '',
28 'support': ''
29 }
30 validationMessages = {
31 'display-name': VIDEO_CHANNEL_DISPLAY_NAME.MESSAGES,
32 'description': VIDEO_CHANNEL_DESCRIPTION.MESSAGES,
33 'support': VIDEO_CHANNEL_SUPPORT.MESSAGES
34 }
35
36 constructor (
95166f9a 37 private authService: AuthService,
08c1efbe
C
38 private notificationsService: NotificationsService,
39 private router: Router,
40 private formBuilder: FormBuilder,
b1d40cff
C
41 private videoChannelService: VideoChannelService,
42 private i18n: I18n
08c1efbe
C
43 ) {
44 super()
45 }
46
47 buildForm () {
48 this.form = this.formBuilder.group({
49 'display-name': [ '', VIDEO_CHANNEL_DISPLAY_NAME.VALIDATORS ],
50 description: [ '', VIDEO_CHANNEL_DESCRIPTION.VALIDATORS ],
51 support: [ '', VIDEO_CHANNEL_SUPPORT.VALIDATORS ]
52 })
53
54 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
55 }
56
57 ngOnInit () {
58 this.buildForm()
59 }
60
61 formValidated () {
62 this.error = undefined
63
64 const body = this.form.value
65 const videoChannelCreate: VideoChannelCreate = {
66 displayName: body['display-name'],
360329cc
C
67 description: body.description || null,
68 support: body.support || null
08c1efbe
C
69 }
70
71 this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe(
72 () => {
95166f9a 73 this.authService.refreshUserInformation()
b1d40cff
C
74 this.notificationsService.success(
75 this.i18n('Success'),
25acef90 76 this.i18n('Video channel {{videoChannelName}} created.', { videoChannelName: videoChannelCreate.displayName })
b1d40cff 77 )
08c1efbe
C
78 this.router.navigate([ '/my-account', 'video-channels' ])
79 },
80
81 err => this.error = err.message
82 )
83 }
84
85 isCreation () {
86 return true
87 }
88
89 getFormButtonTitle () {
b1d40cff 90 return this.i18n('Create')
08c1efbe
C
91 }
92}