'use strict'; angular .module('customerLogin') .component('newAccount', { templateUrl: 'tmpl/newaccount/new-account.html?session=iaWbUNrlMbXobjwRRoxWBpxhFvnpkaVv', controllerAs: 'NewAccountCtrl', controller: ['$rootScope', '$routeParams', '$scope', '$location', '$kWindow', 'AuthService', 'AUTH_STATUS', NewAccountController] }); function NewAccountController($rootScope, $routeParams, $scope, $location, $kWindow, AuthService, AUTH_STATUS) { var self = this; self.dsTitle = [{ id: "Mr", value: "Mr" }, { id: "Mrs", value: "Mrs" }, { id: "Miss", value: "Miss" }, { id: "Ms", value: "Ms" }, { id: "Dr", value: "Dr" }, { id: "Prof", value: "Prof" }]; self.application = { cTitle: "Mr", cFirstname: "", cSurname: "", cCompanyName: "", cEmailAddress: "", cTelephone: "", cPostcode: "", cReCaptchaPass: "" } angular.element(document).ready(function () { $("#cFirstname").select(); }); self.changeView = function (view) { $location.path(view); }; self.viewName = "New Account"; self.companyLogo = "/WMS-Web-Live/img/company-logo.png"; self.validateApplication = function () { if ($.trim(self.application.cFirstname) == "") { self.showErrorMsg("Error", "Please enter a valid firstname.", "cFirstname", false); } else if ($.trim(self.application.cSurname) == "") { self.showErrorMsg("Error", "Please enter a valid surname.", "cSurname", false); } else if ($.trim(self.application.cCompanyName) == "") { self.showErrorMsg("Error", "Please enter a valid company name.", "cCompanyName", false); } else if ($.trim(self.application.cEmailAddress) == "" || !self.application.cEmailAddress) { self.showErrorMsg("Error", "Please enter a valid email address.", "cEmailAddress", false); } else if ($.trim(self.application.cTelephone) == "") { self.showErrorMsg("Error", "Please enter a valid telephone number.", "cTelephone", false); } else if ($.trim(self.application.cPostcode) == "") { self.showErrorMsg("Error", "Please enter a valid postcode.", "cPostcode", false); } else if ($('#g-recaptcha-response').val() == '') { self.showErrorMsg("Error", "Please select reCAPTCHA tickbox", ""); } else { self.application.cReCaptchaPass = $('#g-recaptcha-response').val(); AuthService.submitApplication(self.application).then(function () { if (AuthService.status == AUTH_STATUS.success) { self.initApplication(); self.showErrorMsg("Your Application Received", AuthService.cErrorMsg, "", true); self.changeView('/login'); } else if (AuthService.status == AUTH_STATUS.error) { self.initApplication(); self.showErrorMsg("Error", AuthService.cErrorMsg, "", true); self.changeView('/login'); } }, function () { self.initApplication(); self.showErrorMsg("Login", "New account request failed.", "", true); self.changeView('/login'); }); } }; self.cancelRequest = function () { $rootScope.$broadcast('CancelNewAccount'); } self.reloadLoginPage = function(){ $rootScope.$broadcast('ReloadLoginPage'); } self.showErrorMsg = function (pcTitle, pcErrorMsg, pcField, plReload) { var errorMsgWinHdl = $kWindow.open({ options: { modal: true, title: pcTitle, resizable: true, height: 'auto', width: 400, visible: false }, templateUrl: '../lib/htmls/errormsg.template.html', controllerAs: 'error', controller: ['$windowInstance', 'message', function ErrorMsgContoller($errorMsgWinHdl, pcErrorMsg) { this.message = pcErrorMsg; this.btnOK = function () { $errorMsgWinHdl.close(true); if (pcField != "") $("#" + pcField).select(); if (plReload == true) self.reloadLoginPage(); }; }], resolve: { message: function () { return pcErrorMsg; } } }); }; self.initApplication = function () { self.application = { cTitle: "Mr", cFirstname: "", cSurname: "", cCompanyName: "", cEmailAddress: "", cTelephone: "", cPostcode: "", cReCaptchaPass: "" } } } var resetNACaptcha = function () { grecaptcha.reset('notarobotNA'); }