]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/account/account-settings/account-details/account-details.component.ts
b8c19d8d608774f348529413dc07003ec96138a5
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account-settings / account-details / account-details.component.ts
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
8 @Component({
9 selector: 'my-account-details',
10 templateUrl: './account-details.component.html',
11 styleUrls: [ './account-details.component.scss' ]
12 })
13
14 export class AccountDetailsComponent extends FormReactive implements OnInit {
15 @Input() user: User = null
16
17 error: string = null
18
19 form: FormGroup
20 formErrors = {}
21 validationMessages = {}
22
23 constructor (
24 private authService: AuthService,
25 private formBuilder: FormBuilder,
26 private notificationsService: NotificationsService,
27 private userService: UserService
28 ) {
29 super()
30 }
31
32 buildForm () {
33 this.form = this.formBuilder.group({
34 displayNSFW: [ this.user.displayNSFW ],
35 autoPlayVideo: [ this.user.autoPlayVideo ]
36 })
37
38 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
39 }
40
41 ngOnInit () {
42 this.buildForm()
43 }
44
45 updateDetails () {
46 const displayNSFW = this.form.value['displayNSFW']
47 const autoPlayVideo = this.form.value['autoPlayVideo']
48 const details: UserUpdateMe = {
49 displayNSFW,
50 autoPlayVideo
51 }
52
53 this.error = null
54 this.userService.updateMyDetails(details).subscribe(
55 () => {
56 this.notificationsService.success('Success', 'Information updated.')
57
58 this.authService.refreshUserInformation()
59 },
60
61 err => this.error = err.message
62 )
63 }
64 }