1 import { Component, OnInit } from '@angular/core'
2 import { Router } from '@angular/router'
3 import { NotificationsService } from 'angular2-notifications'
4 import 'rxjs/add/observable/from'
5 import 'rxjs/add/operator/concatAll'
6 import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit'
7 import { FormBuilder, FormGroup } from '@angular/forms'
8 import { VideoChannelCreate } from '../../../../../shared/models/videos'
10 VIDEO_CHANNEL_DESCRIPTION,
11 VIDEO_CHANNEL_DISPLAY_NAME,
13 } from '@app/shared/forms/form-validators/video-channel'
14 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
15 import { AuthService } from '@app/core'
18 selector: 'my-account-video-channel-create',
19 templateUrl: './my-account-video-channel-edit.component.html',
20 styleUrls: [ './my-account-video-channel-edit.component.scss' ]
22 export class MyAccountVideoChannelCreateComponent extends MyAccountVideoChannelEdit implements OnInit {
31 validationMessages = {
32 'display-name': VIDEO_CHANNEL_DISPLAY_NAME.MESSAGES,
33 'description': VIDEO_CHANNEL_DESCRIPTION.MESSAGES,
34 'support': VIDEO_CHANNEL_SUPPORT.MESSAGES
38 private authService: AuthService,
39 private notificationsService: NotificationsService,
40 private router: Router,
41 private formBuilder: FormBuilder,
42 private videoChannelService: VideoChannelService
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 ]
54 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
62 this.error = undefined
64 const body = this.form.value
65 const videoChannelCreate: VideoChannelCreate = {
66 displayName: body['display-name'],
67 description: body.description || undefined,
68 support: body.support || undefined
71 this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe(
73 this.authService.refreshUserInformation()
74 this.notificationsService.success('Success', `Video channel ${videoChannelCreate.displayName} created.`)
75 this.router.navigate([ '/my-account', 'video-channels' ])
78 err => this.error = err.message
86 getFormButtonTitle () {