]>
Commit | Line | Data |
---|---|---|
c30745f3 | 1 | import { Component, Input, OnInit } from '@angular/core' |
df98563e | 2 | import { NotificationsService } from 'angular2-notifications' |
c30745f3 C |
3 | import { UserUpdateMe } from '../../../../../../shared' |
4 | import { AuthService } from '../../../core' | |
5 | import { FormReactive, User, UserService } from '../../../shared' | |
b1d40cff | 6 | import { I18n } from '@ngx-translate/i18n-polyfill' |
d18d6478 | 7 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
4d089429 | 8 | import { Subject } from 'rxjs' |
af5e743b C |
9 | |
10 | @Component({ | |
ed56ad11 C |
11 | selector: 'my-account-video-settings', |
12 | templateUrl: './my-account-video-settings.component.html', | |
13 | styleUrls: [ './my-account-video-settings.component.scss' ] | |
af5e743b | 14 | }) |
ed56ad11 | 15 | export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit { |
df98563e | 16 | @Input() user: User = null |
d18d6478 | 17 | @Input() userInformationLoaded: Subject<any> |
af5e743b | 18 | |
df98563e | 19 | constructor ( |
d18d6478 | 20 | protected formValidatorService: FormValidatorService, |
af5e743b | 21 | private authService: AuthService, |
af5e743b | 22 | private notificationsService: NotificationsService, |
b1d40cff C |
23 | private userService: UserService, |
24 | private i18n: I18n | |
af5e743b | 25 | ) { |
df98563e | 26 | super() |
af5e743b C |
27 | } |
28 | ||
d18d6478 C |
29 | ngOnInit () { |
30 | this.buildForm({ | |
31 | nsfwPolicy: null, | |
32 | autoPlayVideo: null | |
df98563e | 33 | }) |
af5e743b | 34 | |
d18d6478 C |
35 | this.userInformationLoaded.subscribe(() => { |
36 | this.form.patchValue({ | |
37 | nsfwPolicy: this.user.nsfwPolicy, | |
d879e48b | 38 | autoPlayVideo: this.user.autoPlayVideo === true |
d18d6478 C |
39 | }) |
40 | }) | |
af5e743b C |
41 | } |
42 | ||
df98563e | 43 | updateDetails () { |
0883b324 | 44 | const nsfwPolicy = this.form.value['nsfwPolicy'] |
7efe153b | 45 | const autoPlayVideo = this.form.value['autoPlayVideo'] |
8094a898 | 46 | const details: UserUpdateMe = { |
0883b324 | 47 | nsfwPolicy, |
7efe153b | 48 | autoPlayVideo |
df98563e | 49 | } |
af5e743b | 50 | |
ed56ad11 | 51 | this.userService.updateMyProfile(details).subscribe( |
af5e743b | 52 | () => { |
b1d40cff | 53 | this.notificationsService.success(this.i18n('Success'), this.i18n('Information updated.')) |
af5e743b | 54 | |
d592e0a9 | 55 | this.authService.refreshUserInformation() |
af5e743b C |
56 | }, |
57 | ||
b1d40cff | 58 | err => this.notificationsService.error(this.i18n('Error'), err.message) |
df98563e | 59 | ) |
af5e743b C |
60 | } |
61 | } |