diff options
Diffstat (limited to 'client/src/app/my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts')
-rw-r--r-- | client/src/app/my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/client/src/app/my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts b/client/src/app/my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts new file mode 100644 index 000000000..acc70c14d --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts | |||
@@ -0,0 +1,60 @@ | |||
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-video-settings', | ||
10 | templateUrl: './my-account-video-settings.component.html', | ||
11 | styleUrls: [ './my-account-video-settings.component.scss' ] | ||
12 | }) | ||
13 | export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit { | ||
14 | @Input() user: User = null | ||
15 | |||
16 | form: FormGroup | ||
17 | formErrors = {} | ||
18 | validationMessages = {} | ||
19 | |||
20 | constructor ( | ||
21 | private authService: AuthService, | ||
22 | private formBuilder: FormBuilder, | ||
23 | private notificationsService: NotificationsService, | ||
24 | private userService: UserService | ||
25 | ) { | ||
26 | super() | ||
27 | } | ||
28 | |||
29 | buildForm () { | ||
30 | this.form = this.formBuilder.group({ | ||
31 | nsfwPolicy: [ this.user.nsfwPolicy ], | ||
32 | autoPlayVideo: [ this.user.autoPlayVideo ] | ||
33 | }) | ||
34 | |||
35 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
36 | } | ||
37 | |||
38 | ngOnInit () { | ||
39 | this.buildForm() | ||
40 | } | ||
41 | |||
42 | updateDetails () { | ||
43 | const nsfwPolicy = this.form.value['nsfwPolicy'] | ||
44 | const autoPlayVideo = this.form.value['autoPlayVideo'] | ||
45 | const details: UserUpdateMe = { | ||
46 | nsfwPolicy, | ||
47 | autoPlayVideo | ||
48 | } | ||
49 | |||
50 | this.userService.updateMyProfile(details).subscribe( | ||
51 | () => { | ||
52 | this.notificationsService.success('Success', 'Information updated.') | ||
53 | |||
54 | this.authService.refreshUserInformation() | ||
55 | }, | ||
56 | |||
57 | err => this.notificationsService.error('Error', err.message) | ||
58 | ) | ||
59 | } | ||
60 | } | ||