define(['angular'], function (angular) { var HaveYourSay = angular.module('haveYourSay', []) HaveYourSay.controller('haveYourSayController', ['$scope', '$http', function ($scope, $http) { $scope.haveYourSay = { Type: null, Category: null, PolicyNumber: '', Name: '', ContactNumber: '', Email: '', Comment: '', Ref: null, ReCaptchaValue: '' }; $scope.loadingNext = false; $scope.showThankYou = false; $scope.SubmitHaveYourSay = function () { $scope.loadingNext = true; grecaptcha.execute(_recaptchaKey, { action: 'haveYourSay' }) .then(function (token) { $http({ method: 'POST', url: '/haveYourSayBlock/SubmitHaveYourSay', data: { data: $scope.haveYourSay, token: token } }).then(function (data) { if (data.data !== "invalidcaptcha") { $scope.ClearForm(data.data); $scope.showThankYou = true; } $scope.loadingNext = false; }, function () { $scope.loadingNext = false; }); }); }; $scope.ClearForm = function (response) { $scope.loadingNext = false; $scope.haveYourSay = { Type: null, Category: null, PolicyNumber: '', Name: '', ContactNumber: '', Email: '', Comment: '', Ref: response }; $scope.HaveYourSayForm.$setPristine(); }; $scope.NewQuery = function () { $scope.showThankYou = false; $scope.haveYourSay.Ref = null; }; $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 HaveYourSay; });