aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+my-account/my-account-video-channels/my-account-video-channel-create.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-05-09 09:26:41 +0200
committerChocobozzz <me@florianbigard.com>2018-05-09 09:32:26 +0200
commit62e62f118d5da57acd3494fece2e8ed357564ffe (patch)
treeff5b7c6ec5708d71a76a2eb5744d810015ae29a5 /client/src/app/+my-account/my-account-video-channels/my-account-video-channel-create.component.ts
parent1952a538baa330b13bd11631b3975f7ef1c37e70 (diff)
downloadPeerTube-62e62f118d5da57acd3494fece2e8ed357564ffe.tar.gz
PeerTube-62e62f118d5da57acd3494fece2e8ed357564ffe.tar.zst
PeerTube-62e62f118d5da57acd3494fece2e8ed357564ffe.zip
Load my-account module lazily
Diffstat (limited to 'client/src/app/+my-account/my-account-video-channels/my-account-video-channel-create.component.ts')
-rw-r--r--client/src/app/+my-account/my-account-video-channels/my-account-video-channel-create.component.ts89
1 files changed, 89 insertions, 0 deletions
diff --git a/client/src/app/+my-account/my-account-video-channels/my-account-video-channel-create.component.ts b/client/src/app/+my-account/my-account-video-channels/my-account-video-channel-create.component.ts
new file mode 100644
index 000000000..0f03548ad
--- /dev/null
+++ b/client/src/app/+my-account/my-account-video-channels/my-account-video-channel-create.component.ts
@@ -0,0 +1,89 @@
1import { Component, OnInit } from '@angular/core'
2import { Router } from '@angular/router'
3import { NotificationsService } from 'angular2-notifications'
4import 'rxjs/add/observable/from'
5import 'rxjs/add/operator/concatAll'
6import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit'
7import { FormBuilder, FormGroup } from '@angular/forms'
8import { VideoChannelCreate } from '../../../../../shared/models/videos'
9import {
10 VIDEO_CHANNEL_DESCRIPTION,
11 VIDEO_CHANNEL_DISPLAY_NAME,
12 VIDEO_CHANNEL_SUPPORT
13} from '@app/shared/forms/form-validators/video-channel'
14import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
15import { AuthService } from '@app/core'
16
17@Component({
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' ]
21})
22export class MyAccountVideoChannelCreateComponent extends MyAccountVideoChannelEdit implements OnInit {
23 error: string
24
25 form: FormGroup
26 formErrors = {
27 'display-name': '',
28 'description': '',
29 'support': ''
30 }
31 validationMessages = {
32 'display-name': VIDEO_CHANNEL_DISPLAY_NAME.MESSAGES,
33 'description': VIDEO_CHANNEL_DESCRIPTION.MESSAGES,
34 'support': VIDEO_CHANNEL_SUPPORT.MESSAGES
35 }
36
37 constructor (
38 private authService: AuthService,
39 private notificationsService: NotificationsService,
40 private router: Router,
41 private formBuilder: FormBuilder,
42 private videoChannelService: VideoChannelService
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'],
67 description: body.description || undefined,
68 support: body.support || undefined
69 }
70
71 this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe(
72 () => {
73 this.authService.refreshUserInformation()
74 this.notificationsService.success('Success', `Video channel ${videoChannelCreate.displayName} created.`)
75 this.router.navigate([ '/my-account', 'video-channels' ])
76 },
77
78 err => this.error = err.message
79 )
80 }
81
82 isCreation () {
83 return true
84 }
85
86 getFormButtonTitle () {
87 return 'Create'
88 }
89}