[32796] | 1 | (function () {
|
---|
| 2 | angular.module('forms')
|
---|
| 3 | .controller('MembershipFormCtrl', ['$scope', '$document', '$window', function ($scope, $document, $window) {
|
---|
| 4 | // An object to hold all our form field values
|
---|
| 5 | $scope.frm = {};
|
---|
| 6 | $scope.frm.minimumDonationAmount = 100;
|
---|
| 7 | var nz = 'New Zealand';
|
---|
| 8 | $scope.frm.recaptcha = false; // THIS IS NEW
|
---|
| 9 |
|
---|
| 10 | $scope.frm.ApplicationTypes = ["New Membership", "Renew a Membership", "Gift a Membership", "Renew a Gift Membership"];
|
---|
| 11 | $scope.frm.ApplicationType = $scope.frm.ApplicationTypes[0]; // default selected
|
---|
| 12 |
|
---|
| 13 | $scope.$watch('beneficiaryCountryIsNZ()', function (isNz) {
|
---|
| 14 | if (isNz) {
|
---|
| 15 | $scope.frm.OverseasMagazinePostageIsRequired = false;
|
---|
| 16 | $scope.frm.OverseasMembershipCardIsRequired = false;
|
---|
| 17 | } else {
|
---|
| 18 | //after overseas price list introduced, the overseas postage is redundant
|
---|
| 19 | $scope.frm.OverseasMembershipCardIsRequired = false;
|
---|
| 20 | $scope.frm.ExpressServiceFeeIsRequired = false;
|
---|
| 21 | }
|
---|
| 22 | });
|
---|
| 23 |
|
---|
| 24 | $scope.$watch('frm.Country', function (newValue, oldValue) {
|
---|
| 25 | if ($scope.frm.ApplicationType == 'New Membership' || $scope.frm.ApplicationType == 'Renew a Membership') {
|
---|
| 26 | validateAfterCountryChange(newValue, oldValue);
|
---|
| 27 | } else return;
|
---|
| 28 | });
|
---|
| 29 |
|
---|
| 30 | $scope.$watch('frm.RecipientCountry', function (newValue, oldValue) {
|
---|
| 31 | if ($scope.frm.ApplicationType == 'Gift a Membership' || $scope.frm.ApplicationType == 'Renew a Gift Membership') {
|
---|
| 32 | validateAfterCountryChange(newValue, oldValue);
|
---|
| 33 | } else return;
|
---|
| 34 | });
|
---|
| 35 |
|
---|
| 36 | function validateAfterCountryChange(newValue, oldValue) {
|
---|
| 37 | if (oldValue == null) return;
|
---|
| 38 | if (newValue == oldValue) return;
|
---|
| 39 | if (newValue != nz && oldValue != nz) return;
|
---|
| 40 | $scope.frm.MembershipType = null;
|
---|
| 41 | $scope.checkIndividual();
|
---|
| 42 | $scope.showAfterCountryChgange = true;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | $scope.$watch('frm.MembershipType', function (newValue, oldValue) {
|
---|
| 46 | if (newValue == oldValue) return;
|
---|
| 47 | if (newValue != null && newValue != '')
|
---|
| 48 | $scope.showAfterCountryChgange = false;
|
---|
| 49 | $scope.checkIndividual();
|
---|
| 50 | });
|
---|
| 51 |
|
---|
| 52 | // RecipientCountry takes precidence over BillingCountry for Gift a Membership as
|
---|
| 53 | // the recipients panel is only shown when Gift a Membership is the chosen application type
|
---|
| 54 | $scope.beneficiaryCountryIsNZ = function () {
|
---|
| 55 | return $scope.frm.IsGiftTransaction() ? $scope.frm.RecipientCountry == nz : $scope.frm.Country == nz;
|
---|
| 56 | };
|
---|
| 57 |
|
---|
| 58 | // Gift or Gift renewals change validation logic so we need to be able to check what application type is currently active
|
---|
| 59 | $scope.frm.IsGiftTransaction = function () {
|
---|
| 60 | return $scope.frm.ApplicationType.toLowerCase().indexOf('gift') != -1;
|
---|
| 61 | };
|
---|
| 62 |
|
---|
| 63 | $scope.frm.total = function () {
|
---|
| 64 | var membershipTypePrice = parseInt($scope.frm.MembershipTypePrice, 10) || 0,
|
---|
| 65 | donationAmount = parseInt($scope.frm.DonationAmount, 10) || 0,
|
---|
| 66 | overseasMagazinePostageValue = $scope.frm.OverseasMagazinePostageIsRequired ? (parseInt($scope.frm.OverseasMagazinePostageValue, 10) || 0) : 0,
|
---|
| 67 | //overseasMembershipCardValue = $scope.frm.OverseasMembershipCardIsRequired ? (parseInt($scope.frm.OverseasMembershipCardValue, 10) || 0) : 0,
|
---|
| 68 | additionalOrReplacementCardValue = $scope.frm.AdditionalOrReplacementCardIsRequired ? (parseInt($scope.frm.AdditionalOrReplacementCardValue, 10) || 0) : 0,
|
---|
| 69 | expressServiceFeeValue = $scope.frm.ExpressServiceFeeIsRequired ? (parseInt($scope.frm.ExpressServiceFeeValue, 10) || 0) : 0;
|
---|
| 70 |
|
---|
| 71 | return membershipTypePrice + donationAmount + overseasMagazinePostageValue + additionalOrReplacementCardValue + expressServiceFeeValue;
|
---|
| 72 | };
|
---|
| 73 |
|
---|
| 74 | $scope.uncheckIfLessThanMinAmount = function () {
|
---|
| 75 | if ($scope.frm.DonationAmount < $scope.frm.minimumDonationAmount) {
|
---|
| 76 | $scope.frm.ExcludeDonationFromMagazine = false;
|
---|
| 77 | }
|
---|
| 78 | };
|
---|
| 79 |
|
---|
| 80 | $scope.formIsValid = function (form) {
|
---|
| 81 | return $scope.frm.recaptcha && form.$valid && $scope.frm.HasReadPolicy === true ? true : false;
|
---|
| 82 | };
|
---|
| 83 |
|
---|
| 84 | $scope.showConditionsError = function (form) {
|
---|
| 85 | return form.$valid && !$scope.formIsValid(form) ? true : false;
|
---|
| 86 | };
|
---|
| 87 |
|
---|
| 88 | $scope.displayTooltip = function (prop) {
|
---|
| 89 | $scope[prop] = !$scope[prop];
|
---|
| 90 |
|
---|
| 91 | if ($scope[prop]) {
|
---|
| 92 | $window.onclick = function (event) {
|
---|
| 93 | if (event.target.id != prop) {
|
---|
| 94 | $scope.$apply(function () {
|
---|
| 95 | $scope[prop] = false;
|
---|
| 96 | });
|
---|
| 97 | }
|
---|
| 98 | };
|
---|
| 99 | }
|
---|
| 100 | };
|
---|
| 101 |
|
---|
| 102 | $scope.checkIndividual = function() {
|
---|
| 103 | var result = $scope.frm.MembershipType != null && $scope.frm.MembershipType != '' && $scope.frm.JointMemberName != null && $scope.frm.JointMemberName != '' && $scope.frm.MembershipType.toLowerCase().indexOf('individual') != -1;
|
---|
| 104 | $scope.hptFrm.JointMemberName.$setValidity('individual', !result);
|
---|
| 105 | return result;
|
---|
| 106 | };
|
---|
| 107 |
|
---|
| 108 | $scope.setResponse = function (response) {
|
---|
| 109 | console.log(response);
|
---|
| 110 | $.ajax({
|
---|
| 111 | type: 'POST',
|
---|
| 112 | url: "/api/Validation/ReCaptcha",
|
---|
| 113 | data: "=" + response,
|
---|
| 114 | success: function (data) {
|
---|
| 115 | var res = JSON.parse(data);
|
---|
| 116 | console.log(res);
|
---|
| 117 | console.log(res.success);
|
---|
| 118 | if (res.success === true) {
|
---|
| 119 | $scope.frm.recaptcha = true;
|
---|
| 120 | $('#submitContainer').toggle("fast");
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 | });
|
---|
| 124 | };
|
---|
| 125 |
|
---|
| 126 | $scope.onExpire = function () {
|
---|
| 127 | $scope.frm.recaptcha = false;
|
---|
| 128 | $('#submitContainer').toggle("fast");
|
---|
| 129 |
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | }])
|
---|
| 133 | .controller('SubscriptionFormCtrl', ['$scope', '$window', function ($scope, $window) {
|
---|
| 134 | $scope.frm = {};
|
---|
| 135 | $scope.frm.minimumDonationAmount = 100;
|
---|
| 136 | $scope.frm.recaptcha = false; // THIS IS NEW
|
---|
| 137 |
|
---|
| 138 | $scope.frm.SubscriptionTypes = ["New Subscription", "Renew a Subscription", "Gift a Subscription", "Renew a Gift Subscription"];
|
---|
| 139 | $scope.frm.SubscriptionType = $scope.frm.SubscriptionTypes[0]; // default selected
|
---|
| 140 |
|
---|
| 141 | // RecipientCountry takes precidence over BillingCountry for Gift a Membership as
|
---|
| 142 | // the recipients panel is only shown when Gift a Membership is the chosen application type
|
---|
| 143 | $scope.beneficiaryCountryIsNZ = function () {
|
---|
| 144 | return $scope.frm.IsGiftTransaction() ? $scope.frm.RecipientCountry == 'New Zealand' : $scope.frm.Country == 'New Zealand';
|
---|
| 145 | };
|
---|
| 146 |
|
---|
| 147 | // Gift or Gift renewals change validation logic so we need to be able to check what application type is currently active
|
---|
| 148 | $scope.frm.IsGiftTransaction = function () {
|
---|
| 149 | return $scope.frm.SubscriptionType.toLowerCase().indexOf('gift') != -1;
|
---|
| 150 | };
|
---|
| 151 |
|
---|
| 152 | $scope.frm.total = function () {
|
---|
| 153 | var subscriptionAmount = parseInt($scope.frm.SubscriptionAmount, 10) || 0,
|
---|
| 154 | donationAmount = parseInt($scope.frm.DonationAmount, 10) || 0;
|
---|
| 155 |
|
---|
| 156 | return subscriptionAmount + donationAmount;
|
---|
| 157 | };
|
---|
| 158 |
|
---|
| 159 | $scope.uncheckIfLessThanMinAmount = function () {
|
---|
| 160 | if ($scope.frm.DonationAmount < $scope.frm.minimumDonationAmount) {
|
---|
| 161 | $scope.frm.ExcludeDonationFromMagazine = false;
|
---|
| 162 | }
|
---|
| 163 | };
|
---|
| 164 |
|
---|
| 165 | $scope.formIsValid = function (form) {
|
---|
| 166 | return $scope.frm.recaptcha && form.$valid && $scope.frm.HasReadPolicy === true ? true : false;
|
---|
| 167 | };
|
---|
| 168 |
|
---|
| 169 | $scope.showConditionsError = function (form) {
|
---|
| 170 | return form.$valid && !$scope.formIsValid(form) ? true : false;
|
---|
| 171 | };
|
---|
| 172 |
|
---|
| 173 | $scope.displayTooltip = function (prop) {
|
---|
| 174 | $scope[prop] = !$scope[prop];
|
---|
| 175 |
|
---|
| 176 | if ($scope[prop]) {
|
---|
| 177 | $window.onclick = function (event) {
|
---|
| 178 | if (event.target.id != prop) {
|
---|
| 179 | $scope.$apply(function () {
|
---|
| 180 | $scope[prop] = false;
|
---|
| 181 | });
|
---|
| 182 | }
|
---|
| 183 | };
|
---|
| 184 | }
|
---|
| 185 | };
|
---|
| 186 |
|
---|
| 187 | $scope.setResponse = function (response) {
|
---|
| 188 | console.log(response);
|
---|
| 189 | $.ajax({
|
---|
| 190 | type: 'POST',
|
---|
| 191 | url: "/api/Validation/ReCaptcha",
|
---|
| 192 | data: "=" + response,
|
---|
| 193 | success: function (data) {
|
---|
| 194 | var res = JSON.parse(data);
|
---|
| 195 | console.log(res);
|
---|
| 196 | console.log(res.success);
|
---|
| 197 | if (res.success === true) {
|
---|
| 198 | $scope.frm.recaptcha = true;
|
---|
| 199 | $('#submitContainer').toggle("fast");
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 | });
|
---|
| 203 | };
|
---|
| 204 |
|
---|
| 205 | $scope.onExpire = function () {
|
---|
| 206 | $scope.frm.recaptcha = false;
|
---|
| 207 | $('#submitContainer').toggle("fast");
|
---|
| 208 |
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | }])
|
---|
| 212 | .controller('DonationFormCtrl', ['$scope', '$timeout', '$window', 'vcRecaptchaService', function ($scope, $timeout, $window, recaptcha) {
|
---|
| 213 |
|
---|
| 214 | $scope.frm = {};
|
---|
| 215 | $scope.frm.minimumDonationAmount = 100;
|
---|
| 216 | $scope.frm.recaptcha = false; // THIS IS NEW
|
---|
| 217 |
|
---|
| 218 | $scope.initialCause = function (causes) {
|
---|
| 219 | var linkPara = getParameterByName('LinkParameter');
|
---|
| 220 | $scope.frm.items = [];
|
---|
| 221 | var indexPara = -1;
|
---|
| 222 | var showOption = "Yes";
|
---|
| 223 | if (linkPara != null && linkPara != '') {
|
---|
| 224 | indexPara = causes.indexOf(linkPara);
|
---|
| 225 | }
|
---|
| 226 | for (var i = 0; i < causes.length; i++) {
|
---|
| 227 | if (indexPara != -1 && i != indexPara)
|
---|
| 228 | showOption = "No";
|
---|
| 229 | else
|
---|
| 230 | showOption = "Yes";
|
---|
| 231 | $scope.frm.items.push({
|
---|
| 232 | showYN: showOption, Option: causes[i]
|
---|
| 233 | });
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | //$scope.frm.Causes = causes;
|
---|
| 237 | $scope.frm.Causes = $scope.frm.items
|
---|
| 238 | var cau = $scope.frm.items[0];
|
---|
| 239 |
|
---|
| 240 | if (linkPara != null && linkPara != '') {
|
---|
| 241 | if (causes.indexOf(linkPara) == -1) {
|
---|
| 242 | $scope.frm.Cause = cau.Option;
|
---|
| 243 | }
|
---|
| 244 | else {
|
---|
| 245 | $scope.frm.Cause = linkPara;
|
---|
| 246 | }
|
---|
| 247 | }
|
---|
| 248 | else {
|
---|
| 249 |
|
---|
| 250 | $scope.frm.Cause = cau.Option;
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | };
|
---|
| 254 |
|
---|
| 255 |
|
---|
| 256 |
|
---|
| 257 | $scope.formIsValid = function (form) {
|
---|
| 258 | /*return form.$valid && $scope.frm.HasReadPolicy === true ? true : false; OLD ONE*/
|
---|
| 259 | return $scope.frm.recaptcha && form.$valid && $scope.frm.HasReadPolicy === true ? true : false;
|
---|
| 260 | };
|
---|
| 261 |
|
---|
| 262 | $scope.showConditionsError = function (form) {
|
---|
| 263 | return form.$valid && !$scope.formIsValid(form) ? true : false;
|
---|
| 264 | };
|
---|
| 265 |
|
---|
| 266 | $scope.uncheckIfLessThanMinAmount = function () {
|
---|
| 267 | if ($scope.frm.DonationAmount < $scope.frm.minimumDonationAmount) {
|
---|
| 268 | $scope.frm.ExcludeDonationFromMagazine = false;
|
---|
| 269 | }
|
---|
| 270 | };
|
---|
| 271 | $scope.displayTooltip = function (prop) {
|
---|
| 272 | $scope[prop] = !$scope[prop];
|
---|
| 273 |
|
---|
| 274 | if ($scope[prop]) {
|
---|
| 275 | $window.onclick = function (event) {
|
---|
| 276 | if (event.target.id != prop) {
|
---|
| 277 | $scope.$apply(function () {
|
---|
| 278 | $scope[prop] = false;
|
---|
| 279 | });
|
---|
| 280 | }
|
---|
| 281 | };
|
---|
| 282 | }
|
---|
| 283 | };
|
---|
| 284 |
|
---|
| 285 | $scope.setResponse = function (response) {
|
---|
| 286 | console.log(response);
|
---|
| 287 | $.ajax({
|
---|
| 288 | type: 'POST',
|
---|
| 289 | url: "/api/Validation/ReCaptcha",
|
---|
| 290 | data: "=" + response,
|
---|
| 291 | success: function (data) {
|
---|
| 292 | var res = JSON.parse(data);
|
---|
| 293 | console.log(res);
|
---|
| 294 | console.log(res.success);
|
---|
| 295 | if (res.success === true) {
|
---|
| 296 | $scope.frm.recaptcha = true;
|
---|
| 297 | $('#submitContainer').toggle("fast");
|
---|
| 298 | }
|
---|
| 299 | }
|
---|
| 300 | });
|
---|
| 301 | };
|
---|
| 302 |
|
---|
| 303 | $scope.onExpire = function () {
|
---|
| 304 | $scope.frm.recaptcha = false;
|
---|
| 305 | $('#submitContainer').toggle("fast");
|
---|
| 306 |
|
---|
| 307 | }
|
---|
| 308 | function getParameterByName(name) //courtesy Artem
|
---|
| 309 | {
|
---|
| 310 | name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
|
---|
| 311 | var regexS = "[\\?&]" + name + "=([^&#]*)";
|
---|
| 312 | var regex = new RegExp(regexS);
|
---|
| 313 | var results = regex.exec(window.location.href);
|
---|
| 314 | if (results == null)
|
---|
| 315 | return "";
|
---|
| 316 | else
|
---|
| 317 | return decodeURIComponent(results[1].replace(/\+/g, " "));
|
---|
| 318 | }
|
---|
| 319 | }]);
|
---|
| 320 | }()); |
---|