]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob
4588f73db46ff5069b930790ad008fcde572f781
[github/Chocobozzz/PeerTube.git] /
1 import { Component, Input, OnInit } from '@angular/core'
2 import { FormBuilder, FormGroup } from '@angular/forms'
3 import { NotificationsService } from 'angular2-notifications'
4 import { UserUpdateMe } from '../../../../../../shared'
5 import { AuthService } from '../../../core'
6 import { FormReactive, User, UserService } from '../../../shared'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8
9 @Component({
10 selector: 'my-account-video-settings',
11 templateUrl: './my-account-video-settings.component.html',
12 styleUrls: [ './my-account-video-settings.component.scss' ]
13 })
14 export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit {
15 @Input() user: User = null
16
17 form: FormGroup
18 formErrors = {}
19 validationMessages = {}
20
21 constructor (
22 private authService: AuthService,
23 private formBuilder: FormBuilder,
24 private notificationsService: NotificationsService,
25 private userService: UserService,
26 private i18n: I18n
27 ) {
28 super()
29 }
30
31 buildForm () {
32 this.form = this.formBuilder.group({
33 nsfwPolicy: [ this.user.nsfwPolicy ],
34 autoPlayVideo: [ this.user.autoPlayVideo ]
35 })
36
37 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
38 }
39
40 ngOnInit () {
41 this.buildForm()
42 }
43
44 updateDetails () {
45 const nsfwPolicy = this.form.value['nsfwPolicy']
46 const autoPlayVideo = this.form.value['autoPlayVideo']
47 const details: UserUpdateMe = {
48 nsfwPolicy,
49 autoPlayVideo
50 }
51
52 this.userService.updateMyProfile(details).subscribe(
53 () => {
54 this.notificationsService.success(this.i18n('Success'), this.i18n('Information updated.'))
55
56 this.authService.refreshUserInformation()
57 },
58
59 err => this.notificationsService.error(this.i18n('Error'), err.message)
60 )
61 }
62 }