aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/users/user-edit/user-create.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-05 10:58:45 +0200
committerChocobozzz <me@florianbigard.com>2018-06-05 10:58:45 +0200
commitd18d64787b3ea174f7dc2740c8c8c9555625047e (patch)
treee65089e0ca81117c1ada981b9b8a524afa8d70f5 /client/src/app/+admin/users/user-edit/user-create.component.ts
parent25acef90a85c1584880dec96aa402f896af8364a (diff)
downloadPeerTube-d18d64787b3ea174f7dc2740c8c8c9555625047e.tar.gz
PeerTube-d18d64787b3ea174f7dc2740c8c8c9555625047e.tar.zst
PeerTube-d18d64787b3ea174f7dc2740c8c8c9555625047e.zip
Form validators refractoring
Diffstat (limited to 'client/src/app/+admin/users/user-edit/user-create.component.ts')
-rw-r--r--client/src/app/+admin/users/user-edit/user-create.component.ts45
1 files changed, 14 insertions, 31 deletions
diff --git a/client/src/app/+admin/users/user-edit/user-create.component.ts b/client/src/app/+admin/users/user-edit/user-create.component.ts
index 8478a7692..e5f0903b6 100644
--- a/client/src/app/+admin/users/user-edit/user-create.component.ts
+++ b/client/src/app/+admin/users/user-edit/user-create.component.ts
@@ -1,5 +1,4 @@
1import { Component, OnInit } from '@angular/core' 1import { Component, OnInit } from '@angular/core'
2import { FormBuilder, FormGroup } from '@angular/forms'
3import { Router } from '@angular/router' 2import { Router } from '@angular/router'
4import { NotificationsService } from 'angular2-notifications' 3import { NotificationsService } from 'angular2-notifications'
5import { UserService } from '../shared' 4import { UserService } from '../shared'
@@ -8,6 +7,7 @@ import { ServerService } from '../../../core'
8import { UserCreate, UserRole } from '../../../../../../shared' 7import { UserCreate, UserRole } from '../../../../../../shared'
9import { UserEdit } from './user-edit' 8import { UserEdit } from './user-edit'
10import { I18n } from '@ngx-translate/i18n-polyfill' 9import { I18n } from '@ngx-translate/i18n-polyfill'
10import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
11 11
12@Component({ 12@Component({
13 selector: 'my-user-create', 13 selector: 'my-user-create',
@@ -17,25 +17,9 @@ import { I18n } from '@ngx-translate/i18n-polyfill'
17export class UserCreateComponent extends UserEdit implements OnInit { 17export class UserCreateComponent extends UserEdit implements OnInit {
18 error: string 18 error: string
19 19
20 form: FormGroup
21 formErrors = {
22 'username': '',
23 'email': '',
24 'password': '',
25 'role': '',
26 'videoQuota': ''
27 }
28 validationMessages = {
29 'username': USER_USERNAME.MESSAGES,
30 'email': USER_EMAIL.MESSAGES,
31 'password': USER_PASSWORD.MESSAGES,
32 'role': USER_ROLE.MESSAGES,
33 'videoQuota': USER_VIDEO_QUOTA.MESSAGES
34 }
35
36 constructor ( 20 constructor (
37 protected serverService: ServerService, 21 protected serverService: ServerService,
38 private formBuilder: FormBuilder, 22 protected formValidatorService: FormValidatorService,
39 private router: Router, 23 private router: Router,
40 private notificationsService: NotificationsService, 24 private notificationsService: NotificationsService,
41 private userService: UserService, 25 private userService: UserService,
@@ -44,20 +28,19 @@ export class UserCreateComponent extends UserEdit implements OnInit {
44 super() 28 super()
45 } 29 }
46 30
47 buildForm () {
48 this.form = this.formBuilder.group({
49 username: [ '', USER_USERNAME.VALIDATORS ],
50 email: [ '', USER_EMAIL.VALIDATORS ],
51 password: [ '', USER_PASSWORD.VALIDATORS ],
52 role: [ UserRole.USER, USER_ROLE.VALIDATORS ],
53 videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ]
54 })
55
56 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
57 }
58
59 ngOnInit () { 31 ngOnInit () {
60 this.buildForm() 32 const defaultValues = {
33 role: UserRole.USER.toString(),
34 videoQuota: '-1'
35 }
36
37 this.buildForm({
38 username: USER_USERNAME,
39 email: USER_EMAIL,
40 password: USER_PASSWORD,
41 role: USER_ROLE,
42 videoQuota: USER_VIDEO_QUOTA
43 }, defaultValues)
61 } 44 }
62 45
63 formValidated () { 46 formValidated () {