]>
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' |
8094a898 | 14 | import { UserUpdateMe } from '../../../../../shared' |
af5e743b C |
15 | |
16 | @Component({ | |
17 | selector: 'my-account-details', | |
18 | templateUrl: './account-details.component.html' | |
19 | }) | |
20 | ||
21 | export class AccountDetailsComponent extends FormReactive implements OnInit { | |
df98563e | 22 | @Input() user: User = null |
af5e743b | 23 | |
df98563e | 24 | error: string = null |
af5e743b | 25 | |
df98563e C |
26 | form: FormGroup |
27 | formErrors = {} | |
28 | validationMessages = {} | |
af5e743b | 29 | |
df98563e | 30 | constructor ( |
af5e743b C |
31 | private authService: AuthService, |
32 | private formBuilder: FormBuilder, | |
af5e743b C |
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'] | |
8094a898 | 53 | const details: UserUpdateMe = { |
af5e743b | 54 | displayNSFW |
df98563e | 55 | } |
af5e743b | 56 | |
df98563e | 57 | this.error = null |
8094a898 | 58 | this.userService.updateMyDetails(details).subscribe( |
af5e743b | 59 | () => { |
8094a898 | 60 | this.notificationsService.success('Success', 'Information updated.') |
af5e743b | 61 | |
d592e0a9 | 62 | this.authService.refreshUserInformation() |
af5e743b C |
63 | }, |
64 | ||
f7354483 | 65 | err => this.error = err.message |
df98563e | 66 | ) |
af5e743b C |
67 | } |
68 | } |