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