]>
Commit | Line | Data |
---|---|---|
b426edd4 | 1 | import { Component, Input, OnInit } from '@angular/core' |
328c78bc | 2 | import { ActivatedRoute, Router } from '@angular/router' |
328c78bc | 3 | import { UserService } from '@app/shared/users/user.service' |
b426edd4 | 4 | import { Notifier } from '../../../core' |
328c78bc RK |
5 | import { User, UserUpdate } from '../../../../../../shared' |
6 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
7 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | |
8 | import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service' | |
328c78bc RK |
9 | import { FormReactive } from '../../../shared' |
10 | ||
11 | @Component({ | |
12 | selector: 'my-user-password', | |
13 | templateUrl: './user-password.component.html', | |
14 | styleUrls: [ './user-password.component.scss' ] | |
15 | }) | |
b426edd4 | 16 | export class UserPasswordComponent extends FormReactive implements OnInit { |
328c78bc | 17 | error: string |
328c78bc RK |
18 | username: string |
19 | showPassword = false | |
20 | ||
2c2baef6 RK |
21 | @Input() userId: number |
22 | ||
328c78bc RK |
23 | constructor ( |
24 | protected formValidatorService: FormValidatorService, | |
328c78bc RK |
25 | private userValidatorsService: UserValidatorsService, |
26 | private route: ActivatedRoute, | |
27 | private router: Router, | |
b426edd4 | 28 | private notifier: Notifier, |
328c78bc RK |
29 | private userService: UserService, |
30 | private i18n: I18n | |
31 | ) { | |
32 | super() | |
33 | } | |
34 | ||
35 | ngOnInit () { | |
36 | this.buildForm({ | |
37 | password: this.userValidatorsService.USER_PASSWORD | |
38 | }) | |
328c78bc RK |
39 | } |
40 | ||
328c78bc RK |
41 | formValidated () { |
42 | this.error = undefined | |
43 | ||
44 | const userUpdate: UserUpdate = this.form.value | |
45 | ||
46 | this.userService.updateUser(this.userId, userUpdate).subscribe( | |
47 | () => { | |
b426edd4 | 48 | this.notifier.success( |
328c78bc RK |
49 | this.i18n('Password changed for user {{username}}.', { username: this.username }) |
50 | ) | |
51 | }, | |
52 | ||
53 | err => this.error = err.message | |
54 | ) | |
55 | } | |
56 | ||
328c78bc RK |
57 | togglePasswordVisibility () { |
58 | this.showPassword = !this.showPassword | |
59 | } | |
60 | ||
61 | getFormButtonTitle () { | |
62 | return this.i18n('Update user password') | |
63 | } | |
328c78bc | 64 | } |