diff options
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.ts | 89 |
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 @@ | |||
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' | ||
9 | import { | ||
10 | VIDEO_CHANNEL_DESCRIPTION, | ||
11 | VIDEO_CHANNEL_DISPLAY_NAME, | ||
12 | VIDEO_CHANNEL_SUPPORT | ||
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' | ||
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 | }) | ||
22 | export 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 | } | ||