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'
10 selector: 'my-account-video-settings',
11 templateUrl: './my-account-video-settings.component.html',
12 styleUrls: [ './my-account-video-settings.component.scss' ]
14 export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit {
15 @Input() user: User = null
19 validationMessages = {}
22 private authService: AuthService,
23 private formBuilder: FormBuilder,
24 private notificationsService: NotificationsService,
25 private userService: UserService,
32 this.form = this.formBuilder.group({
33 nsfwPolicy: [ this.user.nsfwPolicy ],
34 autoPlayVideo: [ this.user.autoPlayVideo ]
37 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
45 const nsfwPolicy = this.form.value['nsfwPolicy']
46 const autoPlayVideo = this.form.value['autoPlayVideo']
47 const details: UserUpdateMe = {
52 this.userService.updateMyProfile(details).subscribe(
54 this.notificationsService.success(this.i18n('Success'), this.i18n('Information updated.'))
56 this.authService.refreshUserInformation()
59 err => this.notificationsService.error(this.i18n('Error'), err.message)