]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/account/account-details/account-details.component.ts
547f045c4c6fce9e59a92691cf0501da7e03acaf
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account-details / account-details.component.ts
1 import { Component, OnInit, Input } from '@angular/core'
2 import { FormBuilder, FormGroup } from '@angular/forms'
3 import { Router } from '@angular/router'
4
5 import { NotificationsService } from 'angular2-notifications'
6
7 import { AuthService } from '../../core'
8 import {
9 FormReactive,
10 User,
11 UserService,
12 USER_PASSWORD
13 } from '../../shared'
14 import { UserUpdate } from '../../../../../shared'
15
16 @Component({
17 selector: 'my-account-details',
18 templateUrl: './account-details.component.html'
19 })
20
21 export class AccountDetailsComponent extends FormReactive implements OnInit {
22 @Input() user: User = null
23
24 error: string = null
25
26 form: FormGroup
27 formErrors = {}
28 validationMessages = {}
29
30 constructor (
31 private authService: AuthService,
32 private formBuilder: FormBuilder,
33 private router: Router,
34 private notificationsService: NotificationsService,
35 private userService: UserService
36 ) {
37 super()
38 }
39
40 buildForm () {
41 this.form = this.formBuilder.group({
42 displayNSFW: [ this.user.displayNSFW ]
43 })
44
45 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
46 }
47
48 ngOnInit () {
49 this.buildForm()
50 }
51
52 updateDetails () {
53 const displayNSFW = this.form.value['displayNSFW']
54 const details: UserUpdate = {
55 displayNSFW
56 }
57
58 this.error = null
59 this.userService.updateDetails(details).subscribe(
60 () => {
61 this.notificationsService.success('Success', 'Informations updated.')
62
63 this.authService.refreshUserInformations()
64 },
65
66 err => this.error = err
67 )
68 }
69 }