Advertisement
Guest User

Untitled

a guest
Apr 19th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. import { Injectable } from 'angular2/core';
  2. import {
  3. FormBuilder,
  4. Validators,
  5. Control,
  6. ControlGroup }
  7. from 'angular2/common';
  8.  
  9. import { ValidationHelper } from
  10. './validation-helper';
  11.  
  12. @Injectable()
  13. export class SexyUserFormBuilder {
  14.  
  15. public buildProfileForm(user?): ControlGroup {
  16. const builder = new FormBuilder();
  17.  
  18. if (!user) { user = {}; }
  19.  
  20. return builder.group({
  21. first_name: this.first_name(user.first_name),
  22. // Not using middle name. That's rediculous
  23. // middle_name: this.middle_name(user.middle_name),
  24. last_name: this.last_name(user.last_name),
  25. email: this.email(user.email),
  26. password: this.password(),
  27. bio: this.bio(user.bio),
  28. salon_name: this.salon_name(user.salon_name),
  29. license_number: this.license_number(user.license_number),
  30. attended_event: this.attended_event(user.attended_event)
  31. });
  32. }
  33.  
  34. public buildLoginForm(user?): ControlGroup {
  35. const builder = new FormBuilder();
  36.  
  37. if (!user) { user = {}; }
  38.  
  39. return builder.group({
  40. email: this.email(user.email),
  41. password: this.password(),
  42. });
  43. }
  44.  
  45. public buildForgotEmail(): ControlGroup {
  46. const builder = new FormBuilder();
  47.  
  48. return builder.group({
  49. forgotEmail: this.email()
  50. });
  51. }
  52.  
  53. public buildForgotPassword(): ControlGroup {
  54. const builder = new FormBuilder();
  55.  
  56. let password = this.password();
  57.  
  58. return builder.group({
  59. password: password,
  60. confirm: this.confirmPassword(password)
  61. });
  62. }
  63.  
  64. /**
  65. * Inidividual values
  66. */
  67.  
  68. private first_name(initValue?): Control {
  69. return new Control(
  70. initValue || '',
  71. Validators.required
  72. );
  73. }
  74.  
  75. private middle_name(initValue?): Control {
  76. return new Control(
  77. initValue || '',
  78. Validators.required
  79. );
  80. }
  81.  
  82. private last_name(initValue?): Control {
  83. return new Control(
  84. initValue || '',
  85. Validators.required
  86. );
  87. }
  88.  
  89. private email(initValue?): Control {
  90. return new Control(
  91. initValue || '',
  92. Validators.compose([
  93. Validators.required,
  94. ValidationHelper.emailValidator
  95. ])
  96. );
  97. }
  98.  
  99. private password(initValue?): Control {
  100. return new Control(
  101. initValue || '',
  102. Validators.compose([
  103. Validators.required,
  104. ValidationHelper.passwordValidator
  105. ])
  106. );
  107. }
  108.  
  109. private confirmPassword(password: Control): Control {
  110. return new Control(
  111. '',
  112. Validators.compose([
  113. Validators.required,
  114. ValidationHelper.matchValidator(password)
  115. ])
  116. );
  117. }
  118.  
  119. private bio(initValue?): Control {
  120. return new Control(
  121. initValue || ''
  122. );
  123. }
  124.  
  125. private salon_name(initValue?): Control {
  126. return new Control(
  127. initValue || '',
  128. Validators.required
  129. );
  130. }
  131.  
  132. private license_number(initValue?): Control {
  133. return new Control(
  134. initValue || '',
  135. Validators.required
  136. );
  137. }
  138.  
  139. private attended_event(initValue?): Control {
  140. return new Control(
  141. initValue || false
  142. );
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement