]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnInit } from '@angular/core' | |
2 | import { Router } from '@angular/router' | |
3 | import { AuthService, Notifier } from '@app/core' | |
4 | import { FormValidatorService, VideoChannelValidatorsService } from '@app/shared/shared-forms' | |
5 | import { VideoChannelService } from '@app/shared/shared-main' | |
6 | import { VideoChannelCreate } from '@shared/models' | |
7 | import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit' | |
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 | ||
17 | constructor ( | |
18 | protected formValidatorService: FormValidatorService, | |
19 | private authService: AuthService, | |
20 | private videoChannelValidatorsService: VideoChannelValidatorsService, | |
21 | private notifier: Notifier, | |
22 | private router: Router, | |
23 | private videoChannelService: VideoChannelService | |
24 | ) { | |
25 | super() | |
26 | } | |
27 | ||
28 | get instanceHost () { | |
29 | return window.location.host | |
30 | } | |
31 | ||
32 | ngOnInit () { | |
33 | this.buildForm({ | |
34 | name: this.videoChannelValidatorsService.VIDEO_CHANNEL_NAME, | |
35 | 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME, | |
36 | description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION, | |
37 | support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT | |
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-account', '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 | } |