Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from 'angular2/core';
- import {
- FormBuilder,
- Validators,
- Control,
- ControlGroup }
- from 'angular2/common';
- import { ValidationHelper } from
- './validation-helper';
- @Injectable()
- export class SexyUserFormBuilder {
- public buildProfileForm(user?): ControlGroup {
- const builder = new FormBuilder();
- if (!user) { user = {}; }
- return builder.group({
- first_name: this.first_name(user.first_name),
- // Not using middle name. That's rediculous
- // middle_name: this.middle_name(user.middle_name),
- last_name: this.last_name(user.last_name),
- email: this.email(user.email),
- password: this.password(),
- bio: this.bio(user.bio),
- salon_name: this.salon_name(user.salon_name),
- license_number: this.license_number(user.license_number),
- attended_event: this.attended_event(user.attended_event)
- });
- }
- public buildLoginForm(user?): ControlGroup {
- const builder = new FormBuilder();
- if (!user) { user = {}; }
- return builder.group({
- email: this.email(user.email),
- password: this.password(),
- });
- }
- public buildForgotEmail(): ControlGroup {
- const builder = new FormBuilder();
- return builder.group({
- forgotEmail: this.email()
- });
- }
- public buildForgotPassword(): ControlGroup {
- const builder = new FormBuilder();
- let password = this.password();
- return builder.group({
- password: password,
- confirm: this.confirmPassword(password)
- });
- }
- /**
- * Inidividual values
- */
- private first_name(initValue?): Control {
- return new Control(
- initValue || '',
- Validators.required
- );
- }
- private middle_name(initValue?): Control {
- return new Control(
- initValue || '',
- Validators.required
- );
- }
- private last_name(initValue?): Control {
- return new Control(
- initValue || '',
- Validators.required
- );
- }
- private email(initValue?): Control {
- return new Control(
- initValue || '',
- Validators.compose([
- Validators.required,
- ValidationHelper.emailValidator
- ])
- );
- }
- private password(initValue?): Control {
- return new Control(
- initValue || '',
- Validators.compose([
- Validators.required,
- ValidationHelper.passwordValidator
- ])
- );
- }
- private confirmPassword(password: Control): Control {
- return new Control(
- '',
- Validators.compose([
- Validators.required,
- ValidationHelper.matchValidator(password)
- ])
- );
- }
- private bio(initValue?): Control {
- return new Control(
- initValue || ''
- );
- }
- private salon_name(initValue?): Control {
- return new Control(
- initValue || '',
- Validators.required
- );
- }
- private license_number(initValue?): Control {
- return new Control(
- initValue || '',
- Validators.required
- );
- }
- private attended_event(initValue?): Control {
- return new Control(
- initValue || false
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement