diff options
Diffstat (limited to 'client/src/app/+my-account/+my-account-video-channels/my-account-video-channel-create.component.ts')
-rw-r--r-- | client/src/app/+my-account/+my-account-video-channels/my-account-video-channel-create.component.ts | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/client/src/app/+my-account/+my-account-video-channels/my-account-video-channel-create.component.ts b/client/src/app/+my-account/+my-account-video-channels/my-account-video-channel-create.component.ts new file mode 100644 index 000000000..039c389e4 --- /dev/null +++ b/client/src/app/+my-account/+my-account-video-channels/my-account-video-channel-create.component.ts | |||
@@ -0,0 +1,82 @@ | |||
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 { I18n } from '@ngx-translate/i18n-polyfill' | ||
7 | import { VideoChannelCreate } from '@shared/models' | ||
8 | import { MyAccountVideoChannelEdit } from './my-account-video-channel-edit' | ||
9 | |||
10 | @Component({ | ||
11 | selector: 'my-account-video-channel-create', | ||
12 | templateUrl: './my-account-video-channel-edit.component.html', | ||
13 | styleUrls: [ './my-account-video-channel-edit.component.scss' ] | ||
14 | }) | ||
15 | export class MyAccountVideoChannelCreateComponent extends MyAccountVideoChannelEdit implements OnInit { | ||
16 | error: string | ||
17 | |||
18 | constructor ( | ||
19 | protected formValidatorService: FormValidatorService, | ||
20 | private authService: AuthService, | ||
21 | private videoChannelValidatorsService: VideoChannelValidatorsService, | ||
22 | private notifier: Notifier, | ||
23 | private router: Router, | ||
24 | private videoChannelService: VideoChannelService, | ||
25 | private i18n: I18n | ||
26 | ) { | ||
27 | super() | ||
28 | } | ||
29 | |||
30 | get instanceHost () { | ||
31 | return window.location.host | ||
32 | } | ||
33 | |||
34 | ngOnInit () { | ||
35 | this.buildForm({ | ||
36 | name: this.videoChannelValidatorsService.VIDEO_CHANNEL_NAME, | ||
37 | 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME, | ||
38 | description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION, | ||
39 | support: this.videoChannelValidatorsService.VIDEO_CHANNEL_SUPPORT | ||
40 | }) | ||
41 | } | ||
42 | |||
43 | formValidated () { | ||
44 | this.error = undefined | ||
45 | |||
46 | const body = this.form.value | ||
47 | const videoChannelCreate: VideoChannelCreate = { | ||
48 | name: body.name, | ||
49 | displayName: body['display-name'], | ||
50 | description: body.description || null, | ||
51 | support: body.support || null | ||
52 | } | ||
53 | |||
54 | this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe( | ||
55 | () => { | ||
56 | this.authService.refreshUserInformation() | ||
57 | |||
58 | this.notifier.success( | ||
59 | this.i18n('Video channel {{videoChannelName}} created.', { videoChannelName: videoChannelCreate.displayName }) | ||
60 | ) | ||
61 | this.router.navigate([ '/my-account', 'video-channels' ]) | ||
62 | }, | ||
63 | |||
64 | err => { | ||
65 | if (err.status === 409) { | ||
66 | this.error = this.i18n('This name already exists on this instance.') | ||
67 | return | ||
68 | } | ||
69 | |||
70 | this.error = err.message | ||
71 | } | ||
72 | ) | ||
73 | } | ||
74 | |||
75 | isCreation () { | ||
76 | return true | ||
77 | } | ||
78 | |||
79 | getFormButtonTitle () { | ||
80 | return this.i18n('Create') | ||
81 | } | ||
82 | } | ||