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