Guest User

Untitled

a guest
Feb 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.17 KB | None | 0 0
  1. @{
  2. ViewBag.Title = "Account Registration";
  3. }
  4. @section scripts {
  5. <script src="@Url.Content("~/Binding/Models/AccountRegisterModel.js")"
  6. type="text/javascript"></script>
  7. <script src="@Url.Content("~/Binding/ViewModels/AccountRegisterViewModel.js")"
  8. type="text/javascript"></script>
  9. }
  10.  
  11. @section footerScript {
  12. angular.bootstrap(document.getElementById("registration"), ['accountRegister']);
  13. }
  14.  
  15. <div ng-non-bindable>
  16. <div data-ng-controller="AccountRegisterViewModel" id="registration">
  17. <br />
  18. @Html.Partial("~/Views/Shared/_ValidationErrors.cshtml")
  19. <br />
  20. <div ng-view></div>
  21. </div>
  22. </div>
  23.  
  24. var commonModule = angular.module('common', ['ngRoute', 'ui.bootstrap']);
  25.  
  26. // Non-SPA views will use Angular controllers created on the appMainModule.
  27. var appMainModule = angular.module('appMain', ['common']);
  28.  
  29. // SPA-views will attach to their own module and use their own data-ng-app and nested controllers.
  30. // Each MVC-delivered top-spa-level view will link its needed JS files.
  31.  
  32. // Services attached to the commonModule will be available to all other Angular modules.
  33.  
  34. commonModule.factory('viewModelHelper', function ($http, $q) {
  35. return AlbumApp.viewModelHelper($http, $q);
  36. });
  37.  
  38. commonModule.factory('validator', function () {
  39. return valJs.validator();
  40. });
  41.  
  42. (function (aa) {
  43. var viewModelHelper = function ($http, $q) {
  44.  
  45. var self = this;
  46.  
  47. self.modelIsValid = true;
  48. self.modelErrors = [];
  49. self.isLoading = false;
  50. ...
  51.  
  52. var accountRegisterModule = angular.module('accountRegister', ['common'])
  53. .config(function ($routeProvider, $locationProvider) {
  54. $routeProvider.when(AlbumApp.rootPath + 'account/register/step1',
  55. { templateUrl: AlbumApp.rootPath + 'Templates/RegisterStep1.html',
  56. controller: 'AccountRegisterStep1ViewModel' });
  57. $routeProvider.when(AlbumApp.rootPath + 'account/register/step2',
  58. { templateUrl: AlbumApp.rootPath + 'Templates/RegisterStep2.html',
  59. controller: 'AccountRegisterStep2ViewModel' });
  60. $routeProvider.when(AlbumApp.rootPath + 'account/register/step3',
  61. { templateUrl: AlbumApp.rootPath + 'Templates/RegisterStep3.html',
  62. controller: 'AccountRegisterStep3ViewModel' });
  63. $routeProvider.when(AlbumApp.rootPath + 'account/register/confirm',
  64. { templateUrl: AlbumApp.rootPath + 'Templates/RegisterConfirm.html',
  65. controller: 'AccountRegisterConfirmViewModel' });
  66. $routeProvider.otherwise({ redirectTo: AlbumApp.rootPath + 'account/register/step1' });
  67. $locationProvider.html5Mode({ enabled: true, requireBase: false });
  68. });
  69.  
  70.  
  71. accountRegisterModule.controller("AccountRegisterViewModel",
  72. function ($scope, $http, $location, $window, viewModelHelper) {
  73. $scope.viewModelHelper = viewModelHelper;
  74. $scope.accountModelStep1 = new AlbumApp.AccountRegisterModelStep1();
  75. $scope.accountModelStep2 = new AlbumApp.AccountRegisterModelStep2();
  76. $scope.accountModelStep3 = new AlbumApp.AccountRegisterModelStep3();
  77. $scope.previous = function () { $window.history.back(); } });
  78.  
  79.  
  80. accountRegisterModule.controller("AccountRegisterStep1ViewModel",
  81. function ($scope, $http, $location, $window, viewModelHelper, validator) {
  82. viewModelHelper.modelIsValid = true; viewModelHelper.modelErrors = []; var accountModelStep1Rules = [];
  83.  
  84. var setupRules = function () {
  85. accountModelStep1Rules.push(new validator.PropertyRule("FirstName", {
  86. required: { message: "First name is required" } }));
  87. accountModelStep1Rules.push(new validator.PropertyRule("LastName", {
  88. required: { message: "Last name is required" } }));
  89. accountModelStep1Rules.push(new validator.PropertyRule("Address", {
  90. required: { message: "Address is required" } }));
  91. accountModelStep1Rules.push(new validator.PropertyRule("City", {
  92. required: { message: "City is required" } }));
  93. accountModelStep1Rules.push(new validator.PropertyRule("State", {
  94. required: { message: "State is required" } }));
  95. accountModelStep1Rules.push(new validator.PropertyRule("ZipCode", {
  96. required: { message: "Zip code is required" },
  97. pattern: { message: "Zip code is in invalid format (5 digits)",
  98. params: /^d{5}$/ } })); }
  99.  
  100. $scope.step2 = function () {
  101. validator.ValidateModel($scope.accountModelStep1, accountModelStep1Rules);
  102. viewModelHelper.modelIsValid = $scope.accountModelStep1.isValid;
  103. viewModelHelper.modelErrors = $scope.accountModelStep1.errors;
  104. if (viewModelHelper.modelIsValid) { /* api/account/register/validate1 */
  105. viewModelHelper.apiPost('api/account/register/validate1', $scope.accountModelStep1,
  106. function (result) { $scope.accountModelStep1.Initialized = true;
  107. $location.path(AlbumApp.rootPath + 'account/register/step2'); }); }
  108. else viewModelHelper.modelErrors = $scope.accountModelStep1.errors; }
  109.  
  110. setupRules(); });
  111.  
  112.  
  113. accountRegisterModule.controller("AccountRegisterStep2ViewModel", function ($scope, $http,
  114. $location, $window, viewModelHelper, validator) {
  115. if (!$scope.accountModelStep1.Initialized) { // go to this controller before going through step 2
  116. $location.path(AlbumApp.rootPath + 'account/register/step1');}
  117.  
  118. viewModelHelper.modelIsValid = true; viewModelHelper.modelErrors = []; var accountModelStep2Rules = [];
  119.  
  120. var setupRules = function () {
  121. accountModelStep2Rules.push(new validator.PropertyRule("LoginEmail", {
  122. required: { message: "Login Email is required" },
  123. email: { message: "Login email is not an email." } }));
  124. var pwdLen = 6;
  125. accountModelStep2Rules.push(new validator.PropertyRule("Password", {
  126. required: { message: "Password is required" },
  127. minLength: { message: "Password must be at least " + pwdLen + " characters", params: pwdLen } }));
  128. accountModelStep2Rules.push(new validator.PropertyRule("PasswordConfirm", {
  129. required: { message: "Password Confirmation is required" },
  130. custom: {
  131. validator: AlbumApp.mustEqual,
  132. message: "Passwords do not match",
  133. params: function () { return $scope.accountModelStep2.Password; } } }));
  134. }
  135.  
  136. $scope.step3 = function () {
  137. validator.ValidateModel($scope.accountModelStep2, accountModelStep2Rules);
  138. viewModelHelper.modelIsValid = $scope.accountModelStep2.isValid;
  139. viewModelHelper.modelErrors = $scope.accountModelStep2.errors;
  140. if (viewModelHelper.modelIsValid) { /* api/account/register/validate2 */
  141. viewModelHelper.apiPost('api/account/register/validate2', $scope.accountModelStep2,
  142. function (result) {
  143. $scope.accountModelStep2.Initialized = true;
  144. $location.path(AlbumApp.rootPath + 'account/register/step3');
  145. });
  146. }
  147. else viewModelHelper.modelErrors = $scope.accountModelStep2.errors;
  148. }
  149.  
  150. setupRules();
  151. });
  152.  
  153.  
  154. accountRegisterModule.controller("AccountRegisterStep3ViewModel", function ($scope, $http,
  155. $location, viewModelHelper, validator) { // $window
  156. if (!$scope.accountModelStep2.Initialized) { // go to this controller before going through step 3
  157. $location.path(AlbumApp.rootPath + 'account/register/step2');
  158. }
  159.  
  160. viewModelHelper.modelIsValid = true; viewModelHelper.modelErrors = []; var accountModelStep3Rules = [];
  161.  
  162. var setupRules = function () {
  163. accountModelStep3Rules.push(new validator.PropertyRule("CreditCard", {
  164. required: { message: "Credit Card # is required" },
  165. pattern: { message: "CreditCard is in invalid format (16 digits)", params: /^d{16}$/ }
  166. }));
  167. accountModelStep3Rules.push(new validator.PropertyRule("ExpDate", {
  168. required: { message: "Expiration Date is required" },
  169. pattern: {
  170. message: "Expiration Date is in invalid format (MM/YY)",
  171. params: /^(0[1-9]|1[0-2])/[0-9]{2}$/ } }));
  172. }
  173.  
  174. $scope.confirm = function () {
  175. validator.ValidateModel($scope.accountModelStep3, accountModelStep3Rules);
  176. viewModelHelper.modelIsValid = $scope.accountModelStep3.isValid;
  177. viewModelHelper.modelErrors = $scope.accountModelStep3.errors;
  178. if (viewModelHelper.modelIsValid) { /* api/account/register/validate3 */
  179. viewModelHelper.apiPost('api/account/register/validate3', $scope.accountModelStep3,
  180. function (result) {
  181. $scope.accountModelStep3.Initialized = true;
  182. $location.path(AlbumApp.rootPath + 'account/register/confirm');
  183. }); }
  184. else viewModelHelper.modelErrors = $scope.accountModelStep3.errors;
  185. }
  186.  
  187. setupRules();
  188. });
  189.  
  190. accountRegisterModule.controller("AccountRegisterConfirmViewModel", function ($scope, $http,
  191. $location, $window, viewModelHelper) {
  192. if (!$scope.accountModelStep3.Initialized) { // go to this controller before going through step confirm
  193. $location.path(AlbumApp.rootPath + 'account/register/step3'); }
  194.  
  195. $scope.createAccount = function () {
  196. var accountModel;
  197. accountModel = $.extend(accountModel, $scope.accountModelStep1);
  198. accountModel = $.extend(accountModel, $scope.accountModelStep2);
  199. accountModel = $.extend(accountModel, $scope.accountModelStep3);
  200.  
  201. /* api/account/register */
  202. viewModelHelper.apiPost('api/account/register', accountModel,
  203. function (result) { $window.location.href = AlbumApp.rootPath; }); } });
  204.  
  205. <div>
  206. <p class="input-group" style="width: 400px">
  207. <span class="input-group-addon" style="width: 140px; text-align: left;">First name:</span>
  208. <input type="text" class="form-control" ng-model="accountModelStep1.FirstName" placeholder="first name" />
  209. </p>
  210. <p class="input-group" style="width: 400px">
  211. <span class="input-group-addon" style="width: 140px; text-align: left;">Last name:</span>
  212. <input type="text" class="form-control" ng-model="accountModelStep1.LastName" placeholder="last name" />
  213. </p>
  214. <p class="input-group" style="width: 500px">
  215. <span class="input-group-addon" style="width: 140px; text-align: left;">Address:</span>
  216. <input type="text" class="form-control" ng-model="accountModelStep1.Address" placeholder="address" />
  217. </p>
  218. <p class="input-group" style="width: 400px">
  219. <span class="input-group-addon" style="width: 140px; text-align: left;">City:</span>
  220. <input type="text" class="form-control" ng-model="accountModelStep1.City" placeholder="city" />
  221. </p>
  222. <p class="input-group" style="width: 200px">
  223. <span class="input-group-addon" style="width: 140px; text-align: left;">State:</span>
  224. <input type="text" class="form-control" ng-model="accountModelStep1.State" placeholder="state" />
  225. </p>
  226. <p class="input-group" style="width: 215px">
  227. <span class="input-group-addon" style="width: 140px; text-align: left;">Zip code:</span>
  228. <input type="text" class="form-control" ng-model="accountModelStep1.ZipCode" placeholder="zip code" />
  229. </p>
  230. <hr style="width: 415px; text-align: left;" />
  231. <div>
  232. <a href="" class="btn btn-info" ng-show="!viewModelHelper.isLoading" ng-click="step2()">Next</a>
  233. <span class="spinner-config" ng-show="viewModelHelper.isLoading">
  234. <i class="fa fa-spinner fa-spin"></i>
  235. </span>
  236. </div>
  237. </div>
  238.  
  239. <div>
  240. <p class="input-group" style="width: 400px">
  241. <span class="input-group-addon" style="width: 140px; text-align: left;">Login Email:</span>
  242. <input type="text" ng-model="accountModelStep2.LoginEmail" class="form-control" placeholder="login email" />
  243. </p>
  244. <p class="input-group" style="width: 400px">
  245. <span class="input-group-addon" style="width: 140px; text-align: left;">Password:</span>
  246. <input type="password" ng-model="accountModelStep2.Password" class="form-control"placeholder="password" />
  247. </p>
  248. <p class="input-group" style="width: 400px">
  249. <span class="input-group-addon" style="width: 140px; text-align: left;">Confirm Password:</span>
  250. <input type="password" ng-model="accountModelStep2.PasswordConfirm" class="form-control" placeholder="confirm password" />
  251. </p>
  252. <hr style="width: 415px; text-align: left;" />
  253. <div>
  254. <a href="" class="btn btn-info" ng-show="!viewModelHelper.isLoading" ng-click="previous()">Previous</a>
  255. <a href="" class="btn btn-info" ng-show="!viewModelHelper.isLoading" ng-click="step3()">Next</a>
  256. <span class="spinner-config" ng-show="viewModelHelper.isLoading">
  257. <i class="fa fa-spinner fa-spin"></i>
  258. </span>
  259. </div>
  260. </div>
Add Comment
Please, Sign In to add comment