]>
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' |
67ed6552 C |
4 | import { FormValidatorService, VideoChannelValidatorsService } from '@app/shared/shared-forms' |
5 | import { VideoChannelService } from '@app/shared/shared-main' | |
67ed6552 C |
6 | import { VideoChannelCreate } from '@shared/models' |
7 | import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit' | |
08c1efbe C |
8 | |
9 | @Component({ | |
10 | selector: 'my-account-video-channel-create', | |
11 | templateUrl: './my-account-video-channel-edit.component.html', | |
12 | styleUrls: [ './my-account-video-channel-edit.component.scss' ] | |
13 | }) | |
14 | export class MyAccountVideoChannelCreateComponent extends MyAccountVideoChannelEdit implements OnInit { | |
15 | error: string | |
16 | ||
08c1efbe | 17 | constructor ( |
d18d6478 | 18 | protected formValidatorService: FormValidatorService, |
95166f9a | 19 | private authService: AuthService, |
e309822b | 20 | private videoChannelValidatorsService: VideoChannelValidatorsService, |
f8b2c1b4 | 21 | private notifier: Notifier, |
08c1efbe | 22 | private router: Router, |
66357162 C |
23 | private videoChannelService: VideoChannelService |
24 | ) { | |
08c1efbe C |
25 | super() |
26 | } | |
27 | ||
8a19bee1 C |
28 | get instanceHost () { |
29 | return window.location.host | |
30 | } | |
31 | ||
08c1efbe | 32 | ngOnInit () { |
d18d6478 | 33 | this.buildForm({ |
8a19bee1 | 34 | name: this.videoChannelValidatorsService.VIDEO_CHANNEL_NAME, |
e309822b C |
35 | 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME, |
36 | description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION, | |
37 | support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT | |
d18d6478 | 38 | }) |
08c1efbe C |
39 | } |
40 | ||
41 | formValidated () { | |
42 | this.error = undefined | |
43 | ||
44 | const body = this.form.value | |
45 | const videoChannelCreate: VideoChannelCreate = { | |
8a19bee1 | 46 | name: body.name, |
08c1efbe | 47 | displayName: body['display-name'], |
360329cc C |
48 | description: body.description || null, |
49 | support: body.support || null | |
08c1efbe C |
50 | } |
51 | ||
52 | this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe( | |
53 | () => { | |
95166f9a | 54 | this.authService.refreshUserInformation() |
f8b2c1b4 | 55 | |
66357162 | 56 | this.notifier.success($localize`Video channel ${videoChannelCreate.displayName} created.`) |
08c1efbe C |
57 | this.router.navigate([ '/my-account', 'video-channels' ]) |
58 | }, | |
59 | ||
601527d7 C |
60 | err => { |
61 | if (err.status === 409) { | |
66357162 | 62 | this.error = $localize`This name already exists on this instance.` |
601527d7 C |
63 | return |
64 | } | |
65 | ||
66 | this.error = err.message | |
67 | } | |
08c1efbe C |
68 | ) |
69 | } | |
70 | ||
71 | isCreation () { | |
72 | return true | |
73 | } | |
74 | ||
75 | getFormButtonTitle () { | |
66357162 | 76 | return $localize`Create` |
08c1efbe C |
77 | } |
78 | } |