]>
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 C |
12 | import { VideoChannelCreate } from '@shared/models' |
13 | import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit' | |
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 | ||
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 | ||
8a19bee1 C |
33 | get instanceHost () { |
34 | return window.location.host | |
35 | } | |
36 | ||
08c1efbe | 37 | ngOnInit () { |
d18d6478 | 38 | this.buildForm({ |
7ed1edbb C |
39 | name: VIDEO_CHANNEL_NAME_VALIDATOR, |
40 | 'display-name': VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR, | |
41 | description: VIDEO_CHANNEL_DESCRIPTION_VALIDATOR, | |
42 | support: VIDEO_CHANNEL_SUPPORT_VALIDATOR | |
d18d6478 | 43 | }) |
08c1efbe C |
44 | } |
45 | ||
46 | formValidated () { | |
47 | this.error = undefined | |
48 | ||
49 | const body = this.form.value | |
50 | const videoChannelCreate: VideoChannelCreate = { | |
8a19bee1 | 51 | name: body.name, |
08c1efbe | 52 | displayName: body['display-name'], |
360329cc C |
53 | description: body.description || null, |
54 | support: body.support || null | |
08c1efbe C |
55 | } |
56 | ||
57 | this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe( | |
58 | () => { | |
95166f9a | 59 | this.authService.refreshUserInformation() |
f8b2c1b4 | 60 | |
66357162 | 61 | this.notifier.success($localize`Video channel ${videoChannelCreate.displayName} created.`) |
08c1efbe C |
62 | this.router.navigate([ '/my-account', 'video-channels' ]) |
63 | }, | |
64 | ||
601527d7 C |
65 | err => { |
66 | if (err.status === 409) { | |
66357162 | 67 | this.error = $localize`This name already exists on this instance.` |
601527d7 C |
68 | return |
69 | } | |
70 | ||
71 | this.error = err.message | |
72 | } | |
08c1efbe C |
73 | ) |
74 | } | |
75 | ||
76 | isCreation () { | |
77 | return true | |
78 | } | |
79 | ||
80 | getFormButtonTitle () { | |
66357162 | 81 | return $localize`Create` |
08c1efbe C |
82 | } |
83 | } |