]>
Commit | Line | Data |
---|---|---|
08c1efbe C |
1 | import { Component, OnInit } from '@angular/core' |
2 | import { Router } from '@angular/router' | |
f8b2c1b4 | 3 | import { AuthService, Notifier } from '@app/core' |
7ed1edbb C |
4 | import { |
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' | |
10 | import { FormValidatorService } from '@app/shared/shared-forms' | |
67ed6552 | 11 | import { VideoChannelService } from '@app/shared/shared-main' |
67ed6552 | 12 | import { VideoChannelCreate } from '@shared/models' |
f2eb23cd | 13 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' |
17119e4a | 14 | import { MyVideoChannelEdit } from './my-video-channel-edit' |
08c1efbe C |
15 | |
16 | @Component({ | |
17119e4a C |
17 | templateUrl: './my-video-channel-edit.component.html', |
18 | styleUrls: [ './my-video-channel-edit.component.scss' ] | |
08c1efbe | 19 | }) |
17119e4a | 20 | export class MyVideoChannelCreateComponent extends MyVideoChannelEdit implements OnInit { |
08c1efbe C |
21 | error: string |
22 | ||
08c1efbe | 23 | constructor ( |
d18d6478 | 24 | protected formValidatorService: FormValidatorService, |
95166f9a | 25 | private authService: AuthService, |
f8b2c1b4 | 26 | private notifier: Notifier, |
08c1efbe | 27 | private router: Router, |
66357162 C |
28 | private videoChannelService: VideoChannelService |
29 | ) { | |
08c1efbe C |
30 | super() |
31 | } | |
32 | ||
08c1efbe | 33 | ngOnInit () { |
d18d6478 | 34 | this.buildForm({ |
7ed1edbb C |
35 | name: VIDEO_CHANNEL_NAME_VALIDATOR, |
36 | 'display-name': VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR, | |
37 | description: VIDEO_CHANNEL_DESCRIPTION_VALIDATOR, | |
38 | support: VIDEO_CHANNEL_SUPPORT_VALIDATOR | |
d18d6478 | 39 | }) |
08c1efbe C |
40 | } |
41 | ||
42 | formValidated () { | |
43 | this.error = undefined | |
44 | ||
45 | const body = this.form.value | |
46 | const videoChannelCreate: VideoChannelCreate = { | |
8a19bee1 | 47 | name: body.name, |
08c1efbe | 48 | displayName: body['display-name'], |
360329cc C |
49 | description: body.description || null, |
50 | support: body.support || null | |
08c1efbe C |
51 | } |
52 | ||
53 | this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe( | |
54 | () => { | |
95166f9a | 55 | this.authService.refreshUserInformation() |
f8b2c1b4 | 56 | |
66357162 | 57 | this.notifier.success($localize`Video channel ${videoChannelCreate.displayName} created.`) |
17119e4a | 58 | this.router.navigate([ '/my-library', 'video-channels' ]) |
08c1efbe C |
59 | }, |
60 | ||
601527d7 | 61 | err => { |
f2eb23cd | 62 | if (err.status === HttpStatusCode.CONFLICT_409) { |
66357162 | 63 | this.error = $localize`This name already exists on this instance.` |
601527d7 C |
64 | return |
65 | } | |
66 | ||
67 | this.error = err.message | |
68 | } | |
08c1efbe C |
69 | ) |
70 | } | |
71 | ||
72 | isCreation () { | |
73 | return true | |
74 | } | |
75 | ||
76 | getFormButtonTitle () { | |
66357162 | 77 | return $localize`Create` |
08c1efbe C |
78 | } |
79 | } |