Merge pull request #1105 from BO41/unused-imports
[oweals/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 { NotificationsService } from 'angular2-notifications'
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 { AuthService } from '@app/core'
8 import { I18n } from '@ngx-translate/i18n-polyfill'
9 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
10 import { VideoChannelValidatorsService } from '@app/shared/forms/form-validators/video-channel-validators.service'
11
12 @Component({
13   selector: 'my-account-video-channel-create',
14   templateUrl: './my-account-video-channel-edit.component.html',
15   styleUrls: [ './my-account-video-channel-edit.component.scss' ]
16 })
17 export class MyAccountVideoChannelCreateComponent extends MyAccountVideoChannelEdit implements OnInit {
18   error: string
19
20   constructor (
21     protected formValidatorService: FormValidatorService,
22     private authService: AuthService,
23     private videoChannelValidatorsService: VideoChannelValidatorsService,
24     private notificationsService: NotificationsService,
25     private router: Router,
26     private videoChannelService: VideoChannelService,
27     private i18n: I18n
28   ) {
29     super()
30   }
31
32   get instanceHost () {
33     return window.location.host
34   }
35
36   ngOnInit () {
37     this.buildForm({
38       name: this.videoChannelValidatorsService.VIDEO_CHANNEL_NAME,
39       'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
40       description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION,
41       support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT
42     })
43   }
44
45   formValidated () {
46     this.error = undefined
47
48     const body = this.form.value
49     const videoChannelCreate: VideoChannelCreate = {
50       name: body.name,
51       displayName: body['display-name'],
52       description: body.description || null,
53       support: body.support || null
54     }
55
56     this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe(
57       () => {
58         this.authService.refreshUserInformation()
59         this.notificationsService.success(
60           this.i18n('Success'),
61           this.i18n('Video channel {{videoChannelName}} created.', { videoChannelName: videoChannelCreate.displayName })
62         )
63         this.router.navigate([ '/my-account', 'video-channels' ])
64       },
65
66       err => this.error = err.message
67     )
68   }
69
70   isCreation () {
71     return true
72   }
73
74   getFormButtonTitle () {
75     return this.i18n('Create')
76   }
77 }