From d18d64787b3ea174f7dc2740c8c8c9555625047e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 5 Jun 2018 10:58:45 +0200 Subject: Form validators refractoring --- .../users/user-edit/user-create.component.ts | 45 +++++++--------------- 1 file changed, 14 insertions(+), 31 deletions(-) (limited to 'client/src/app/+admin/users/user-edit/user-create.component.ts') 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 @@ import { Component, OnInit } from '@angular/core' -import { FormBuilder, FormGroup } from '@angular/forms' import { Router } from '@angular/router' import { NotificationsService } from 'angular2-notifications' import { UserService } from '../shared' @@ -8,6 +7,7 @@ import { ServerService } from '../../../core' import { UserCreate, UserRole } from '../../../../../../shared' import { UserEdit } from './user-edit' import { I18n } from '@ngx-translate/i18n-polyfill' +import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' @Component({ selector: 'my-user-create', @@ -17,25 +17,9 @@ import { I18n } from '@ngx-translate/i18n-polyfill' export class UserCreateComponent extends UserEdit implements OnInit { error: string - form: FormGroup - formErrors = { - 'username': '', - 'email': '', - 'password': '', - 'role': '', - 'videoQuota': '' - } - validationMessages = { - 'username': USER_USERNAME.MESSAGES, - 'email': USER_EMAIL.MESSAGES, - 'password': USER_PASSWORD.MESSAGES, - 'role': USER_ROLE.MESSAGES, - 'videoQuota': USER_VIDEO_QUOTA.MESSAGES - } - constructor ( protected serverService: ServerService, - private formBuilder: FormBuilder, + protected formValidatorService: FormValidatorService, private router: Router, private notificationsService: NotificationsService, private userService: UserService, @@ -44,20 +28,19 @@ export class UserCreateComponent extends UserEdit implements OnInit { super() } - buildForm () { - this.form = this.formBuilder.group({ - username: [ '', USER_USERNAME.VALIDATORS ], - email: [ '', USER_EMAIL.VALIDATORS ], - password: [ '', USER_PASSWORD.VALIDATORS ], - role: [ UserRole.USER, USER_ROLE.VALIDATORS ], - videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ] - }) - - this.form.valueChanges.subscribe(data => this.onValueChanged(data)) - } - ngOnInit () { - this.buildForm() + const defaultValues = { + role: UserRole.USER.toString(), + videoQuota: '-1' + } + + this.buildForm({ + username: USER_USERNAME, + email: USER_EMAIL, + password: USER_PASSWORD, + role: USER_ROLE, + videoQuota: USER_VIDEO_QUOTA + }, defaultValues) } formValidated () { -- cgit v1.2.3