aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts')
-rw-r--r--client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts78
1 files changed, 78 insertions, 0 deletions
diff --git a/client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts b/client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts
new file mode 100644
index 000000000..1d0cbf246
--- /dev/null
+++ b/client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts
@@ -0,0 +1,78 @@
1import { Component, OnInit } from '@angular/core'
2import { Router } from '@angular/router'
3import { AuthService, Notifier } from '@app/core'
4import {
5 VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
6 VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
7 VIDEO_CHANNEL_NAME_VALIDATOR,
8 VIDEO_CHANNEL_SUPPORT_VALIDATOR
9} from '@app/shared/form-validators/video-channel-validators'
10import { FormValidatorService } from '@app/shared/shared-forms'
11import { VideoChannelService } from '@app/shared/shared-main'
12import { VideoChannelCreate } from '@shared/models'
13import { MyVideoChannelEdit } from './my-video-channel-edit'
14
15@Component({
16 templateUrl: './my-video-channel-edit.component.html',
17 styleUrls: [ './my-video-channel-edit.component.scss' ]
18})
19export class MyVideoChannelCreateComponent extends MyVideoChannelEdit implements OnInit {
20 error: string
21
22 constructor (
23 protected formValidatorService: FormValidatorService,
24 private authService: AuthService,
25 private notifier: Notifier,
26 private router: Router,
27 private videoChannelService: VideoChannelService
28 ) {
29 super()
30 }
31
32 ngOnInit () {
33 this.buildForm({
34 name: VIDEO_CHANNEL_NAME_VALIDATOR,
35 'display-name': VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
36 description: VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
37 support: VIDEO_CHANNEL_SUPPORT_VALIDATOR
38 })
39 }
40
41 formValidated () {
42 this.error = undefined
43
44 const body = this.form.value
45 const videoChannelCreate: VideoChannelCreate = {
46 name: body.name,
47 displayName: body['display-name'],
48 description: body.description || null,
49 support: body.support || null
50 }
51
52 this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe(
53 () => {
54 this.authService.refreshUserInformation()
55
56 this.notifier.success($localize`Video channel ${videoChannelCreate.displayName} created.`)
57 this.router.navigate([ '/my-library', 'video-channels' ])
58 },
59
60 err => {
61 if (err.status === 409) {
62 this.error = $localize`This name already exists on this instance.`
63 return
64 }
65
66 this.error = err.message
67 }
68 )
69 }
70
71 isCreation () {
72 return true
73 }
74
75 getFormButtonTitle () {
76 return $localize`Create`
77 }
78}