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'
9 selector: 'my-account-video-settings',
10 templateUrl: './my-account-video-settings.component.html',
11 styleUrls: [ './my-account-video-settings.component.scss' ]
13 export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit {
14 @Input() user: User = null
18 validationMessages = {}
21 private authService: AuthService,
22 private formBuilder: FormBuilder,
23 private notificationsService: NotificationsService,
24 private userService: UserService
30 this.form = this.formBuilder.group({
31 nsfwPolicy: [ this.user.nsfwPolicy ],
32 autoPlayVideo: [ this.user.autoPlayVideo ]
35 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
43 const nsfwPolicy = this.form.value['nsfwPolicy']
44 const autoPlayVideo = this.form.value['autoPlayVideo']
45 const details: UserUpdateMe = {
50 this.userService.updateMyProfile(details).subscribe(
52 this.notificationsService.success('Success', 'Information updated.')
54 this.authService.refreshUserInformation()
57 err => this.notificationsService.error('Error', err.message)