define(['angular'], function (angular) { var Life = angular.module('life', []); Life.controller('LifeController', ['$scope', '$http', '$q', function ($scope, $http, $q) { $scope.QuoteStep = 1; $scope.LifeQuoteModel = {}; $scope.LifeQuoteModel.Personal = {}; $scope.QuoteResults = {}; $scope.LifeQuoteLoading = false; $scope.LifeQuoteModel.CoverDetails = ""; $scope.LifeQuoteModel.Income = ""; $scope.LifeQuoteModel.Education = ""; $scope.LifeQuoteModel.SmokerStatus = ""; $scope.LifeQuoteModel.CoverValue = ""; $scope.EducationLevels = [{ value: 1, text: 'Less than Matric' }, { value: 2, text: 'Matric of Grade 12' }, { value: 3, text: 'Three Year Diploma' }, { value: 4, text: 'Four Year Diploma' }, { value: 5, text: 'Postgraduate' }]; $scope.MaritalStatus = [ { value: 'A', text: 'Separated' }, { value: 'D', text: 'Divorced' }, { value: 'M', text: 'Married' }, { value: 'P', text: 'Cohabiting/Partnered' }, { value: 'S', text: 'Single' }, { value: 'W', text: 'Widowed' } ] $scope.SelectedMaritalStatus = function(value) { var retVal = ""; for (i = 0; i < $scope.MaritalStatus.length; i++) { if($scope.MaritalStatus[i].value == value) { return $scope.MaritalStatus[i].text; } } return retVal; } $scope.Validity = { PersonalDetails: true }; $scope.$watch("PersonalForm.$valid", function (valid) { $scope.Validity.PersonalDetails = valid }) $scope.NextStep = function () { $scope.loadingNext = true; $scope.getQuote(); }; $scope.getQuote = function () { $scope.LifeQuoteLoading = true; grecaptcha.ready(function () { grecaptcha.execute('6Lf_NY4UAAAAAGfHCg-dsNkl-Te1cWUR0aDq9zDp', { action: 'LifeQuote' }) .then(function (token) { var data = { quoteModel: $scope.LifeQuoteModel, token: token }; $http.post("/quote/Life/GetQuote", data).then(function (results) { $scope.QuoteResults = results.data; $scope.LifeQuoteLoading = false; $scope.QuoteStep += 1; }); }); }); }; $scope.suburbAutocompleteFormatter = function suburbAutocompleteFormatter(value) { if (value && value.SuburbName) { return value.SuburbName + ' ' + value.PostCode; } else { return value; } }; $scope.occupationAutoCompleteFormatter = function occupationAutoCompleteFormatter(value) { if (value && value.Description) { return value.Description; } else { return value; } }; $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"); }]); });