Created
April 19, 2016 18:06
-
-
Save Spittal/7816b99ea9e60560275b8df55ebd904d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment