define(['angular'], function (angular) { var qq = angular.module('quickquote', []) qq.controller('QuickQuoteController', ['$scope', '$http', function ($scope, $http) { $scope.QuickQuote = {}; $scope.QuickQuote.UseGoogleAddress = true; //for car model autocomplete. TODO: replace with directive $scope.carAutocompleteFormatter = function carAutocompleteFormatter(value) { if (value && value.Description) { return value.Description.replace(value.Year + ' ', ''); } else { return value; } } $scope.SubmitQuickQuote = function () { $scope.QuickQuoteResults = null; $http({ method: 'POST', url: '/Quote/QuickQuoteBlock/ProcessQuickQuote', data: { quickQuote: $scope.QuickQuote }, headers: { 'RequestVerificationToken': $scope.antiForgeryToken } }).success(function (data) { $scope.QuoteStarting = false; $scope.QuickQuoteResults = data.quoteModel; $scope.ReferenceNumber = data.referenceNumber; }).error(function () { }); }; function validateAddress(nv) { var hasPolicies = !!($scope.RiskAddresses && $scope.RiskAddresses.length); var address = !!(nv && nv.SuburbName && nv.PostCode); var valid; if (hasPolicies) { valid = address || $scope.QuickQuote.SelectedRiskAddress != "Other"; } else { valid = address; } if ($scope.QuickQuoteForm && $scope.QuickQuoteForm.RiskAddress && $scope.QuickQuote.UseGoogleAddress) { $scope.QuickQuoteForm.RiskAddress.$setValidity('required', valid); $scope.QuickQuoteForm.RiskAddress.$setValidity('autocomplete', valid); } else if ($scope.QuickQuoteForm) { $scope.QuickQuoteForm.RiskAddress.$setValidity('required', true); $scope.QuickQuoteForm.RiskAddress.$setValidity('autocomplete', true); } } $scope.$watch("QuickQuote.RiskAddress", validateAddress, true); function blankAddress() { return { "AccessControlledArea": null, "Address1": null, "Address2": null, "Address3": null, "AreaType": null, "PostalAddressSame": null, "PostCode": null, "ReferenceNumber": null, "SuburbName": null, "SuburbSequence": 0, "AddressLattitude": 0, "AddressLongitude": 0 }; } //for suburb autocomplete. TODO: replace with directive $scope.suburbAutocompleteFormatter = function suburbAutocompleteFormatter(value) { if (value && value.SuburbName) { return "" + value.SuburbName + ' ' + value.PostCode; } else { return ""; } } $scope.ToggleAddressSearch = function () { if ($scope.QuickQuote.UseGoogleAddress) $scope.QuickQuote.RiskAddress = undefined; else $scope.QuickQuote.RiskAddress = {}; $scope.QuickQuote.UseGoogleAddress = !$scope.QuickQuote.UseGoogleAddress; validateAddress(); }; $scope.QuickQuote.RiskAddress = blankAddress(); }]); qq.controller('QuickQuoteDirectController', ['$scope', '$http', 'Helpers', '$timeout', function ($scope, $http, Helpers, $timeout) { // First Init code // Initialise the QuickQuote State with the Viewmodel from the server $scope.QuickQuoteState = GetQuickQuoteState(); $scope.QuickQuoteState.UseGoogleAddress = true; $scope.QuickQuoteState.Step = 'details'; $scope.LoadingNext = false; $scope.ConsultantSuccess = false; if (sessionStorage.getItem("SweptClient") == null) sessionStorage.setItem("SweptClient", false); //new min and max values based on what george gave me $scope.QuickQuoteState.HomeContentMinValue = $scope.QuickQuoteState.HomeMinMax.MinValue; $scope.QuickQuoteState.HomeContentMaxValue = $scope.QuickQuoteState.HomeMinMax.MaxValue; $scope.QuickQuoteState.BuildingMinValue = $scope.QuickQuoteState.BuildingMinMax.MinValue; $scope.QuickQuoteState.BuildingMaxValue = $scope.QuickQuoteState.BuildingMinMax.MaxValue; hiddenprop($scope, "CurrentCarDriverLicenseIssueDate", function () { var dly = ''; var dlm = ''; if ($scope.QuickQuoteState.IdNumber && $scope.CurrentDriverBirthDate) { dly = $scope.CurrentDriverBirthDate.getFullYear() && $scope.QuickQuoteState.VehicleLicenceYearIssued, dlm = $scope.CurrentDriverBirthDate.getMonth() && $scope.QuickQuoteState.VehicleLicenceMonthIssued; } if (!dly || !dlm) return null; return new Date(dly, dlm - 1); }); hiddenprop($scope, "CurrentMotorDriverLicenseIssueDate", function () { var dly = ''; var dlm = ''; if ($scope.QuickQuoteState.IdNumber && $scope.CurrentDriverBirthDate) { dly = $scope.CurrentDriverBirthDate.getFullYear() && $scope.QuickQuoteState.MotorLicenceYearIssued, dlm = $scope.CurrentDriverBirthDate.getMonth() && $scope.QuickQuoteState.MotorLicenceMonthIssued; } if (!dly || !dlm) return null; return new Date(dly, dlm - 1); }); hiddenprop($scope, "CurrentDriverBirthDate", function () { var bd = ""; if ($scope.QuickQuoteState.IdNumber != null) { bd = Helpers.getIdNumberBirthdate($scope.QuickQuoteState.IdNumber); } return bd; }); $scope.QuickQuoteState.DiscountInProgress = true; var discountGroups = { g1: { //motor and building message: '', Vehicle: true, Home: false, Building: true }, g2: { //motor and home message: '', Vehicle: true, Home: true, Building: false }, g3: { //building and home message: '', Vehicle: false, Home: true, Building: true }, g4: { //motor, building and home message: '', Vehicle: true, Home: true, Building: true } }; //functions function validateCarEventDate(eventDate) { var returnObject = { CarValid: true, CarFuture: true, CarBeforeLicenseDate: true, CarLicenseDateBeforeBirth: true }; if (!eventDate) { returnObject.CarValid = true; return returnObject; } else { //Create date var now = new Date(); var license = $scope.CurrentCarDriverLicenseIssueDate; var birth = $scope.CurrentDriverBirthDate returnObject.CarValid = true; if (eventDate > now) { returnObject.CarValid = false; returnObject.CarFuture = false; return returnObject; } if (returnObject.CarValid && license && eventDate < license) { returnObject.CarValid = false; returnObject.CarBeforeLicenseDate = false; return returnObject; } if (returnObject.CarValid && birth) { var requiredAge = 18; var date18 = new Date(birth.getFullYear() + requiredAge, birth.getMonth(), 1); if (eventDate < date18) { returnObject.CarValid = false; returnObject.CarLicenseDateBeforeBirth = false; return returnObject; } } } return returnObject; } //functions function validateMotorEventDate(eventDate) { var returnObject = { MotorValid: true, MotorFuture: true, MotorBeforeLicenseDate: true, MotorLicenseDateBeforeBirth: true }; if (!eventDate) { returnObject.MotorValid = true; return returnObject; } else { //Create date var now = new Date(); var license = $scope.CurrentMotorDriverLicenseIssueDate; var birth = $scope.CurrentDriverBirthDate returnObject.MotorValid = true; if (eventDate > now) { returnObject.MotorValid = false; returnObject.MotorFuture = false; return returnObject; } if (returnObject.MotorValid && license && eventDate < license) { returnObject.MotorValid = false; returnObject.MotorBeforeLicenseDate = false; return returnObject; } if (returnObject.MotorValid && birth) { var requiredAge = 18; var date18 = new Date(birth.getFullYear() + requiredAge, birth.getMonth(), 1); if (eventDate < date18) { returnObject.MotorValid = false; returnObject.MotorLicenseDateBeforeBirth = false; return returnObject; } } } return returnObject; } function validateCarDateBasedControls(eventDate) { var validObject = validateCarEventDate(eventDate); for (var i = 1; i < arguments.length; i++) { for (var key in validObject) { if (arguments[i] && arguments[i].$setValidity) { arguments[i].$setValidity(key, validObject[key]); } } } } function validateMotorDateBasedControls(eventDate) { var validObject = validateMotorEventDate(eventDate); for (var i = 1; i < arguments.length; i++) { for (var key in validObject) { if (arguments[i] && arguments[i].$setValidity) { arguments[i].$setValidity(key, validObject[key]); } } } } function validateMotorLicenseDate() { var eventDate = $scope.CurrentMotorDriverLicenseIssueDate; validateMotorDateBasedControls(eventDate, $scope.QuickQuoteMotorcycleForm.MotorLicenceYear, $scope.QuickQuoteMotorcycleForm.MotorLicenceMonth); } function validateCarLicenseDate() { var eventDate = $scope.CurrentCarDriverLicenseIssueDate; validateCarDateBasedControls(eventDate, $scope.QuickQuoteCarForm.VehicleLicenceYear, $scope.QuickQuoteCarForm.VehicleLicenceMonth); } $scope.$watch("QuickQuoteState.MotorLicenceYearIssued", validateMotorLicenseDate); $scope.$watch("QuickQuoteState.MotorLicenceMonthIssued", validateMotorLicenseDate); $scope.$watch("QuickQuoteState.VehicleLicenceYearIssued", validateCarLicenseDate); $scope.$watch("QuickQuoteState.VehicleLicenceMonthIssued", validateCarLicenseDate); //for suburb autocomplete. TODO: replace with directive $scope.suburbAutocompleteFormatter = function suburbAutocompleteFormatter(value) { if (value && value.SuburbName) { return "" + value.SuburbName + ' ' + value.PostCode; } else { return ""; } } //Check that a risk item has been selected function selectionChanged(v) { $scope.DiscountGroups = []; $scope.QuickQuoteState.DiscountsActiveCount = 0; group4Message = ''; if ((discountGroups.g2.Vehicle != ($scope.QuickQuoteState.Motorcycle || $scope.QuickQuoteState.Car) || discountGroups.g2.Home != $scope.QuickQuoteState.Home) && discountGroups.g2.Building == $scope.QuickQuoteState.Building) { var riskItem = $scope.QuickQuoteState.Motorcycle || $scope.QuickQuoteState.Car ? 'Home Contents' : 'Car'; discountGroups.g2.message = 'Add ' + riskItem + ' insurance and save 20% on your total premium'; $scope.DiscountGroups.push(discountGroups.g2); } if ((discountGroups.g1.Vehicle != ($scope.QuickQuoteState.Motorcycle || $scope.QuickQuoteState.Car) || discountGroups.g1.Building != $scope.QuickQuoteState.Building) && (discountGroups.g1.Home == $scope.QuickQuoteState.Home)) { var riskItem = $scope.QuickQuoteState.Motorcycle || $scope.QuickQuoteState.Car ? 'Building' : 'Car'; discountGroups.g1.message = 'Add ' + riskItem + ' insurance and save 15% on your total premium'; $scope.DiscountGroups.push(discountGroups.g1); } if ((discountGroups.g3.Vehicle == ($scope.QuickQuoteState.Motorcycle || $scope.QuickQuoteState.Car)) && (discountGroups.g3.Building != $scope.QuickQuoteState.Building || discountGroups.g3.Home != $scope.QuickQuoteState.Home)) { var riskItem = $scope.QuickQuoteState.Home ? 'Building' : 'Home Contents'; discountGroups.g3.message = 'Add ' + riskItem + ' insurance and save 25% on your total premium'; $scope.DiscountGroups.push(discountGroups.g3); } if (discountGroups.g4.Vehicle != ($scope.QuickQuoteState.Motorcycle || $scope.QuickQuoteState.Car) || discountGroups.g4.Home != $scope.QuickQuoteState.Home || discountGroups.g4.Building != $scope.QuickQuoteState.Building) { group4Message = determineGroup4Message(); discountGroups.g4.message = 'Add ' + group4Message + ' insurance and save 30% on your total premium'; $scope.DiscountGroups.push(discountGroups.g4); } $scope.QuickQuoteState.DiscountsActiveCount = $scope.DiscountGroups.length; var any = $scope.QuickQuoteState.Car || $scope.QuickQuoteState.Home || $scope.QuickQuoteState.Building || $scope.QuickQuoteState.Motorcycle || v || false; $scope.riskSelection = !any; } var determineGroup4Message = function () { var carOrMotorcycle = $scope.QuickQuoteState.Motorcycle || $scope.QuickQuoteState.Car; var carHome = discountGroups.g4.Vehicle != carOrMotorcycle && discountGroups.g4.Home != $scope.QuickQuoteState.Home; var carBuilding = discountGroups.g4.Vehicle != carOrMotorcycle && discountGroups.g4.Building != $scope.QuickQuoteState.Building; var homeBuilding = discountGroups.g4.Home != $scope.QuickQuoteState.Home && discountGroups.g4.Building != $scope.QuickQuoteState.Building && discountGroups.g4.Vehicle == carOrMotorcycle; var homeOnly = discountGroups.g4.Home != $scope.QuickQuoteState.Home && discountGroups.g4.Building == $scope.QuickQuoteState.Building && discountGroups.g4.Vehicle == carOrMotorcycle; var buildingOnly = discountGroups.g4.Home == $scope.QuickQuoteState.Home && discountGroups.g4.Building != $scope.QuickQuoteState.Building && discountGroups.g4.Vehicle == carOrMotorcycle; var carOnly = discountGroups.g4.Home == $scope.QuickQuoteState.Home && discountGroups.g4.Building == $scope.QuickQuoteState.Building && discountGroups.g4.Vehicle != carOrMotorcycle; if (carHome) return 'Car and Home Contents'; else if (carBuilding) return 'Car and Building'; else if (homeBuilding) return 'Home Contents and Building'; else if (homeOnly) return 'Home Contents'; else if (buildingOnly) group4Message = 'Building'; else if (carOnly) return 'Car'; else return ''; }; $scope.vehicleAutocomplete = function () { $scope.QuickQuoteState.Vehicle = undefined; } $scope.addDiscount = function (value) { $scope.QuickQuoteState.Car = value.Vehicle; $scope.QuickQuoteState.Home = value.Home; $scope.QuickQuoteState.Building = value.Building; } $scope.$watch("QuickQuoteState.Car", selectionChanged); $scope.$watch("QuickQuoteState.Home", selectionChanged); $scope.$watch("QuickQuoteState.Building", selectionChanged); $scope.$watch("QuickQuoteState.Motorcycle", selectionChanged); //for motorcycle model autocomplete. TODO: replace with directive $scope.motorcycleAutocompleteFormatter = function motorcycleAutocompleteFormatter(value) { if (value && value.Description) { return value.Description; } else { return value; } } // Init the quick quote header $scope.QuickQuoteStepHeader = { ShowLoader: false, MainHeading: 'Online insurance quote' }; // Init the list of risk addresses if the user is logged in and has any risk addresses on his/her policy $scope.RiskAddresses = GetRiskAddresses(); // Add "empty" or other address option if the user wishes to type in a new address var otherOption = { Address1: 'Other' }; if ($scope.RiskAddresses !== undefined && $scope.RiskAddresses !== null) $scope.RiskAddresses.push(otherOption); $scope.getQuickQuoteContinueUrl = function (coverType) { var url = '/quote/' + $scope.QuickQuoteState.Results.ReferenceNumberDisplay + '/?' + 'idNumber=' + $scope.QuickQuoteState.Results.IdnumberEncrypted; if (coverType) url += '&coverType=' + coverType; if ($scope.QuickQuoteState.Building) url += '&building=' + $scope.QuickQuoteState.Building; if ($scope.QuickQuoteState.Home) url += '&home=' + $scope.QuickQuoteState.Home; if ($scope.QuickQuoteState.Motorcycle) url += '&motorcycle=' + $scope.QuickQuoteState.Motorcycle; return url; } //for car model autocomplete. TODO: replace with directive $scope.carAutocompleteFormatter = function carAutocompleteFormatter(value) { if (value && value.Description) { return value.Description.replace(value.Year + ' ', ''); } else { return value; } }; $scope.ConsultantText = "Ask for a call back"; $scope.Consultant = function () { if ($scope.ConsultantSuccess || $scope.sendRequest) return; $scope.sendRequest = true; $http({ method: 'POST', url: '/QuickQuote/Consultant', data: $scope.QuickQuoteState }).then(function (data) { $scope.index = data.data; $scope.sendRequest = false; if (data.data.result == 'success') { $scope.ConsultantSuccess = true; $scope.ConsultantText = "Request sent"; } }); }; $scope.SubmitQuickQuote = function () { $scope.QuickQuoteState.Results = null; $scope.QuickQuoteStepHeader.ShowLoader = true; $scope.QuickQuoteStepHeader.MainHeading = "Online insurance quote"; $scope.QuickQuoteStepHeader.SubTextHeading = "In a moment you'll receive a tailor-made quote, just for you."; if ($scope.RiskAddresses && $scope.RiskAddresses.length > 0 && ($scope.QuickQuoteState.SelectedRiskAddress && $scope.QuickQuoteState.SelectedRiskAddress.Address1 != "Other")) { $scope.QuickQuoteState.RiskAddress = $scope.QuickQuoteState.SelectedRiskAddress; } if (!$scope.QuickQuoteState.Car) { $scope.QuickQuoteState.VehicleLicenceMonthIssued = undefined; $scope.QuickQuoteState.VehicleLicenceYearIssued = undefined; $scope.QuickQuoteState.Vehicle = undefined; $scope.QuickQuoteState.VehicleFinanced = undefined; } if (!$scope.QuickQuoteState.Building) { $scope.QuickQuoteState.BuildingValue = undefined; $scope.QuickQuoteState.BuildingFinanced = undefined; } if (!$scope.QuickQuoteState.Home) { $scope.QuickQuoteState.HomeLastClaimYear = undefined; $scope.QuickQuoteState.HomeContentValue = undefined; $scope.QuickQuoteState.HomeMovedInMonth = undefined; $scope.QuickQuoteState.HomeMovedInYear = undefined; } if (!$scope.QuickQuoteState.Motorcycle) { $scope.QuickQuoteState.MotorVehicle = undefined; $scope.QuickQuoteState.MotorLicenceMonthIssued = undefined; $scope.QuickQuoteState.MotorLicenceYearIssued = undefined; $scope.QuickQuoteState.MotorcycleValue = undefined; $scope.QuickQuoteState.MotorYearRegistered = undefined; $scope.QuickQuoteState.MotorFinanced = undefined; } if (!$scope.QuickQuoteState.Motorcycle && !$scope.QuickQuoteState.Car) { $scope.QuickQuoteState.LastClaimYear = null; } grecaptcha.ready(function () { grecaptcha.execute('6Lf_NY4UAAAAAGfHCg-dsNkl-Te1cWUR0aDq9zDp', { action: 'QuickQuote' }) .then(function (token) { $http({ method: 'POST', url: '/QuickQuote/Submit', data: { quickQuoteDetails: $scope.QuickQuoteState, token: token }, headers: { 'RequestVerificationToken': $scope.antiForgeryToken } }).success(function (data) { if (data.MustRedirect) { window.location = data.RedirectUrl; } else { $scope.InsuredItems = []; $scope.PremiumIncludes = []; $scope.QuoteStarting = false; $scope.QuickQuoteState.Step = 'summary'; $scope.QuickQuoteState.Results = data; $scope.QuickQuoteStepHeader.ShowLoader = false; $scope.QuickQuoteStepHeader.SubHeading = null; $scope.QuickQuoteStepHeader.SubTextHeading = null; var homeOnly = true; if ($scope.QuickQuoteState.Car) { $scope.PremiumIncludes.push('Comprehensive vehicle insurance'); $scope.PremiumIncludes.push('AutoSOS benefit'); $scope.PremiumIncludes.push('Windscreen cover'); $scope.PremiumIncludes.push('Hail cover'); $scope.InsuredItems.push({ Premium: $scope.QuickQuoteState.Results.CarPremiumDisplay, Description: $scope.QuickQuoteState.Vehicle.Description, BasicExcess: $scope.QuickQuoteState.Results.VehicleBasicExcess }); homeOnly = false; } if ($scope.QuickQuoteState.Motorcycle) { $scope.PremiumIncludes.push('Towing and storage by an approved towline due to an accident'); $scope.PremiumIncludes.push('Cover against theft or accidental damage'); $scope.InsuredItems.push({ Premium: $scope.QuickQuoteState.Results.MotorcyclePremiumDisplay, Description: $scope.QuickQuoteState.MotorVehicle.Description, BasicExcess: $scope.QuickQuoteState.Results.MotorcycleBasicExcess }); homeOnly = false; } if ($scope.QuickQuoteState.Home) { $scope.PremiumIncludes.push('Replacement of lost bank cards'); $scope.PremiumIncludes.push('Veterinary expenses'); $scope.InsuredItems.push({ Premium: $scope.QuickQuoteState.Results.HomePremiumDisplay, Description: 'Home Contents', BasicExcess: $scope.QuickQuoteState.Results.HomeContentBasicExcess }); } if ($scope.QuickQuoteState.Building) { $scope.PremiumIncludes.push('Cover in the event of a storm or flooding'); $scope.PremiumIncludes.push('Replacements for damaged locks and keys if your house is broken in to'); $scope.InsuredItems.push({ Premium: $scope.QuickQuoteState.Results.BuildingPremiumDisplay, Description: 'Building', BasicExcess: $scope.QuickQuoteState.Results.BuildingBasicExcess }); homeOnly = false; //$scope.InsuredItems.insuredCar.Premium = $scope.QuickQuoteState.Results.BuildingPremiumDisplay; //$scope.InsuredItems.insuredCar.Description = 'Building'; //$scope.InsuredItems.insuredCar.BasicExcess = $scope.QuickQuoteState.Results.BuildingBasicExcess; } $scope.hasAdminFee = false; for (var i = 0; i < $scope.QuickQuoteState.Results.SasriaDialog.length; i++) { var val = $scope.QuickQuoteState.Results.SasriaDialog[i]; if (val.match(/admin fee/ig)) { $scope.hasAdminFee = true; } } $scope.InsuredItems.push({ Premium: $scope.QuickQuoteState.Results.TotalAdminFeesPremiumDisplay, Description: ($scope.hasAdminFee ? homeOnly ? 'Admin Fee' : 'Sasria & Admin Fee' : 'Sasria'), BasicExcess: "N\\A" }); if ($scope.QuickQuoteState.Car && $scope.QuickQuoteState.VehicleFinanced == "N") { var premium = $scope.QuickQuoteState.Results.TotalPremium - $scope.QuickQuoteState.Results.CarPremium; $scope.ThirdPartyOnly = (premium + $scope.QuickQuoteState.Results.TotalThirdPartyOnlyPremium).toFixed(2); $scope.ThirdPartyFireTheft = (premium + $scope.QuickQuoteState.Results.TotalThirdPartyFireTheftPremium).toFixed(2); } } }).error(function () { $scope.QuickQuoteStepHeader.ShowLoader = false; $scope.QuickQuoteStepHeader.SubHeading = null; $scope.QuickQuoteStepHeader.SubTextHeading = null; }); }); }); }; function validateAddress(nv) { var hasPolicies = !!($scope.RiskAddresses && $scope.RiskAddresses.length); var address = !!(nv && nv.SuburbName && nv.PostCode); var valid; if (hasPolicies) { valid = address || ($scope.QuickQuoteState.SelectedRiskAddress && $scope.QuickQuoteState.SelectedRiskAddress.Address1 != "Other"); } else { valid = address; } if ($scope.QuickQuotePersonalForm && $scope.QuickQuotePersonalForm.RiskSuburb && $scope.QuickQuoteState.UseGoogleAddress) { $scope.QuickQuotePersonalForm.RiskSuburb.$setValidity('required', valid); $scope.QuickQuotePersonalForm.RiskSuburb.$setValidity('autocomplete', valid); } else if ($scope.QuickQuotePersonalForm && $scope.QuickQuotePersonalForm.RiskSuburb) { $scope.QuickQuotePersonalForm.RiskSuburb.$setValidity('required', true); $scope.QuickQuotePersonalForm.RiskSuburb.$setValidity('autocomplete', true); } } $scope.$watch("QuickQuoteState.Suburb", validateAddress, true); $scope.clearAddress = function () { $scope.QuickQuoteState.RiskAddress = blankAddress(); }; function blankAddress() { return { "AccessControlledArea": null, "Address1": null, "Address2": null, "Address3": null, "AreaType": null, "PostalAddressSame": null, "PostCode": null, "ReferenceNumber": null, "SuburbName": null, "SuburbSequence": 0, "AddressLattitude": 0, "AddressLongitude": 0 }; } //for suburb autocomplete. TODO: replace with directive $scope.suburbAutocompleteFormatter = function suburbAutocompleteFormatter(value) { if (value && value.SuburbName) { return "" + value.SuburbName + ' ' + value.PostCode; } else { return ""; } } $scope.ToggleAddressSearch = function () { if ($scope.QuickQuoteState.UseGoogleAddress) $scope.QuickQuoteState.RiskAddress = undefined; else $scope.QuickQuoteState.RiskAddress = {}; $scope.QuickQuoteState.UseGoogleAddress = !$scope.QuickQuoteState.UseGoogleAddress; }; // Final variable inits // Set RiskAddress to blankAddress to prevent null property javascript issues $scope.QuickQuoteState.RiskAddress = blankAddress(); function idLuhnChck(idNumber) { var digits = new Array(12); for (var i = 0; i < 12; i++) digits[i] = parseFloat(idNumber[i]); var a = digits[0] + digits[2] + digits[4] + digits[6] + digits[8] + digits[10]; var b = digits[1] * 100000 + digits[3] * 10000 + digits[5] * 1000 + digits[7] * 100 + digits[9] * 10 + digits[11]; var cs = (b * 2).toString(), c = 0; for (var i = 0; i < cs.length; i++) c += parseFloat(cs[i]); var d = a + c; var z = (10 - (d % 10)) % 10; return z; } // !function (n, r, e, t, u) { n.magicalness = function () { var n = function (n) { return function (r, e) { return t(n() * ( e - r + 1) + r); }; }(u), i = n(80, 90), o = n(1, 12), c = n(1, 28), a = n(0, 9999), f = 0, n = 8, h = function (n, r) { return n += "", n['length'] >= r ? n : new e(r - n.length + 1).join("0") + n; }, c = [h(i, 2), h(o, 2), h(c, 2), h(a, 4), h(f, 1), h(n, 1)].join(""), s = r(c); return c + s; } }($scope, idLuhnChck, Array, parseInt, Math.random); // //var getDefaultSuburb = function () { // return { // City: null, // DisplayName: "DAINFERN", // PostCode: "2191", // StreetDelivery: null, // SuburbName: "DAINFERN", // SuburbSequence: 2795, // Longitude: "28.00460400000000000", // Latitude: "-25.99333500000000000" // } //}; $scope.getLocation = function () { navigator.geolocation.getCurrentPosition(successCallback, errorCallback, { maximumAge: Infinity, timeout: 5000 }); function successCallback(position) { // By setting the 'maximumAge' to Infinity, the position // object is guaranteed to be a cached one. // By using a 'timeout' of 0 milliseconds, if there is // no cached position available at all, the user agent // will immediately invoke the error callback with code // TIMEOUT and will not initiate a new position // acquisition process. if (position.timestamp > new Date(Date.now() - 1 * 60 * 60 * 1000)) { var geocoder; geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); geocoder.geocode( { 'latLng': latlng }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[0]) { var add = results[0].formatted_address; var value = add.split(","); var count = value.length; var suburb = value[count - 4]; if (suburb.charAt(0) === ' ') { suburb = suburb.substr(1); } $http({ method: 'POST', url: '/quote/personal/GetSuburbExact', data: { suburbName: suburb, postalCode: value[count - 2] } }).success(function (data) { if ($scope.currentLocationSub != {} && $scope.currentLocationSub.SuburbName == data.SuburbName) $scope.QuickQuoteState.Suburb = $scope.currentLocationSub; else $scope.currentLocationSub = data; $scope.enablecurrentlocation = true; }).error(function () { $scope.enablecurrentlocation = true; }); } } } ) } else { doFallback(); } } function errorCallback() { doFallback(); } function doFallback() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function (position) { var latitude = position.coords.latitude; var longitude = position.coords.longitude; var geocoder; geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(latitude, longitude); geocoder.geocode( { 'latLng': latlng }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[0]) { var add = results[0].formatted_address; var value = add.split(","); var count = value.length; var suburb = value[count - 4]; if (suburb.charAt(0) === ' ') { suburb = suburb.substr(1); } $http({ method: 'POST', url: '/quote/personal/GetSuburbExact', data: { suburbName: suburb, postalCode: value[count - 2] } }).success(function (data) { if ($scope.currentLocationSub != {} && $scope.currentLocationSub.SuburbName == data.SuburbName) $scope.QuickQuoteState.Suburb = $scope.currentLocationSub; else $scope.currentLocationSub = data; $scope.enablecurrentlocation = true; }).error(function () { $scope.enablecurrentlocation = true; }); } } } ) }); } } } $scope.currentLocationSub = {}; $scope.updateAddress = function () { if ($scope.currentLocationSub.DisplayName != null) $scope.QuickQuoteState.Suburb = $scope.currentLocationSub; } $scope.enablecurrentlocation = true; $scope.$watch("currentLocationSub", $scope.updateAddress, true); $scope.isActive = false; $scope.currentLocation = function () { if ($scope.enablecurrentlocation) { $scope.enablecurrentlocation = false; $scope.getSuburbLocation(); $scope.isActive = true; } }; $scope.sweepNumber = function () { $timeout.cancel($scope.sweepingDelay); if ($scope.QuickQuotePersonalForm && $scope.QuickQuotePersonalForm.firstName.$valid && $scope.QuickQuotePersonalForm.contactNumber.$valid && $scope.QuickQuoteState.TrueAndCorrect) { $scope.sweepingDelay = $timeout(function () { $http({ method: 'POST', url: '/QuickQuote/SweepNumber', data: { name: $scope.QuickQuoteState.FirstName, number: $scope.QuickQuoteState.ContactNumber } }); }, 5000); } }; $scope.$watch("QuickQuoteState.ContactNumber", $scope.sweepNumber, false); $scope.$watch("QuickQuoteState.FirstName", $scope.sweepNumber, false); $scope.$watch("QuickQuoteState.TrueAndCorrect", $scope.sweepNumber, false); //UpstreamDigital/AutoGen/issues/57 $scope.sweepClient = function () { if (!EnablePersonalLandingSweeping || sessionStorage.getItem("SweptClient") == "true") return; if ($scope.QuickQuotePersonalForm.firstName.$valid && $scope.QuickQuotePersonalForm.contactNumber.$valid) { sessionStorage.setItem("SweptClient", true); $http({ method: 'POST', url: "/CallMeBack/CallMeBack", data: { Name: $scope.QuickQuoteState.FirstName, ContactNumber: $scope.QuickQuoteState.ContactNumber } }).success(function (result) { console.log(result); }); } } $scope.QuickQuoteState.FirstName = $scope.QuickQuoteState && $scope.QuickQuoteState.FirstName || ((isDebugMode) ? "Bruce" : ""); $scope.QuickQuoteState.LastName = $scope.QuickQuoteState && $scope.QuickQuoteState.LastName || ((isDebugMode) ? "Wayne" : ""); $scope.QuickQuoteState.ContactNumber = $scope.QuickQuoteState && $scope.QuickQuoteState.ContactNumber || ((isDebugMode) ? "0821231234" : ""); $scope.QuickQuoteState.IdNumber = $scope.QuickQuoteState && $scope.QuickQuoteState.IdNumber || ((isDebugMode) ? $scope.magicalness() : ""); $scope.QuickQuoteState.EmailAddress = $scope.QuickQuoteState && $scope.QuickQuoteState.EmailAddress || ((isDebugMode) ? "dailrabbit_" + $scope.QuickQuoteState.IdNumber + "@yopmail.com" : ""); //$scope.QuickQuoteState.Suburb = $scope.QuickQuoteState && $scope.QuickQuoteState.Suburb || ((isDebugMode) ? getDefaultSuburb() : ""); $scope.QuickQuoteState.MaritalStatus = $scope.QuickQuoteState && $scope.QuickQuoteState.MaritalStatus || ((isDebugMode) ? "S" : ""); $scope.loadScript = function (url) { var script = document.createElement("script"); script.type = "text/javascript"; script.defer = "true"; script.src = url; document.getElementsByTagName("head")[0].appendChild(script); }; $scope.loadScript("https://www.google.com/recaptcha/api.js?render=6Lf_NY4UAAAAAGfHCg-dsNkl-Te1cWUR0aDq9zDp"); }]); return qq; });