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