1(function () { 2 angular.module('pwa.views') 3 .controller("RegisterCtrl", RegisterCtrl); 4 5 RegisterCtrl.$inject = ['registrationData', '$scope', '$window', '$http', 'pwaCookies', 'WebApiUrls', 'inValUtils', 'pwaUtils', 'inUiUtils', '$rootElement', '$route', '$parse', "$timeout", "$location", 'dataservice', 'pwaNavigation']; 6 7 function RegisterCtrl(registrationData, $scope, $window, $http, dpdCookies, WebApiUrls, inValUtils, dpdUtils, inUiUtils, $rootElement, $route, $parse, $timeout, $location, dataservice, pwaNavigation) { 8 var cookieKey = "pwaRegData";//REFACTOR move to constants 9 var vm = this; 10 11 vm.getTemplateName = getTemplateName; 12 vm.toStep2 = toStep2; 13 vm.toStep3 = toStep3; 14 vm.validateMobile = validateMobile; 15 vm.resendMobileToken = resendMobileToken; 16 vm.updateRegistrationDetails = updateRegistrationDetails; 17 18 vm.page = 0; 19 $scope.registration = { 20 name: "", 21 surname: "", 22 email: "", 23 password: "", 24 passwordConfirmation: "", 25 mobile: "", 26 step: 1, 27 MarketingOptIn: false 28 }; 29 30 $scope.fireConversion = function () { 31 try { 32 $window.google_trackConversion({ 33 google_conversion_id: 968857083, 34 google_conversion_language: "en", 35 google_conversion_format: "3", 36 google_conversion_color: "ffffff", 37 google_conversion_label: "TDpuCLzkwGEQ-6v-zQM", 38 google_conversion_value: 0, 39 google_remarketing_only: false 40 }); 41 } 42 catch (err) 43 { 44 45 } 46 } 47 48 49 $scope.mobileValidation = { 50 token: "" 51 }; 52 $scope.getMobileValidationData = getMobileValidationData; 53 54 init(); 55 56 function init() { 57 if (typeof (registrationData) !== 'undefined') { 58 $scope.registration = registrationData 59 } 60 var path = $location.path(); 61 vm.page = path.charAt(path.length - 1); 62 63 inValUtils.addValidationConfiguration($scope, "registerFormPassword", { 64 pattern: "Password must contain minimum 8 characters and a combination of upper and lower case letters and digits", 65 required: "Password must contain minimum 8 characters and a combination of upper and lower case letters and digits" 66 }); 67 inValUtils.addValidationConfiguration($scope, "registerFormPasswordConfirm", { 68 mismatch: "'Password Confirmation' must match the 'Password' field" 69 }); 70 71 dpdUtils.addMobileNumberAjaxValidation($scope, $scope.getMobileValidationData); 72 dpdUtils.addFirstNameValidationMessageConfig($scope); 73 dpdUtils.addSurnameValidationMessageConfig($scope); 74 75 pageLoaded(); 76 } 77 function toStep2(evt) { 78 evt.preventDefault(); 79 $scope.registration.step = 2; 80 dpdCookies.putObject(cookieKey, $scope.registration, { expires: new Date().addDays(1) }); 81 $location.path('/step/2'); 82 } 83 function toStep3(evt) { 84 evt.preventDefault(); 85 $scope.registration.step = 3; 86 dpdCookies.putObject(cookieKey, $scope.registration, { expires: new Date().addDays(1) }); 87 $scope.fireConversion(); 88 $location.path('/step/3'); 89 } 90 91 function validateMobile(e) { 92 if (!dpdUtils.isEnterOrClick(e)) { 93 return; 94 } 95 96 e.preventDefault(); 97 98 //if (inValUtils.isFormValid($scope.mobileValidationForm) == false) { 99 // return false; 100 //} 101 102 inUiUtils.hideOverlay(); 103 //inUiUtils.showOverlay(); 104 105 $scope.errorMessage = ""; 106 $scope.message = ""; 107 108 109 $http.post(WebApiUrls.validateMobileToken, { token: $scope.mobileValidation.token }) 110 .success(function (data) { 111 inUiUtils.hideOverlay(); 112 113 if (!data.success) { 114 $scope.errorMessage = data.message; 115 } 116 else { 117 if (!window.location.origin) { 118 window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : ''); 119 } 120 121 window.location.replace(window.location.origin + '/'); 122 } 123 }) 124 .error(function (data) { 125 inUiUtils.hideOverlay(); 126 $scope.errorMessage = data.message; 127 }); 128 } 129 130 function resendMobileToken() { 131 inUiUtils.hideOverlay(); 132 //inUiUtils.showOverlay(); 133 134 $scope.errorMessage = ""; 135 $scope.message = ""; 136 137 //REFACTORING 138 $http.post(WebApiUrls.requestMobileValidationToken, {}) 139 .success(function (data) { 140 $scope.errorMessage = ""; 141 inUiUtils.hideOverlay(); 142 143 if (!data.success) { 144 $scope.errorMessage = data.message; 145 $scope.message = "Validation token sent." 146 } 147 else { 148 $scope.tokenSentToMobileNo = data.data; 149 $scope.message = "Validation token sent." 150 } 151 }) 152 .error(function (data) { 153 inUiUtils.hideOverlay(); 154 $scope.errorMessage = data.message; 155 }); 156 }; 157
158 function updateRegistrationDetails(e) { 159 if (e) e.preventDefault(); 160 161 if (!window.location.origin) { 162 window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : ''); 163 } 164 165 window.location.replace(window.location.origin + '/#/register/update'); 166 167 //pwaNavigation.redirectTo('/register/update'); 168 } 169 170 171 172 function getTemplateName() { 173 var step = $location.path().split("/").pop() || 1; 174 var tmpDafaultName = '/registrationStep-%s.tmpl.html'; 175 176 var template = tmpDafaultName.replace('%s', step); 177 return template; 178 } 179 180 function getMobileValidationData() { 181 return { 182 key: "phoneNumber", 183 value: $scope.registration.mobile,//$parse("registration.mobile")($scope), 184 caption: "Mobile", 185 dependencies: [{ 186 key: "isMobile", 187 value: true, 188 caption: "", 189 dependencies: [] 190 }] 191 }; 192 } 193 194 $scope.getPostcodeValidationData = function () { 195 return { 196 key: "description", 197 value: $parse("registration.postcode")($scope), 198 caption: "postcode", 199 dependencies: [{ 200 key: "county", 201 value: $parse("registration.county")($scope), 202 caption: "county" 203 }] 204 }; 205 } 206 207 $scope.init = function () { 208 //check if we're on the /register/update route, if so then pull current registration details 209 // if ($route.current.$$route.regexp.test(dpdUtils.getNgRelativePath(AppUrls.registerUpdate.route))) { 210 211 // dataservice.getRegistrationDetails() 212 // .then(onSuccess) 213 // .catch(onError); 214 //["finally"](pageLoaded); 215 216 function onSuccess(data) { 217 $scope.registration = data; 218 } 219 // } 220 221 dpdUtils.addMobileNumberAjaxValidation($scope, $scope.getMobileValidationData); 222 dpdUtils.addPostcodeAjaxValidation($scope, $scope.getPostcodeValidationData); 223 dpdUtils.addFirstNameValidationMessageConfig($scope); 224 dpdUtils.addSurnameValidationMessageConfig($scope); 225 226 inValUtils.addValidationConfiguration($scope, "registerFormEmailConfirm", { 227 mismatch: "'Email Confirmation' must match the 'Email' field" 228 }); 229 230 inValUtils.addValidationConfiguration($scope, "registerFormPassword", { 231 pattern: "Password must contain minimum 8 characters and a combination of upper and lower case letters and digits", 232 required: "Password must contain minimum 8 characters and a combination of upper and lower case letters and digits" 233 }); 234 235 inValUtils.addValidationConfiguration($scope, "registerFormPasswordConfirm", { 236 mismatch: "'Password Confirmation' must match the 'Password' field" 237 }); 238 239 inValUtils.addValidationConfiguration($scope, "registerFormTerms", { 240 required: "Please confirm that you have read our Terms and Conditions and Privacy Policy" 241 }); 242 //REFACTORING use anguylar.element 243 $(document).ready(function () { 244 $('.fieldRegister').blur(function () { 245 if ($(this).val().length > 0) { 246 dpdUtils.sendGoogleAnalyticsEvent('completed', 'blur:' + $(this).attr('name')); 247 } 248 else { 249 dpdUtils.sendGoogleAnalyticsEvent('skipped', 'blur:' + $(this).attr('name')); 250 } 251 }); 252 $('.fieldRegister').focus(function () { 253 if (!$(this).is(':checkbox')) { 254 dpdUtils.sendGoogleAnalyticsEvent('focused', $(this).attr('name')); 255 } 256 }); 257 $('input:checkbox.fieldRegister').click(function () { 258 dpdUtils.sendGoogleAnalyticsEvent('focused', $(this).attr('name')); 259 }); 260 }); 261 262 pageLoaded(); 263 }; 264 265 $scope.register = function (e) { 266 if (!dpdUtils.isEnterOrClick(e)) { 267 return; 268 } 269 270 e.preventDefault(); 271 272 if (inValUtils.isFormValid($scope.registrationForm) == false) { 273 //TODO: send GA event "invalid reg validation" 274 return false;
275 } 276 else { 277 //TODO: send GA event "valid registration form" 278 } 279 280 inUiUtils.hideOverlay(); 281 //inUiUtils.showOverlay(); 282 283 $scope.errorMessage = ""; 284 //REFACTORING move to dataservice 285 $http.post(WebApiUrls.register, $scope.registration) 286 .success(function (data) { 287 $scope.errorMessage = ""; 288 289 if (!data.success) { 290 $scope.errorMessage = data.message; 291 } 292 else { 293 navigation.redirectTo("EmailValidationInfo"); 294 } 295 296 inUiUtils.hideOverlay(); 297 }).error(function (data, status) { 298 $scope.errorMessage = data.message; 299 300 inUiUtils.hideOverlay(); 301 }); 302 } 303 304 //set postcode mandatory if NI county selected 305 $scope.$watch("registration.county", function (newVal, oldVal) { 306 if (newVal != oldVal) { 307 $scope.postcodeMandatory = dpdUtils.isNiCounty(newVal); 308 309 $($scope.txtPostcode).blur();//force the postcode re-validation 310 } 311 }); 312 313 $scope.getAdditionalInfoConfig = function () { 314 var retVal = { 315 show: false, 316 labelCaption: "" 317 }; 318 319 if ($scope.registration) { 320 if ($scope.registration.howHeardCode == 'Promo Code') { 321 retVal.show = true; 322 retVal.labelCaption = "Enter Here"; 323 retVal.dataType = "integer"; 324 } 325 else if ($scope.registration.howHeardCode == 'Radio') { 326 retVal.show = true; 327 retVal.labelCaption = "What Station?"; 328 } 329 else if ($scope.registration.howHeardCode == 'Press') { 330 retVal.show = true; 331 retVal.labelCaption = "What Publication?"; 332 } 333 else if ($scope.registration.howHeardCode == 'Friend') { 334 retVal.show = true; 335 retVal.labelCaption = "Name"; 336 } 337 else if ($scope.registration.howHeardCode == 'Other') { 338 retVal.show = true; 339 retVal.labelCaption = "Please specify"; 340 } 341 } 342 343 return retVal; 344 } 345 346 ////only allow entering integers for promo code 347 //$scope.$watch("registration.howHeardDesc", function (newVal, oldVal) { 348 // if (newVal && newVal != oldVal && $scope.registration.howHeardCode == "Promo Code") { 349 // newVal = newVal.toString().trim(); 350 351 // if (/^\d+$/.test(newVal)==false) { 352 // inValUtils.setTooltipMessage($scope.txtHowHeardDesc, "Promo code must be a whole number"); 353 // $timeout(function () { 354 // $($scope.txtHowHeardDesc).tooltip("show"); 355 // }, 100); 356 357 // } 358 // else { 359 // $($scope.txtHowHeardDesc).tooltip("hide"); 360 // } 361 // } 362 //}); 363 364 // private fn 365 function pageLoaded() { 366 inUiUtils.hideOverlay(); 367 } 368 369 function onError(data) { 370 $scope.errorMessage = data.message; 371 } 372 } 373})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.