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