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-update.component.ts | 33 ++++++---------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'client/src/app/+admin/users/user-edit/user-update.component.ts') diff --git a/client/src/app/+admin/users/user-edit/user-update.component.ts b/client/src/app/+admin/users/user-edit/user-update.component.ts index 5689aab2f..f8073c928 100644 --- a/client/src/app/+admin/users/user-edit/user-update.component.ts +++ b/client/src/app/+admin/users/user-edit/user-update.component.ts @@ -1,5 +1,4 @@ import { Component, OnDestroy, OnInit } from '@angular/core' -import { FormBuilder, FormGroup } from '@angular/forms' import { ActivatedRoute, Router } from '@angular/router' import { Subscription } from 'rxjs' import { NotificationsService } from 'angular2-notifications' @@ -9,6 +8,7 @@ import { ServerService } from '../../../core' import { UserEdit } from './user-edit' import { UserUpdate } from '../../../../../../shared' import { I18n } from '@ngx-translate/i18n-polyfill' +import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' @Component({ selector: 'my-user-update', @@ -20,44 +20,27 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy { userId: number username: string - form: FormGroup - formErrors = { - 'email': '', - 'role': '', - 'videoQuota': '' - } - validationMessages = { - 'email': USER_EMAIL.MESSAGES, - 'role': USER_ROLE.MESSAGES, - 'videoQuota': USER_VIDEO_QUOTA.MESSAGES - } - private paramsSub: Subscription constructor ( + protected formValidatorService: FormValidatorService, protected serverService: ServerService, private route: ActivatedRoute, private router: Router, private notificationsService: NotificationsService, - private formBuilder: FormBuilder, private userService: UserService, private i18n: I18n ) { super() } - buildForm () { - this.form = this.formBuilder.group({ - email: [ '', USER_EMAIL.VALIDATORS ], - role: [ '', USER_ROLE.VALIDATORS ], - videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ] - }) - - this.form.valueChanges.subscribe(data => this.onValueChanged(data)) - } - ngOnInit () { - this.buildForm() + const defaultValues = { videoQuota: '-1' } + this.buildForm({ + email: USER_EMAIL, + role: USER_ROLE, + videoQuota: USER_VIDEO_QUOTA + }, defaultValues) this.paramsSub = this.route.params.subscribe(routeParams => { const userId = routeParams['id'] -- cgit v1.2.3