1(function ($) { 2 function setCookie(cname, cvalue, exdays) { 3 const d = new Date(); 4 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); 5 let expires = "expires="+d.toUTCString(); 6 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; 7 } 8 var EASLmzStorage = window.EASLmzStorage = {}; 9 var mzModal = window.mzModal = { 10 $el: null, 11 $backdrop: null, 12 $content: null, 13 $closeButton: null, 14 transitionEventName: "transitionEnd webkitTransitionEnd transitionend oTransitionEnd msTransitionEnd", 15 noClose: false, 16 show: function (html, name) { 17 html && this.$content.html(html); 18 this.$el.attr("data-mzname", name); 19 this.$el.addClass("easl-mz-modal-shown"); 20 }, 21 hide: function () { 22 // `name` used to be read from here without ever being declared, so it resolved to the 23 // global window.name â empty on a normal page load, and therefore falsy. The namespaced 24 // event never fired and every "do X once this modal is dismissed" handler was dead. 25 // show() already records the name on the element, so read it back from there. 26 var name = this.$el.attr("data-mzname"); 27 this.$el.removeClass("easl-mz-modal-shown"); 28 this.$el.trigger("mz.modal.hidden"); 29 name && this.$el.trigger("mz.modal.hidden." + name); 30 }, 31 events: function () { 32 var _this = this; 33 _this.$closeButton.on("click", function (event) { 34 event.preventDefault(); 35 !_this.noClose && _this.hide(); 36 }); 37 _this.$backdrop.on("click", function (event) { 38 event.preventDefault(); 39 !_this.noClose && _this.hide(); 40 }); 41 }, 42 init: function (noClose) { 43 this.noClose = noClose || false; 44 if (!this.$el) { 45 this.$el = $('<div id="easl-mz-modal-wrap"></div>'); 46 this.$el.append('<div class="easl-mz-modal-backdrop"></div><div class="easl-mz-modal"><div class="easl-mz-modal-content"></div><div class="easl-mz-modal-buttons"><a class="easl-mz-modal-close" href="#">OK</a></div></div>'); 47 $("body").append(this.$el); 48 this.$backdrop = $(".easl-mz-modal-backdrop", this.$el); 49 this.$content = $(".easl-mz-modal-content", this.$el); 50 this.$closeButton = $(".easl-mz-modal-close", this.$el); 51 this.events(); 52 } 53 if(this.noClose) { 54 this.$el.addClass('easl-mz-modal-no-close'); 55 }else{ 56 this.$el.removeClass('easl-mz-modal-no-close'); 57 } 58 return this; 59 }, 60 61 }; 62 63 paymentIframeMessage = function (event){ 64 if(event.originalEvent.data.message === 'css') { 65 easlMemberZone.SaferPayFrameCss(event.originalEvent.data); 66 EASLmzStorage.saferPay.$iframe.css({ 67 'height': parseInt(event.originalEvent.data.height) + 30, 68 }); 69 EASLmzStorage.saferPay.$lb.addClass('easl-active'); 70 mzModal.hide(); 71 } 72 if(event.originalEvent.data.message === 'easl_safer_pay_return') { 73 easlMemberZone.handleSaferPayReturn(event.originalEvent.data.status); 74 } 75 } 76 var easlMemberZone = window.easlMemberZone = { 77 homePage: EASLMZSETTINGS.homeURL, 78 url: EASLMZSETTINGS.ajaxURL, 79 action: EASLMZSETTINGS.ajaxActionName, 80 loaderHtml: EASLMZSETTINGS.loaderHtml, 81 messages: EASLMZSETTINGS.messages, 82 modulesLoadTrigger: false, 83 memberDirectoryRequest: false, 84 methods: { 85 "resetPassword": 'reset_member_password', 86 "changePassword": 'change_member_password', 87 "memberCard": 'get_member_card', 88 "featuredMember": 'get_featured_member', 89 "membershipForm": 'get_membership_form', 90 "subscribeMailList": 'subscribe_member_to_mailing_list', 91 "membershipBanner": 'get_membership_banner', 92 "newMembershipForm": 'get_new_membership_form', 93 "submitMemberShipForm": "update_member_profile", 94 "submitNewMemberForm": "create_member_profile", 95 "deleteMyAccount": "delete_current_member", 96 "getMemberDirectory": "get_members_list", 97 "getMemberDetails": "get_member_details", 98 "getMembersMembership": "get_members_memberships", 99 "getMembersCRMNotes": "get_members_crm_notes", 100 "getMembersMembershipDocs": "get_members_memberships_notes", 101 "getMembershipNotes": "get_memberships_notes", 102 "getMemberStats": "get_member_statistics", 103 "initializePayment": "initialize_payment", 104 "createMembership": "create_membership" 105 }, 106 loadHtml: function ($el, response) { 107 if (response.Status === 200 || response.Status === 201) { 108 $el.html(response.Html); 109 $el.removeClass("easl-mz-loading"); 110 } else if (response.Status === 401) { 111 _this.sessionExpiredModal(); 112 } 113 114 }, 115 showModuleLoading: function () { 116 $(".easl-mz-crm-view").html(this.loaderHtml); 117 }, 118 showFieldError: function (fieldName, errorMsg, $context) { 119 $context = $context || $('body'); 120 var $field = $('#mzf_' + fieldName, $context), $fieldWrap = $field.closest(".mzms-field-wrap"); 121 $fieldWrap.addClass("easl-mz-field-has-error"); 122 !$(".mzms-field-error-msg", $fieldWrap).length && $fieldWrap.append('<p class="mzms-field-error-msg"></p>'); 123 $(".mzms-field-error-msg", $fieldWrap).html(errorMsg) 124 }, 125 clearSingleFieldError: function (fieldName, $context) { 126 var $field = $('#mzf_' + fieldName, $context), 127 $fieldWrap = $('#mzf_' + fieldName, $context).closest(".mzms-field-wrap"); 128 $fieldWrap.removeClass('easl-mz-field-has-error'); 129 $(".mzms-field-error-msg", $fieldWrap).html(''); 130 }, 131 clearFieldErrors: function ($context) { 132 $('.mzms-field-wrap', $context).removeClass('easl-mz-field-has-error'); 133 $(".mzms-field-error-msg", $context).html(''); 134 }, 135 customFileInput: function ($el) { 136 $('.mzms-field-file-wrap input', $el).each(function () { 137 var $input = $(this); 138 var $label = $(this).closest(".mzms-field-file-wrap"); 139 var fileName = ''; 140 141 $input.on('change', function (e) { 142 if (this.files && this.files.length > 1) { 143 fileName = (this.getAttribute('data-multiple-caption') || '').replace('{count}', this.files.length); 144 } else if (e.target.value) { 145 fileName = e.target.value.split('\\').pop(); 146 } 147 if (fileName) { 148 $label.addClass('mzfs-file-selected').find('.mzms-field-file-label').html(fileName); 149 } else { 150 $label.removeClass('mzfs-file-selected').find('.mzms-field-file-label').html(''); 151 } 152 }); 153 154 // Firefox bug fix 155 $input 156 .on('focus', function () { 157 $input.addClass('has-focus'); 158 }) 159 .on('blur', function () { 160 $input.removeClass('has-focus'); 161 }); 162 }); 163 }, 164 sessionExpiredModal: function(){ 165 var _this = this; 166 mzModal.init(); 167 mzModal.$el.one("mz.modal.hidden.session.expired", function () { 168 window.location.href = _this.homePage; 169 }); 170 mzModal.show('<div class="mz-modal-password-reset">Your session expired</div>', 'session.expired'); 171 }, 172 resetPassword: function () { 173 var _this = this; 174 $(".mz-reset-pass-button").on("mz_loaded:" + this.methods.resetPassword, function (event, response, method) { 175 var $resetButton = $(this); 176 if (response.Status === 200) { 177 mzModal.init(); 178 mzModal.$el.one("mz.modal.hidden.email.reset.ok", function () { 179 $resetButton 180 .closest(".easl-mz-login-form-wrapper") 181 .removeClass("mz-show-reset-form mz-reset-pass-processing") 182 .find(".mz-forgot-password") 183 .html("Forgot your password?"); 184 }); 185 mzModal.show('<div class="mz-modal-password-reset">Your password has been reset, <br>please check your email</div>', 'email.reset.ok'); 186 } else { 187 mzModal.init(); 188 mzModal.$el.one("mz.modal.hidden.email.reset.notfound", function () { 189 $resetButton 190 .closest(".easl-mz-login-form-wrapper") 191 .removeClass("mz-show-reset-form mz-reset-pass-processing") 192 .find(".mz-forgot-password") 193 .html("Forgot your password?"); 194 }); 195 mzModal.show('<div class="mz-modal-password-reset">We could not find your email</div>', 'email.reset.notfound'); 196 } 197 198 }); 199 $(".mz-reset-pass-button").on("click", function (event) { 200 event.preventDefault(); 201 $el = $(this); 202 var email = $el.closest(".easl-mz-login-form-wrapper").addClass("mz-reset-pass-processing").find(".mz-reset-pass-email").val(); 203 if (email) { 204 _this.request(_this.methods.resetPassword, $el, {"email": email}); 205 } 206 207 }); 208 }, 209 loadMemberZonePanel: function (html) { 210 var $panel = $("#mz-panel-outer-wrapper"); 211 if ($panel.length === 0) { 212 $("body").append('<div id="mz-panel-outer-wrapper"></div>'); 213 $panel = $("#mz-panel-outer-wrapper"); 214 $panel.html(html); 215 $("body").on("click", ".mz-member-panel-button", function (event) { 216 event.preventDefault(); 217 if ($panel.hasClass("mz-show-panel")) { 218 $panel.removeClass("mz-show-panel"); 219 } else { 220 $panel.addClass("mz-show-panel"); 221 } 222 }); 223 $(".mz-panel-close").on("click", function (event) { 224 event.preventDefault(); 225 $panel.removeClass("mz-show-panel"); 226 }); 227 } 228 }, 229 getMemberCard: function () { 230 var _this = this; 231 var $el = $(".easl-mz-membercard"); 232 if ($el.length) { 233 $el.on("mz_loaded:get_member_card", function (event, response, method) { 234 if (response.Status === 200) { 235 $(this) 236 .html(response.Html) 237 .removeClass("easl-mz-loading"); 238 } else { 239 _this.sessionExpiredModal(); 240 } 241 }); 242 this.request('get_member_card', $el); 243 } 244 }, 245 getFeaturedMembers: function () { 246 var _this = this; 247 var $el = $(".easl-mz-featured-members-slider"); 248 if ($el.length) { 249 $el.on("mz_loaded:" + this.methods.featuredMember, function (event, response, method) { 250 _this.loadHtml($(this), response); 251 ('function' === typeof (window['vcexCarousels'])) && window.vcexCarousels($(this)); 252 }); 253 this.request(this.methods.featuredMember, $el); 254 } 255 }, 256 membershipFormEvents: function ($el) { 257 var _this = this; 258 var $jobFunction = $("#mzf_dotb_job_function", $el); 259 var $jobFunctionOther = $("#mzms-fields-con-dotb_job_function_other", $el); 260 var $speciality = $("#mzf_medical_speciality_c", $el); 261 var $specialityOther = $("#mzms-fields-con-medical_speciality_c_other", $el); 262 var $userCategory = $("#mzf_participant_type_c", $el); 263 var $userCategoryOther = $("#mzms-fields-con-participant_type_c_other", $el); 264 var $publicField = $("#mzms_dotb_public_profile", $el); 265 var $publicProfileFields = $("#mzf_dotb_public_profile_fields", $el); 266 267 if ($jobFunction.val() === "Other") { 268 $jobFunctionOther.removeClass("easl-mz-hide"); 269 } else { 270 $jobFunctionOther.addClass("easl-mz-hide"); 271 } 272 $jobFunction.on("change", function () { 273 if ($(this).val() === "Other") { 274 $jobFunctionOther.removeClass("easl-mz-hide"); 275 } else { 276 $jobFunctionOther.addClass("easl-mz-hide"); 277 } 278 }); 279 280 if ($speciality.val() === "Other") { 281 $specialityOther.removeClass("easl-mz-hide"); 282 } else { 283 $specialityOther.addClass("easl-mz-hide"); 284 } 285 286 $speciality.on("change", function () { 287 if ($speciality.val() === "Other") { 288 $specialityOther.removeClass("easl-mz-hide"); 289 } else { 290 $specialityOther.addClass("easl-mz-hide"); 291 } 292 }); 293 if ($userCategory.val() === "Other") { 294 $userCategoryOther.removeClass("easl-mz-hide"); 295 } else { 296 $userCategoryOther.addClass("easl-mz-hide"); 297 } 298 $userCategory.on("change", function () { 299 if ($(this).val() === "Other") { 300 $userCategoryOther.removeClass("easl-mz-hide"); 301 } else { 302 $userCategoryOther.addClass("easl-mz-hide"); 303 } 304 }); 305 306 $("#mzms-delete-account", $el).on("click", function (event) { 307 event.preventDefault(); 308 _this.deleteMyAccount($("#easl-mz-membership-form", $el)); 309 }); 310 311 // Change Picture form events 312 313 _this.customFileInput($el); 314 315 $(".mzms-change-image", $el).on("click", function (event) { 316 event.preventDefault(); 317 $el.addClass("mz-show-picture-change-form"); 318 }); 319 $(".mzms-change-picture-cancel", $el).on("click", function (event) { 320 event.preventDefault(); 321 $el.removeClass("mz-show-picture-change-form"); 322 }); 323 $(".mzms-fields-privacy-icon", $el).on("click", function (event) { 324 var $fieldWrap = $(this).closest(".mzms-field-wrap"); 325 event.preventDefault(); 326 if (!$fieldWrap.hasClass("mzms-privacy-enabled")) { 327 $fieldWrap.addClass("mzms-privacy-enabled");
328 $(".mzms-fields-privacy-tooltip", $fieldWrap).html("Show to public"); 329 } else { 330 $fieldWrap.removeClass("mzms-privacy-enabled"); 331 $(".mzms-fields-privacy-tooltip", $fieldWrap).html("Hide from public") 332 !$publicField.prop("checked") && $publicField.prop("checked", true).closest("label").addClass("easl-active"); 333 } 334 $publicProfileFields.val(_this.getMemberProfilePublicFieldsValue()); 335 }); 336 $publicField.on("click", function (event) { 337 if (!$(this).prop("checked")) { 338 $(".mzms-field-has-privacy", $el).addClass("mzms-privacy-enabled"); 339 $publicProfileFields.val(''); 340 } else { 341 $(".mzms-field-has-privacy", $el).removeClass("mzms-privacy-enabled"); 342 $publicProfileFields.val(_this.getMemberProfilePublicFieldsValue()); 343 } 344 }); 345 346 // Change password form events 347 $(".mzms-change-password_disabled", $el).on("click", function (event) { 348 event.preventDefault(); 349 $el.addClass("mz-show-password-change-form"); 350 }); 351 $(".mzms-change-password-cancel", $el).on("click", function (event) { 352 event.preventDefault(); 353 $el.removeClass("mz-show-password-change-form"); 354 }); 355 $(".mzms-change-password-submit", $el).on("click", function (event) { 356 event.preventDefault(); 357 _this.changePassword($el); 358 }); 359 $(".mzms-sub-unsub-button", $el).on("click", function (event) { 360 event.preventDefault(); 361 _this.subscribeMemberToMailList($(this), $el); 362 }); 363 $(".mzms-disable-auto-renew-button", $el).on("click", function (event) { 364 event.preventDefault(); 365 _this.disableAutoRenew($(this), $el); 366 }); 367 $(".mzms-button-has-empty-fields", $el).on("click", function (event) { 368 event.preventDefault(); 369 var $button = $(this); 370 var Errors = $button.data("errors"); 371 Errors = Errors || {}; 372 if( $button.data("doSubmit")) { 373 _this.submitMemberShipForm($("#easl-mz-membership-form"), function (res) { 374 mzModal.init(); 375 mzModal.show('<div class="mz-modal-password-changed">Your profile updated successfully!<br/> You are redirecting to membership page.</div>', 'account.update.ok'); 376 window.location.href = $button.attr("href"); 377 }); 378 }else { 379 mzModal.init(); 380 mzModal.show('<div class="mz-modal-password-changed">Please fix the errors with highlighted fields!</div>', 'account.fields.empty'); 381 for (var fieldName in Errors) { 382 _this.showFieldError(fieldName, Errors[fieldName], $el); 383 } 384 $button.data("doSubmit", true); 385 } 386 //submitMemberShipForm 387 }); 388 389 if($el.hasClass('easl-highlight-errors')) { 390 var $button = $(".mzms-button-has-empty-fields", $el); 391 var Errors = {}; 392 if($button.length < 1) { 393 return 394 } 395 Errors = $button.data("errors"); 396 Errors = Errors || {}; 397 for (var fieldName in Errors) { 398 _this.showFieldError(fieldName, Errors[fieldName], $el); 399 } 400 setTimeout(function (){ 401 mzModal.init(); 402 mzModal.show('<div class="mz-modal-password-changed">Please fix the errors with highlighted fields!</div>', 'account.fields.empty'); 403 }, 1000); 404 405 406 $button.data("doSubmit", true); 407 } 408 $("#easl-mz-membership-form").on("submit", function (event) { 409 event.preventDefault(); 410 _this.submitMemberShipForm($(this)); 411 }); 412 }, 413 getMemberProfilePublicFieldsValue: function ($el) { 414 var field_names = []; 415 $(".mzms-field-has-privacy").not(".mzms-privacy-enabled").find(":input").each(function () { 416 $(this).attr('name') && field_names.push($(this).attr('name')); 417 }); 418 return field_names.join(','); 419 }, 420 changePassword: function ($el) { 421 var _this = this; 422 var $wrap = $el.find(".easl-mz-password-change-wrap"); 423 var error = false;
424 var data = { 425 "old_password": $("#mzf_old_password", $wrap).val(), 426 "new_password": $("#mzf_new_password", $wrap).val(), 427 "new_password2": $("#mzf_new_password2", $wrap).val() 428 }; 429 430 _this.clearFieldErrors($wrap); 431 432 if (!data.old_password) { 433 _this.showFieldError('old_password', "Mandatory field", $wrap); 434 error = true; 435 } else { 436 _this.clearSingleFieldError('old_password', $wrap); 437 } 438 if (!data.new_password) { 439 _this.showFieldError('new_password', "Mandatory field", $wrap); 440 error = true; 441 } else { 442 _this.clearSingleFieldError('new_password', $wrap); 443 } 444 if (!data.new_password2) { 445 _this.showFieldError('new_password2', "Mandatory field", $wrap); 446 error = true; 447 } else { 448 _this.clearSingleFieldError('new_password2', $wrap); 449 } 450 if (!error) { 451 if (data.new_password2 !== data.new_password) { 452 _this.showFieldError('new_password2', "Must be same as password.", $wrap); 453 error = true; 454 } else { 455 _this.clearSingleFieldError('new_password2', $wrap); 456 } 457 } 458 if (!error) { 459 $el.addClass("easl-mz-modal-processing"); 460 $el.one("mz_loaded:" + this.methods.changePassword, function (event, response, method) { 461 $el.removeClass("easl-mz-modal-processing"); 462 if (response.Status === 200) { 463 mzModal.init(); 464 mzModal.$el.one("mz.modal.hidden.password.changed.ok", function () { 465 $el.removeClass("mz-show-password-change-form"); 466 }); 467 mzModal.show('<div class="mz-modal-password-changed">Your password has been changed successfully!</div>', 'password.changed.ok'); 468 } 469 if (response.Status === 400) { 470 // TODO - Replace with a modal 471 for (var fieldName in response.Errors) { 472 _this.showFieldError(fieldName, response.Errors[fieldName], $wrap); 473 } 474 } 475 if (response.Status === 405) { 476 mzModal.init(); 477 mzModal.$el.one("mz.modal.hidden.password.changed.notok", function () { 478 // May be refresh 479 }); 480 mzModal.show('<div class="mz-modal-password-changed">Failed! Refresh the page and try again!</div>', 'password.changed.notok'); 481 } 482 if (response.Status === 401) { 483 _this.sessionExpiredModal(); 484 } 485 }); 486 this.request(this.methods.changePassword, $el, data); 487 } 488 }, 489 deleteMyAccount: function ($form) { 490 var _this = this; 491 $form.closest(".wpb_easl_mz_membership").addClass("easl-mz-form-processing").append('<div class="easl-mz-membership-loader">' + this.loaderHtml + '</div>'); 492 $("html, body").stop().animate({ 493 "scrollTop": 0 494 }, 600); 495 $form.one("mz_loaded:" + this.methods.deleteMyAccount, function (event, response, method) { 496 $form.closest(".wpb_easl_mz_membership").removeClass("easl-mz-form-processing").find(".easl-mz-membership-loader").remove(); 497 if (response.Status === 200) { 498 mzModal.init(); 499 mzModal.$el.one("mz.modal.hidden.account.delete.ok", function () { 500 window.location.href = _this.homePage; 501 }); 502 mzModal.show('<div class="mz-modal-password-changed">Your account deleted successfully!</div>', 'account.delete.ok'); 503 } 504 if (response.Status === 400) { 505 mzModal.init(); 506 mzModal.$el.one("mz.modal.hidden.account.delete.notok", function () { 507 508 }); 509 mzModal.show('<div class="mz-modal-password-changed">Could not delete account! Refresh the page and try again.</div>', 'account.delete.notok'); 510 } 511 if (response.Status === 401) { 512 mzModal.init(); 513 mzModal.$el.one("mz.modal.hidden.account.delete.unauthorized", function () { 514 515 }); 516 mzModal.show('<div class="mz-modal-unauthorized">Unauthorized! Refresh the page.</div>', 'account.delete.unauthorized'); 517 } 518 }); 519 this.request(this.methods.deleteMyAccount, $form, {"id": $form.find('#mzf_id').val()}); 520 }, 521 subscribeMemberToMailList: function($button, $el) { 522 var _this = this; 523 var data = { 524 sub_type: $button.attr('data-type') 525 } 526 if($button.hasClass('easl-button-processing')) { 527 return; 528 } 529 $button.addClass('easl-button-processing'); 530 $button.one("mz_loaded:" + this.methods.subscribeMailList, function (event, response, method) { 531 $button.removeClass('easl-button-processing'); 532 if (response.Status === 200) { 533 mzModal.init(); 534 mzModal.show('<div class="mz-modal-response-msg">'+ response.Data.msg +'</div>', 'account.subscribed.ok'); 535 $button.attr('data-type', response.Data.type); 536 $button.find('span').html(response.Data.button_title); 537 } 538 if (response.Status === 404) { 539 mzModal.init(); 540 mzModal.show('<div class="mz-modal-response-msg">We could not process your request. Please try again.</div>', 'account.subscribed.failed'); 541 } 542 if (response.Status === 400) { 543 mzModal.init(); 544 mzModal.show('<div class="mz-modal-response-msg">'+ response.Data.msg +'</div>', 'account.subscribed.failed'); 545 } 546 if (response.Status === 401) { 547 mzModal.init(); 548 mzModal.$el.one("mz.modal.hidden.account.update.unauthorized", function () { 549 //may be refresh here 550 }); 551 mzModal.show('<div class="mz-modal-password-changed">Unauthorized! Refresh the page.</div>', 'account.update.unauthorized'); 552 } 553 }); 554 555 _this.request(this.methods.subscribeMailList, $button, data); 556 }, 557 disableAutoRenew: function($button, $el) { 558 var _this = this; 559 if($button.hasClass('easl-button-processing')) { 560 return; 561 } 562 $button.addClass('easl-button-processing'); 563 $button.one("mz_loaded:disable_auto_renew", function (event, response, method) { 564 $button.removeClass('easl-button-processing'); 565 if (response.Status === 200) { 566 mzModal.init(); 567 mzModal.show('<div class="mz-modal-response-msg">'+ response.Data.msg +'</div>', 'account.auto_renew_disabled.ok'); 568 $button.remove(); 569 } 570 if (response.Status === 404) { 571 mzModal.init(); 572 mzModal.show('<div class="mz-modal-response-msg">We could not process your request. Please try again.</div>', 'account.auto_renew_disabled.failed'); 573 } 574 if (response.Status === 400) { 575 mzModal.init(); 576 mzModal.show('<div class="mz-modal-response-msg">'+ response.Data.msg +'</div>', 'account.auto_renew_disabled.failed'); 577 } 578 if (response.Status === 401) { 579 mzModal.init(); 580 mzModal.$el.one("mz.modal.hidden.account.update.unauthorized", function () { 581 //may be refresh here 582 }); 583 mzModal.show('<div class="mz-modal-password-changed">Unauthorized! Refresh the page.</div>', 'account.update.unauthorized'); 584 } 585 }); 586 587 _this.request('disable_auto_renew', $button, {}); 588 }, 589 submitMemberShipForm: function ($form, successCB) { 590 var _this = this; 591 this.clearFieldErrors($form); 592 $form.closest(".wpb_easl_mz_membership").addClass("easl-mz-form-processing").append('<div class="easl-mz-membership-loader">' + this.loaderHtml + '</div>'); 593 $("html, body").stop().animate({ 594 "scrollTop": 0 595 }, 600); 596 $form.one("mz_loaded:" + this.methods.submitMemberShipForm, function (event, response, method) { 597 $form.closest(".wpb_easl_mz_membership").removeClass("easl-mz-form-processing").find(".easl-mz-membership-loader").remove(); 598 if (response.Status === 200) { 599 if(typeof successCB === 'function') { 600 successCB.call(null, response); 601 }else { 602 mzModal.init(); 603 _this.getMembershipForm(); 604 mzModal.show('<div class="mz-modal-password-changed">Your profile updated successfully!</div>', 'account.update.ok'); 605 } 606 } 607 if (response.Status === 400) { 608 mzModal.init(); 609 mzModal.$el.one("mz.modal.hidden.account.update.error", function () { 610 // 611 }); 612 mzModal.show('<div class="mz-modal-password-changed">Please fix the errors with highlighted fields!</div>', 'account.update.error'); 613 for (var fieldName in response.Errors) {
614 _this.showFieldError(fieldName, response.Errors[fieldName], $form); 615 } 616 } 617 if (response.Status === 401) { 618 mzModal.init(); 619 mzModal.$el.one("mz.modal.hidden.account.update.unauthorized", function () { 620 //may be refresh here 621 }); 622 mzModal.show('<div class="mz-modal-password-changed">Unauthorized! Refresh the page.</div>', 'account.update.unauthorized'); 623 } 624 }); 625 _this.request(this.methods.submitMemberShipForm, $form, $form.serialize()); 626 }, 627 getMembershipForm: function () { 628 var _this = this; 629 var $el = $(".easl-mz-membership-inner"); 630 if ($el.length) { 631 $(".mz-expiring-message-wrap").addClass('mz-banner-loading'); 632 $el.on("mz_loaded:" + this.methods.membershipForm, function (event, response, method) { 633 if (response.Status === 200) { 634 $(this) 635 .html(response.Html) 636 .removeClass("easl-mz-loading"); 637 $("body").trigger("mz_reload_custom_fields"); 638 $(".easl-mz-select2", $(this)).select2({ 639 closeOnSelect: true, 640 allowClear: true, 641 maximumSelectionLength: 4 642 }); 643 $("#mzf_birthdate_fz", $(this)).datepicker({ 644 dateFormat: "dd.mm.yy", 645 altFormat: "yy-mm-dd", 646 altField: "#mzf_birthdate", 647 changeMonth: true, 648 changeYear: true, 649 yearRange: "1900:-18", 650 maxDate: "-0D" 651 }); 652 _this.membershipFormEvents($el); 653 } else { 654 _this.sessionExpiredModal(); 655 } 656 if ((response.Status === 200) && response.Data && response.Data.banner) { 657 _this.loadBanner(response.Data.banner); 658 } 659 }); 660 this.request(this.methods.membershipForm, $el); 661 } 662 }, 663 loadBanner: function (msg) { 664 var $wrap = $(".mz-expiring-message-wrap"); 665 666 if (msg) { 667 $wrap.find('.mz-expiring-message').html(msg); 668 $wrap.addClass('mz-banner-loaded easl-active').removeClass('mz-banner-loading'); 669 $(".mz-expiring-message-close", $wrap).one("click", function (event) { 670 event.preventDefault(); 671 $wrap.removeClass("easl-active"); 672 }); 673 } 674 }, 675 getMembershipBanner: function () { 676 var _this = this; 677 var $el = $(".mz-expiring-message-wrap"); 678 if ($el.length && !($el.hasClass('mz-banner-loaded') || $el.hasClass('mz-banner-loading'))) { 679 $el.on("mz_loaded:" + this.methods.membershipBanner, function (event, response, method) { 680 if ((response.Status === 200) && response.Html) { 681 _this.loadBanner(response.Html); 682 } 683 }); 684 this.request(this.methods.membershipBanner, $el); 685 } 686 }, 687 initNewMemberForm: function () { 688 var _this = this; 689 var $el = $(".wpb_easl_mz_new_member_form"); 690 if ($el.length) { 691 $(".easl-mz-select2", $el).select2({ 692 closeOnSelect: true, 693 allowClear: true, 694 maximumSelectionLength: 4 695 }); 696 $(".easl-mz-date", $el).datepicker({ 697 dateFormat: "dd.mm.yy", 698 altFormat: "yy-mm-dd", 699 altField: "#mzf_birthdate", 700 changeMonth: true, 701 changeYear: true, 702 yearRange: "1900:-18", 703 maxDate: "-0D" 704 }); 705 var $jobFunction = $("#mzf_dotb_job_function", $el); 706 var $jobFunctionOther = $("#mzms-fields-con-dotb_job_function_other", $el); 707 var $speciality = $("#mzf_dotb_easl_specialty", $el); 708 var $specialityOther = $("#mzms-fields-con-dotb_easl_specialty_other", $el); 709 var $userCategory = $("#mzf_dotb_user_category", $el); 710 var $userCategoryOther = $("#mzms-fields-con-dotb_user_category_other", $el); 711 712 if ($jobFunction.val() === "other") { 713 $jobFunctionOther.removeClass("easl-mz-hide"); 714 } else { 715 $jobFunctionOther.addClass("easl-mz-hide"); 716 } 717 $jobFunction.on("change", function () { 718 if ($(this).val() === "other") { 719 $jobFunctionOther.removeClass("easl-mz-hide"); 720 } else { 721 $jobFunctionOther.addClass("easl-mz-hide"); 722 } 723 }); 724 725 if ($speciality.val() === "other") { 726 $specialityOther.removeClass("easl-mz-hide"); 727 } else { 728 $specialityOther.addClass("easl-mz-hide"); 729 } 730 $speciality.on("change", function () { 731 if ($(this).val() && (-1 !== $(this).val().indexOf("other"))) { 732 $specialityOther.removeClass("easl-mz-hide"); 733 } else { 734 $specialityOther.addClass("easl-mz-hide"); 735 } 736 }); 737 738 if ($userCategory.val() === "other") { 739 $userCategoryOther.removeClass("easl-mz-hide"); 740 } else { 741 $userCategoryOther.addClass("easl-mz-hide"); 742 } 743 $userCategory.on("change", function () { 744 if ($(this).val() && (-1 !== $(this).val().indexOf("other"))) { 745 $userCategoryOther.removeClass("easl-mz-hide"); 746 } else { 747 $userCategoryOther.addClass("easl-mz-hide"); 748 } 749 }); 750 751 var $termsCondition = $("#mzf_terms_condition", $el); 752 $("#easl-mz-new-member-form").on("submit", function (event) { 753 event.preventDefault(); 754 if (!$termsCondition.prop("checked")) {
755 _this.showFieldError("terms_condition", "You must agree to our terms and conditions.", $el); 756 event.preventDefault(); 757 } else { 758 _this.clearSingleFieldError("terms_condition", $el); 759 _this.submitNewMemberForm($(this)); 760 } 761 }); 762 } 763 }, 764 submitNewMemberForm: function ($form) { 765 _this = this; 766 this.clearFieldErrors($form); 767 $form.closest(".wpb_easl_mz_new_member_form").addClass("easl-mz-form-processing"); 768 $("html, body").stop().animate({ 769 "scrollTop": 0 770 }, 600); 771 $form.one("mz_loaded:" + this.methods.submitNewMemberForm, function (event, response, method) { 772 $form.closest(".wpb_easl_mz_new_member_form").removeClass("easl-mz-form-processing"); 773 if (response.Status === 400) { 774 for (var fieldName in response.Errors) { 775 _this.showFieldError(fieldName, response.Errors[fieldName], $form); 776 } 777 } 778 if (response.Status === 417) { 779 // Member creation failed 780 mzModal.init(); 781 mzModal.$el.one("mz.modal.hidden.account.create.failed", function () { 782 783 }); 784 mzModal.show('<div class="mz-modal-unauthorized">Failed! Please try again.</div>', 'account.create.failed'); 785 } 786 if (response.Status === 401) { 787 mzModal.init(); 788 mzModal.$el.one("mz.modal.hidden.account.create.unauthorized", function () { 789 //may be refresh here 790 }); 791 mzModal.show('<div class="mz-modal-unauthorized">Unauthorized! Refresh the page.</div>', 'account.create.unauthorized'); 792 } 793 794 if (response.Status === 200) { 795 // Member created and login OK - redirect member 796 window.location.href = response.Html; 797 } 798 }); 799 _this.request(this.methods.submitNewMemberForm, $form, $form.serialize()); 800 }, 801 newMembershipFormEvents: function ($el) { 802 var _this = this; 803 // Membership Category Form events 804 var requireProof = ["trainee_jhep", "trainee", "nurse_jhep", "nurse", "allied_pro_jhep", "allied_pro", "undergraduate_students", "undergraduate_students_jhep", "corresponding_aleh", "emeritus", "emeritus_jhep"]; 805 var jhef = ["regular_jhep", "corresponding_jhep", "trainee_jhep", "nurse_jhep", "patient_jhep", "emeritus_jhep", "allied_pro_jhep", "undergraduate_students_jhep"]; 806 var noAutoRenew = [ "trainee", "trainee_jhep", "undergraduate_students", "undergraduate_students_jhep", "corresponding_aleh"]; 807 var $mzf_membership_category = $("#mzf_membership_category", $el); 808 var $mzf_membership_payment_type = $("#mzf_membership_payment_type", $el); 809 var $mzf_auto_renew_wrap = $("#mzf_auto_renew_wrap", $el); 810 var $mzf_auto_renew_field = $("#mzf_auto_renew", $el); 811 var $mzf_membership_start_date = $("#mzf_membership_start_date", $el); 812 var $mzf_billing_address_street = $("#mzf_billing_address_street", $el); 813 var $mzf_billing_address_city = $("#mzf_billing_address_city", $el); 814 var $mzf_billing_address_postalcode = $("#mzf_billing_address_postalcode", $el); 815 var $mzf_billing_address_country = $("#mzf_billing_address_country", $el); 816 var $mzf_supporting_docs = $("#mzf_supporting_docs", $el); 817 818 var $mzf_jhephardcopyotheraddress_street = $("#mzf_jhephardcopyotheraddress_street", $el); 819 var $mzf_jhephardcopyotheraddress_city = $("#mzf_jhephardcopyotheraddress_city", $el); 820 var $mzf_jhephardcopyotheraddress_postalcode = $("#mzf_jhephardcopyotheraddress_postalcode", $el); 821 var $mzf_jhephardcopyotheraddress_country = $("#mzf_jhephardcopyotheraddress_country", $el); 822
823 var $piHeading = $("#mzms-membership-pi-heading"); 824 var $piWrap = $("#mzms-membership-pi"); 825 var $piInner = $("#mzms-membership-pi-inner"); 826 var $payNowButton = $("#mz-pay-now-btn", $el); 827 828 var $billing_inst_cb = $("#mzf_billing_institution_address"); 829 var $billing_home_cb = $("#mzf_billing_home_address"); 830 831 $billing_inst_cb.on('change', function(){ 832 var address = $(this).data('address'); 833 if(this.checked) { 834 $billing_home_cb.prop('checked', false).closest('label').removeClass('easl-active'); 835 836 $mzf_billing_address_street.val(address.street); 837 $mzf_billing_address_city.val(address.city); 838 $mzf_billing_address_postalcode.val(address.postalcode); 839 $mzf_billing_address_country.val(address.country).trigger('change'); 840 } 841 }); 842 $mzf_auto_renew_field.on('change', function(){ 843 if(this.checked) { 844 $mzf_membership_start_date.addClass('easl-input-readonly').prop('disabled', true); 845 } else { 846 $mzf_membership_start_date.removeClass('easl-input-readonly').prop('disabled', false); 847 } 848 }); 849 850 $billing_home_cb.on('change', function(){ 851 var address = $(this).data('address'); 852 if(this.checked) { 853 $billing_inst_cb.prop('checked', false).closest('label').removeClass('easl-active'); 854 $mzf_billing_address_street.val(address.street); 855 $mzf_billing_address_city.val(address.city); 856 $mzf_billing_address_postalcode.val(address.postalcode); 857 $mzf_billing_address_country.val(address.country).trigger('change'); 858 } 859 }); 860 861 $piHeading.on('click', function (e){ 862 if($(this).hasClass('easlmz-active')) { 863 $(this).removeClass('easlmz-active'); 864 $piInner.css({ 865 'max-height': '0px' 866 }); 867 }else{ 868 $(this).addClass('easlmz-active'); 869 $piInner.css({ 870 'max-height': $piWrap.height() 871 }); 872 } 873 }); 874 875 if (-1 !== requireProof.indexOf($mzf_membership_category.val())) { 876 $("#mzms-support-docs-wrap").addClass("easl-active"); 877 } else { 878 $("#mzms-support-docs-wrap").removeClass("easl-active") 879 } 880 if (-1 !== jhef.indexOf($mzf_membership_category.val())) { 881 $("#mz-membership-jhe-pother-address-wrap").addClass("easl-active"); 882 } else { 883 $("#mz-membership-jhe-pother-address-wrap").removeClass("easl-active"); 884 } 885 886 $mzf_membership_category.on("change", function (event) { 887 var cat = $mzf_membership_category.val(); 888 if (-1 !== requireProof.indexOf(cat)) { 889 $("#mzms-support-docs-wrap").addClass("easl-active"); 890 } else { 891 $("#mzms-support-docs-wrap").removeClass("easl-active") 892 } 893 if (-1 !== jhef.indexOf(cat)) { 894 $("#mz-membership-jhe-pother-address-wrap").addClass("easl-active"); 895 } else { 896 $("#mz-membership-jhe-pother-address-wrap").removeClass("easl-active"); 897 } 898 if(!cat){ 899 $mzf_auto_renew_wrap.removeClass("easl-active"); 900 $mzf_auto_renew_field.prop('checked', false); 901 }else if (-1 !== noAutoRenew.indexOf(cat)) { 902 $mzf_auto_renew_wrap.removeClass("easl-active"); 903 $mzf_auto_renew_field.prop('checked', false); 904 } else { 905 if ('online_cc_indiv' === $mzf_membership_payment_type.val()) { 906 $mzf_auto_renew_wrap.addClass("easl-active"); 907 } else { 908 $mzf_auto_renew_wrap.removeClass("easl-active"); 909 $mzf_auto_renew_field.prop('checked', false); 910 } 911 } 912 913 }); 914 915 $mzf_membership_payment_type.on("change", function (event) { 916 var paymentType = $mzf_membership_payment_type.val(); 917 if(!$mzf_membership_category.val()){ 918 $mzf_auto_renew_wrap.removeClass("easl-active"); 919 $mzf_auto_renew_field.prop('checked', false); 920 }else if (-1 !== noAutoRenew.indexOf($mzf_membership_category.val())) { 921 $mzf_auto_renew_wrap.removeClass("easl-active"); 922 $mzf_auto_renew_field.prop('checked', false); 923 } else { 924 if ('online_cc_indiv' === paymentType) { 925 $mzf_auto_renew_wrap.addClass("easl-active"); 926 } else { 927 $mzf_auto_renew_wrap.removeClass("easl-active"); 928 $mzf_auto_renew_field.prop('checked', false); 929 } 930 } 931 }); 932 if(!$mzf_membership_category.val()){ 933 $mzf_auto_renew_wrap.removeClass("easl-active"); 934 $mzf_auto_renew_field.prop('checked', false); 935 }else if (-1 !== noAutoRenew.indexOf($mzf_membership_category.val())) { 936 $mzf_auto_renew_wrap.removeClass("easl-active"); 937 $mzf_auto_renew_field.prop('checked', false); 938 } else { 939 if ('online_cc_indiv' === $mzf_membership_payment_type.val()) { 940 $mzf_auto_renew_wrap.addClass("easl-active"); 941 } else { 942 $mzf_auto_renew_wrap.removeClass("easl-active"); 943 $mzf_auto_renew_field.prop('checked', false); 944 } 945 } 946 var $termsCondition = $("#mzf_terms_condition", $el); 947 $("form", $el).on("submit", function (event) { 948 var hasError = false;
949 var cat = $mzf_membership_category.val(); 950 var autoRenew = $('#mzf_auto_renew').prop('checked'); 951 event.preventDefault(); 952 if(!cat) { 953 hasError = true; 954 _this.showFieldError("membership_category", "Please select a category.", $el); 955 }else{ 956 _this.clearSingleFieldError("membership_category", $el); 957 } 958 if(!$mzf_billing_address_street.val()) { 959 hasError = true; 960 _this.showFieldError("billing_address_street", "Please enter street.", $el); 961 }else{ 962 _this.clearSingleFieldError("billing_address_street", $el); 963 } 964 if(!$mzf_billing_address_city.val()) { 965 hasError = true; 966 _this.showFieldError("billing_address_city", "Please city.", $el); 967 }else{ 968 _this.clearSingleFieldError("billing_address_city", $el); 969 } 970 if(!$mzf_billing_address_postalcode.val()) { 971 hasError = true; 972 _this.showFieldError("billing_address_postalcode", "Please enter postal code.", $el); 973 }else{ 974 _this.clearSingleFieldError("billing_address_postalcode", $el); 975 } 976 if(!$mzf_billing_address_country.val()) { 977 hasError = true; 978 _this.showFieldError("billing_address_country", "Please select country.", $el); 979 }else{ 980 _this.clearSingleFieldError("billing_address_country", $el); 981 } 982 if (!$termsCondition.prop("checked")) { 983 hasError = true; 984 _this.showFieldError("terms_condition", "You must agree to our terms and conditions.", $el); 985 } else { 986 _this.clearSingleFieldError("terms_condition", $el); 987 } 988 if ((-1 !== requireProof.indexOf(cat)) && !$mzf_supporting_docs.val()) { 989 hasError = true; 990 _this.showFieldError("supporting_docs", "Please upload supporting document.", $el); 991 } else { 992 _this.clearSingleFieldError("supporting_docs", $el); 993 } 994 if (-1 !== jhef.indexOf(cat)) { 995 if(!$mzf_jhephardcopyotheraddress_street.val()) { 996 hasError = true; 997 _this.showFieldError("jhephardcopyotheraddress_street", "Please enter street.", $el); 998 }else{ 999 _this.clearSingleFieldError("jhephardcopyotheraddress_street", $el); 1000 } 1001 if(!$mzf_jhephardcopyotheraddress_city.val()) { 1002 hasError = true; 1003 _this.showFieldError("jhephardcopyotheraddress_city", "Please enter city.", $el); 1004 }else{ 1005 _this.clearSingleFieldError("jhephardcopyotheraddress_city", $el); 1006 } 1007 if(!$mzf_jhephardcopyotheraddress_postalcode.val()) { 1008 hasError = true; 1009 _this.showFieldError("jhephardcopyotheraddress_postalcode", "Please enter postal code.", $el); 1010 }else{ 1011 _this.clearSingleFieldError("jhephardcopyotheraddress_postalcode", $el); 1012 } 1013 if(!$mzf_jhephardcopyotheraddress_country.val()) { 1014 hasError = true; 1015 _this.showFieldError("jhephardcopyotheraddress_country", "Please select country.", $el); 1016 }else{ 1017 _this.clearSingleFieldError("jhephardcopyotheraddress_country", $el); 1018 } 1019 } 1020 if(!hasError) { 1021 // The submit handler is never unbound and the button is never disabled, so a 1022 // fast double-click or a repeated Enter fired two create_membership POSTs and 1023 // left two membership records in the CRM. The class below is styling only. 1024 if ($el.data('mzSubmitting')) { 1025 return; 1026 } 1027 $el.data('mzSubmitting', true); 1028 $el.find(".easl-mz-new-membership-form-inner").addClass("easl-mz-nm-form-submitted"); 1029 var formData = new FormData(this); 1030 formData.append('action', _this.action); 1031 formData.append('method', _this.methods.createMembership); 1032 axios.post(_this.url, formData, { 1033 headers: { 1034 'Content-Type': 'multipart/form-data' 1035 }, 1036 responseType: 'json' 1037 }).then(function (res){ 1038 //$el.find(".easl-mz-new-membership-form-inner").removeClass("easl-mz-nm-form-submitted"); 1039 if(res.data.Status === 201) { 1040 if(typeof res.data.Data.redirectUrl !== 'undefined') { 1041 mzModal.init(); 1042 mzModal.show('<div class="mz-modal-membership-modal">Membership created! You are redirecting to the payment details page.</div>', 'membership.create.ok'); 1043 window.location.href = res.data.Data.redirectUrl; 1044 }else{ 1045 _this.processPaymentLightBox($el, res.data.Data, autoRenew); 1046 } 1047 }else if(res.data.Status === 401){ 1048 $el.data('mzSubmitting', false); 1049 _this.sessionExpiredModal(); 1050 }else{ 1051 // Nothing was created, so let the member correct and resubmit. 1052 $el.data('mzSubmitting', false); 1053 $el.find(".easl-mz-new-membership-form-inner").removeClass("easl-mz-nm-form-submitted"); 1054 mzModal.init(); 1055 mzModal.show('<div class="mz-modal-membership-modal">We could not create your membership! Please try again.</div>', 'membership.create.notok'); 1056 } 1057 }).catch(function (error){ 1058 //_this.sessionExpiredModal(); 1059 $el.data('mzSubmitting', false); 1060 $el.find(".easl-mz-new-membership-form-inner").removeClass("easl-mz-nm-form-submitted"); 1061 mzModal.init(); 1062 mzModal.$el.one("mz.modal.hidden.membership.create.notok", function () { 1063 1064 }); 1065 mzModal.show('<div class="mz-modal-membership-modal">We could not create your membership! Please try again.</div>', 'membership.create.notok'); 1066 }); 1067 } 1068 }); 1069 $payNowButton.on('click', function (e){ 1070 var $button = $(this); 1071 var autoRenew = $button.attr('data-auto-renew'); 1072 e.preventDefault(); 1073 var membershipData = { 1074 memberID: $button.attr('data-member-id'), 1075 membershipID: $button.attr('data-membership-id'), 1076 membershipCat: $button.attr('data-membership-cat') 1077 }; 1078 _this.processPaymentLightBox($el, membershipData, autoRenew); 1079 }); 1080 $("#mz-start-over-now-btn", $el).on('click', function (e){ 1081 e.preventDefault(); 1082 mzModal.init(true); 1083 mzModal.show('<div class="mz-modal-membership-modal">You pending membership is being removed. Please wait.</div>', 'membership.pending.remove'); 1084 $el.one("mz_loaded:remove_pending_memberships", function (event, response, method) { 1085 if (response.Status === 200) { 1086 // Pending memberships are removed 1087 mzModal.show('<div class="mz-modal-membership-modal">Pending memberships are removed. You\'re now being redirected to the renew membership page</div>', 'membership.pending.removed'); 1088 window.location.reload(); 1089 } else { 1090 mzModal.init(false); 1091 mzModal.show('<div class="mz-modal-membership-modal">We could not remove your pending memberships. Please try again or c
1091ontact us.</div>', 'membership.pending.not_removed'); 1092 } 1093 }); 1094 _this.request('remove_pending_memberships', $el, {}); 1095 }); 1096 }, 1097 processPaymentLightBox: function ($el, data, autoRenew) { 1098 var _this = this; 1099 // One guard covering both entry points â the membership form and the "Pay now" button. 1100 // Each click used to start its own SaferPay transaction for the same membership, so two 1101 // payment pages could be open at once and the member could be charged twice. 1102 if (EASLmzStorage.paymentInFlight) { 1103 return; 1104 } 1105 EASLmzStorage.paymentInFlight = true; 1106 mzModal.init(true); 1107 mzModal.show('<div class="mz-modal-membership-modal">Your payment form is being prepared!</div>', 'membership.create.ok'); 1108 EASLmzStorage.saferPay = { 1109 memberID: data.memberID, 1110 membershipID: data.membershipID, 1111 autoRenew: autoRenew, 1112 membershipCat: data.membershipCat, 1113 }; 1114 $el.one("mz_loaded:" + _this.methods.initializePayment, function (event, response, method) { 1115 if (response.Status === 200) { 1116 _this.displayPaymentIframeLightBox($el, response.Data); 1117 } else { 1118 // Preparation failed, so release the guard: the member may legitimately try 1119 // again without the page having gone anywhere. 1120 EASLmzStorage.paymentInFlight = false; 1121 // Dismissible: this modal carries a reload handler, so locking it shut left 1122 // the member stuck with no way out but a manual refresh. 1123 mzModal.init(false); 1124 mzModal.$el.one("mz.modal.hidden", function () { 1125 window.location.reload(); 1126 }); 1127 mzModal.show('<div class="mz-modal-membership-modal">We could not prepare the payment form. Please contact us.</div>', 'membership.payment.notok'); 1128 } 1129 }); 1130 _this.request(_this.methods.initializePayment, $el, { 1131 'member_id': data.memberID, 1132 'membership_id': data.membershipID, 1133 'auto_renew': autoRenew 1134 }); 1135 }, 1136 displayPaymentIframeLightBox: function ($el, data){ 1137 EASLmzStorage.saferPay.Token = data.Token; 1138 EASLmzStorage.saferPay.$el = $el; 1139 EASLmzStorage.saferPay.$lb = $('#payment-iframe-lightbox', $el); 1140 $el.addClass('easl-disable-with-overlay'); 1141 if($('iframe', EASLmzStorage.saferPay.$lb).length) { 1142 $('iframe', EASLmzStorage.saferPay.$lb).remove(); 1143 } 1144 EASLmzStorage.saferPay.$iframe = $('<iframe/>', { 1145 id: 'membershipPaymentFrame', 1146 name: 'membershipPaymentFrame', 1147 src: data.RedirectUrl, 1148 frameborder: '0', 1149 allowtransparency: 'true', 1150 allowpaymentrequest:'true', 1151 tabIndex: '1' 1152 }); 1153 EASLmzStorage.saferPay.$lb.append(EASLmzStorage.saferPay.$iframe); 1154 }, 1155 SaferPayFrameCss: function (data){ 1156 EASLmzStorage.saferPay.$iframe.css({ 1157 'height': parseInt(data.height) + 30, 1158 }); 1159 EASLmzStorage.saferPay.$lb.addClass('easl-active'); 1160 mzModal.hide(); 1161 }, 1162 handleSaferPayReturn: function (status){ 1163 EASLmzStorage.saferPay.$lb.removeClass('easl-active'); 1164 //console.log(status); 1165 if('Success' !== status) { 1166 mzModal.init(false); 1167 mzModal.$el.one("mz.modal.hidden", function () { 1168 window.location.reload(); 1169 }); 1170 mzModal.show('<div class="mz-modal-membership-modal">Payment failed! Please try again</div>', 'membership.payment.failed'); 1171 }else{ 1172 this.processSaferPayTransaction(); 1173 } 1174 }, 1175 processSaferPayTransaction: function (){ 1176 var _this = this; 1177 mzModal.init(true); 1178 mzModal.show('<div class="mz-modal-membership-modal">We are processing your payment. Please wait...</div>', 'membership.payment.processing'); 1179 1180 EASLmzStorage.saferPay.$el.one("mz_loaded:sf_process_after_transaction", function (event, response, method) { 1181 if (response.Status === 200) { 1182 mzModal.init(true); 1183 mzModal.show('<div class="mz-modal-membership-modal">'+ response.Html +'</div>', 'membership.payment.status.ok'); 1184 window.location.href = response.Data.RedirectUrl; 1185 } else if (response.Data && response.Data.PaymentCaptured) { 1186 // The card was charged but the membership could not be activated. Show the 1187 // server's message and send the member to the dashboard on dismiss. Never 1188 // reload here: that lands back on the waiting-payment form, whose "Pay now" 1189 // button would charge them a second time. 1190 mzModal.init(false); 1191 mzModal.$el.one("mz.modal.hidden", function () { 1192 if (response.Data.RedirectUrl) { 1193 window.location.href = response.Data.RedirectUrl; 1194 } 1195 }); 1196 mzModal.show('<div class="mz-modal-membership-modal">'+ response.Html +'</div>', 'membership.payment.status.unconfirmed'); 1197 } else { 1198 mzModal.init(false); 1199 mzModal.$el.one("mz.modal.hidden", function () { 1200 window.location.reload(); 1201 }); 1202 mzModal.show('<div class="mz-modal-membership-modal">Payment failed! Please try again</div>', 'membership.payment.failed'); 1203 } 1204 }); 1205 _this.request('sf_process_after_transaction', EASLmzStorage.saferPay.$el, { 1206 token: EASLmzStorage.saferPay.Token, 1207 member_id: EASLmzStorage.saferPay.memberID, 1208 membership_id: EASLmzStorage.saferPay.membershipID, 1209 auto_renew: EASLmzStorage.saferPay.autoRenew, 1210 mz_cat: EASLmzStorage.saferPay.membershipCat 1211 }); 1212 }, 1213 updateMemCatDDc: function($el) { 1214 var cc = $("#mzf_primary_address_country", $el).val(); 1215 var $memCatDD = $("#mzf_membership_category", $el); 1216 var memCat = $memCatDD.val(); 1217 var isEurope = EASLMZSETTINGS.europeCCs.indexOf(cc) >= 0; 1218 if(isEurope){ 1219 $memCatDD.find('option[value="regular"],option[value="regular_jhep"]').prop('disabled', false); 1220 $memCatDD.find('option[value="corresponding"],option[value="corresponding_jhep"]').prop('disabled', true); 1221 if(memCat === 'corresponding' || memCat === 'corresponding_jhep') { 1222 $memCatDD.val(null).trigger('change'); 1223 } 1224 }else{ 1225 $memCatDD.find('option[value="regular"],option[value="regular_jhep"]').prop('disabled', true); 1226 $memCatDD.find('option[value="corresponding"],option[value="corresponding_jhep"]').prop('disabled', false); 1227 if(memCat === 'regular' || memCat === 'regular_jhep') { 1228 $memCatDD.val(null).trigger('change'); 1229 } 1230 } 1231 }, 1232 getNewMembershipForm: function () { 1233 var _this = this; 1234 var $el = $(".easl-mz-new-membership-form"); 1235 if ($el.length) { 1236 $(".mz-expiring-message-wrap").addClass('mz-banner-loading'); 1237 $el.on("mz_loaded:" + this.methods.newMembershipForm, function (event, response, method) { 1238 _this.loadHtml($(this), response); 1239 $("body").trigger("mz_reload_custom_fields"); 1240 $(".easl-mz-select2", $(this)).select2({ 1241 closeOnSelect: true, 1242 allowClear: true, 1243 maximumSelectionLength: 4 1244 }); 1245 $("#mzf_membership_start_date", $(this)).datepicker({ 1246 dateFormat: "dd.mm.yy", 1247 changeMonth: true, 1248 changeYear: true, 1249 //minDate: "+0D", 1250 }); 1251 _this.customFileInput($el); 1252 _this.newMembershipFormEvents($el); 1253 if ((response.Status === 200) && response.Data && response.Data.banner) { 1254 _this.loadBanner(response.Data.banner); 1255 } 1256 }); 1257 1258 url = new URL(window.location.href); 1259 var skipDashboard = url.searchParams.get('skip_dashboard'); 1260 this.request(this.methods.newMembershipForm, $el, { 1261 'renew': $el.data('paymenttype'), 1262 'messages': _this.messages, 1263 'skip_dashboard': skipDashboard 1264 }); 1265 } 1266 }, 1267 getMemberDirectory: function ($el) { 1268 var _this = this; 1269 var search = $("#mz-md-filter-search", $el).val(); 1270 var country = $("#mz-md-filter-country", $el).val(); 1271 var speciality = $("#mz-md-filter-spec", $el).val(); 1272 var letter = $("#mz-md-filter-letter", $el).val(); 1273 var page = $("#mz-md-filter-page", $el).val(); 1274 1275 if (typeof _this.memberDirectoryRequest === 'object') { 1276 _this.memberDirectoryRequest.abort(); 1277 } 1278 $el.addClass("mz-md-loading"); 1279 _this.memberDirectoryRequest = _this.request(this.methods.getMemberDirectory, $el, { 1280 "search": search, 1281 "country": country, 1282 "speciality": speciality, 1283 "letter": letter, 1284 "page_offset": page 1285 }); 1286 }, 1287 initMemberDirectory: function () { 1288 var _this = this; 1289 var $el = $(".easl-mz-directory-inner"); 1290 if ($el.length) { 1291 $el.on("mz_loaded:" + this.methods.getMemberDirectory, function (event, response, method) { 1292 if (response.Status === 200) { 1293 $(".easl-mz-members-direcoty-content-inner", $el).html(response.Html); 1294 } else if (response.Status === 404) { 1295 $(".easl-mz-members-direcoty-content-inner", $el).html("No members found!"); 1296 } else if (response.Status === 401) { 1297 // TODO-maybe reload 1298 } 1299 $el.removeClass("mz-md-loading"); 1300 }); 1301 $el.on("click", ".easl-mz-clear-filters", function (event) { 1302 event.preventDefault(); 1303 $("#mz-md-filter-search", $el).val(""); 1304 $("#mz-md-filter-letter", $el).val(""); 1305 $("#mz-md-filter-page", $el).val(""); 1306 $(".easl-mz-select2", $el).val(null).trigger('change'); 1307 _this.getMemberDirectory($el); 1308 }); 1309 $el.on("keyup", "#mz-md-filter-search", function (event) { 1310 if (event.which === 13) { 1311 $("#mz-md-filter-page", $el).val(""); 1312 _this.getMemberDirectory($el); 1313 } 1314 }); 1315 $el.on("click", "#mz-search-trigger", function (event) { 1316 event.preventDefault(); 1317 $("#mz-md-filter-page", $el).val(""); 1318 _this.getMemberDirectory($el); 1319 }); 1320 $el.on("click", ".easl-mz-letter-filter a", function (event) { 1321 event.preventDefault(); 1322 $("#mz-md-filter-page", $el).val(""); 1323 if (!$(this).hasClass("mz-active")) { 1324 $("#mz-md-filter-letter", $el).val($(this).data('value')); 1325 $(this).siblings("mz-active").removeClass("mz-active"); 1326 $(this).addClass("mz-active"); 1327 } else { 1328 $("#mz-md-filter-letter", $el).val(""); 1329 $(this).removeClass("mz-active"); 1330 } 1331 _this.getMemberDirectory($el); 1332 }); 1333 $("#mz-md-filter-country", $el).on("change.select2", function (event) { 1334 $("#mz-md-filter-page", $el).val(""); 1335 _this.getMemberDirectory($el); 1336 }); 1337 $("#mz-md-filter-spec", $el).on("change.select2", function (event) { 1338 $("#mz-md-filter-page", $el).val(""); 1339 _this.getMemberDirectory($el); 1340 }); 1341 $el.on("click", ".easl-mz-pagination-list a", function (event) { 1342 var page; 1343 event.preventDefault(); 1344 page = $(this).attr("href").replace("#", ''); 1345 $("#mz-md-filter-page", $el).val(page); 1346 _this.getMemberDirectory($el); 1347 }); 1348 _this.getMemberDirectory($el); 1349 } 1350 }, 1351 getMemberDocuments: function () { 1352 var _this = this; 1353 var $el = $(".easl-mz-mydocs-inner"); 1354 if ($el.length) { 1355 var $membership_docs_con = $("#mz-membership-docs", $el); 1356 var $docs_con = $("#mz-content-docs", $el); 1357 $el.on("mz_loaded:get_members_memberships_notes", function (event, response, method) { 1358 if (response.Status === 200) { 1359 $membership_docs_con.append(response.Html); 1360 $('#mz-membership-docs-wrap').removeClass('easl-mz-hide') 1361 } else if (response.Status === 404) { 1362 1363 } else if (response.Status === 401) { 1364 // TODO-maybe reload 1365 } 1366 $el.removeClass("mz-docs-loading"); 1367 _this.memberDocsEvents($el); 1368 if(!$docs_con.find('.mzmd-docs-card').length) { 1369 $docs_con.remove(); 1370 } 1371 }); 1372 if('yes' !== $el.data('compact')) { 1373 $el.on("mz_loaded:get_members_crm_notes", function (event, response, method) { 1374 if (response.Status === 200) { 1375 $docs_con.append(response.Html); 1376 } else if (response.Status === 404) { 1377 1378 } else if (response.Status === 401) { 1379 // TODO-maybe reload 1380 } 1381 _this.request('get_members_memberships_notes', $el); 1382 }); 1383 this.request('get_members_crm_notes', $el); 1384 }else{ 1385 this.request('get_members_memberships_notes', $el, {compact: $el.data('compact') }); 1386 } 1387 } 1388 }, 1389 memberDocsEvents: function ($el){ 1390 var _this = this; 1391 $('.mz-email-doc', $el).on('click', function (e){ 1392 e.preventDefault(); 1393 var $this = $(this); 1394 if($this.hasClass('mz-doc-processing')) { 1395 return false;
1396 } 1397 $this.addClass('mz-doc-processing'); 1398 $this.one('mz_loaded:get_membership_docs_email', function (event, response, method) { 1399 if (response.Status === 200) { 1400 mzModal.init(false); 1401 mzModal.show('<div class="mz-modal-doc-emailed">' + response.Html + '</div>', 'membership.document.emailed.success'); 1402 } else if (response.Status === 404) { 1403 mzModal.init(false); 1404 mzModal.show('<div class="mz-modal-doc-emailed">' + response.Html + '</div>', 'membership.document.emailed.failed'); 1405 } else if (response.Status === 401) { 1406 // TODO-maybe reload 1407 } 1408 $this.removeClass('mz-doc-processing'); 1409 }); 1410 _this.request('get_membership_docs_email', $this, { 1411 'membership_id': $this.attr('data-membership-id'), 1412 'doc_type': $this.attr('data-doc-type') 1413 }); 1414 }); 1415 }, 1416 initMemberStatsEvents: function ($el) { 1417 $("#mzstat_country", $el).select2({ 1418 closeOnSelect: true, 1419 allowClear: true 1420 }).on("change.select2", function (event) { 1421 $(".mz-country-stats span").removeClass("mz-ms-active"); 1422 var val = $(this).val(); 1423 if (val) { 1424 $(".mz-country-stats").find('#mzcstat-' + val).addClass("mz-ms-active"); 1425 } 1426 }); 1427 }, 1428 initMemberStatistics: function () { 1429 var _this = this; 1430 var $el = $(".mz-statistics-inner"); 1431 if ($el.length) { 1432 $el.on("mz_loaded:" + this.methods.getMemberStats, function (event, response, method) { 1433 if (response.Status === 200) { 1434 $(".mz-stats-container", $el).html(response.Html); 1435 _this.initMemberStatsEvents($el); 1436 $el.trigger('mz-stats-loaded', [response.Data]); 1437 } else if (response.Status === 404) { 1438 $(".mz-stats-container", $el).html("No data found!"); 1439 } else if (response.Status === 401) { 1440 // TODO-maybe reload 1441 } 1442 $el.removeClass("mz-ms-loading"); 1443 }); 1444 this.request(this.methods.getMemberStats, $el); 1445 } 1446 }, 1447 request: function (method, $el, reqData) { 1448 reqData = reqData || {}; 1449 return $.ajax({ 1450 url: this.url, 1451 method: "POST", 1452 data: { 1453 action: this.action, 1454 method: method, 1455 request_data: reqData 1456 }, 1457 success: $.proxy(function (response) { 1458 response && response.Status && $el.trigger("mz_loaded:" + method, [response, method]); 1459 }, this), 1460 dataType: "json" 1461 }); 1462 }, 1463 getMemberDetailsCon: function () { 1464 var $con = $(".easl-mz-container-inner .easl-mz-member-profile-wrap"); 1465 if ($con.length === 0) { 1466 $con = $('<div class="easl-mz-member-profile-wrap"><div class="easl-mz-member-profile-con"><div class="easl-mz-back-link-wrap"><a class="easl-mz-back-link mz-member-profile-back" href="#">Back</a></div><div class="easl-easl-mz-member-profile"></div></div>' + this.loaderHtml + '</div>'); 1467 $(".easl-mz-container-inner").append($con); 1468 } 1469 return $con; 1470 }, 1471 events: function () { 1472 var _this = this; 1473 var $body = $('body'); 1474 $(".mz-forgot-password").on("click", function (event) { 1475 event.preventDefault(); 1476 var $formWrap = $(this).closest(".easl-mz-login-form-wrapper"); 1477 if ($formWrap.hasClass("mz-show-reset-form")) { 1478 $formWrap.removeClass("mz-show-reset-form"); 1479 $(this).html("Forgot your password?"); 1480 } else { 1481 $formWrap.addClass("mz-show-reset-form"); 1482 $(this).html("Login"); 1483 } 1484 }); 1485 1486 $body.on("click", ".mz-member-details-trigger", function (event) { 1487 var $con = _this.getMemberDetailsCon(); 1488 var $conWrap = $(".easl-mz-container-inner"); 1489 var id = $(this).data("memberid"); 1490 event.preventDefault(); 1491 $con.find(".easl-easl-mz-member-profile").html(""); 1492 $con.addClass("mz-mpd-loading");
1493 $conWrap.addClass("easl-mz-mp-show-details").data('easlscrollpos', document.documentElement.scrollTop); 1494 $('html, body').animate({ 1495 scrollTop: $conWrap.offset().top - $('#site-header').height() - 100 1496 }, 275); 1497 $con.one("mz_loaded:" + _this.methods.getMemberDetails, function (event, response, method) { 1498 1499 if (response.Status === 200) { 1500 $con.find(".easl-easl-mz-member-profile").html(response.Html); 1501 } else if (response.Status === 404) { 1502 $(".easl-mz-members-direcoty-content-inner", $el).html("Member not found!"); 1503 } else if (response.Status === 401) { 1504 // TODO-maybe reload 1505 } 1506 $con.removeClass("mz-mpd-loading"); 1507 }); 1508 _this.request(_this.methods.getMemberDetails, $con, { 1509 'member_id': id 1510 }); 1511 }); 1512 $body.on("click", ".mz-member-profile-back", function (event) { 1513 var $conWrap = $(".easl-mz-container-inner"); 1514 event.preventDefault(); 1515 $conWrap.removeClass("easl-mz-mp-show-details"); 1516 var scrollPosition = $conWrap.data('easlscrollpos') || false; 1517 if (scrollPosition) { 1518 $('html, body').animate({ 1519 scrollTop: scrollPosition 1520 }, 275); 1521 } 1522 $conWrap.data('easlscrollpos', false); 1523 }); 1524 $body.on('click', '[href="#jhep_link"]', function(e) { 1525 var $link = $(this); 1526 e.preventDefault(); 1527 mzModal.init(true); 1528 mzModal.show('Please wait while we redirect you'); 1529 $link.one("mz_loaded:get_jhep_access_link", function (event, response, method) { 1530 if (response.Status === 200) { 1531 mzModal.show('We are now redirecting you to the journal site!'); 1532 //window.location.href = response.Data.tickurl; 1533 window.open(response.Data.tickurl, '_blank'); 1534 mzModal.hide(); 1535 } else if (response.Status === 404) { 1536 mzModal.init(); 1537 mzModal.show('JHep access link was not created!'); 1538 // TODO-maybe reload 1539 } else if(response.Status === 401) { 1540 mzModal.init(); 1541 mzModal.show('You must login to get access!'); 1542 // TODO-maybe reload 1543 } 1544 }); 1545 _this.request('get_jhep_access_link', $link); 1546 }); 1547 $(window).on('message', paymentIframeMessage); 1548 }, 1549 loadModules: function () { 1550 this.modulesLoadTrigger = true; 1551 this.getMemberCard(); 1552 this.getFeaturedMembers(); 1553 this.getMembershipForm(); 1554 this.getMemberDocuments(); 1555 this.getNewMembershipForm(); 1556 this.getMembershipBanner(); 1557 this.initMemberDirectory(); 1558 this.initMemberStatistics(); 1559 }, 1560 init: function () { 1561 this.events(); 1562 this.showModuleLoading(); 1563 this.checkStatus(); 1564 //this.getMemberCard(); 1565 this.initNewMemberForm(); 1566 this.resetPassword(); 1567 }, 1568 // Header state classes on <html>, consumed by the CSS that hides the signup 1569 // button and recolours the member icon. The page markup is identical for 1570 // every visitor â it may be served from a full-page cache that knows nothing 1571 // about member sessions â so the header is styled from these classes rather 1572 // than rendered conditionally on the server. 1573 applyMemberUIState: function (loggedIn, activeMember) { 1574 $('html') 1575 .toggleClass('easl-mz-logged-in', !!loggedIn) 1576 .toggleClass('easl-mz-active-member', !!activeMember); 1577 }, 1578 checkStatus: function (){ 1579 var _this = this; 1580 var $el = $('body'); 1581 $el.on("mz_loaded:get_member_session_status", function (event, response, method) { 1582 if (response.Status === 200) { 1583 _this.applyMemberUIState(response.isLoggedIn, response.isActiveMember); 1584 !response.isLoggedOut && !_this.modulesLoadTrigger && _this.loadModules(); 1585 } else { 1586 // Expired or rejected session â fall back to the logged-out header. 1587 _this.applyMemberUIState(false, false); 1588 _this.sessionExpiredModal(); 1589 } 1590 }); 1591 this.request('get_member_session_status', $el); 1592 } 1593 }; 1594 1595 $(document).ready(function () { 1596 // $(".easl-mz-header-login-button").on("click", function (event) { 1597 // event.preventDefault(); 1598 // $(".easl-mz-login-form").toggleClass("easl-active"); 1599 // }); 1600 if (typeof $.fn.select2 !== "undefined") { 1601 $(".easl-mz-select2").length && $(".easl-mz-select2").select2({ 1602 closeOnSelect: true, 1603 allowClear: true, 1604 maximumSelectionLength: 4 1605 }); 1606 } 1607 1608 easlMemberZone.init(); 1609 1610 $('.sp-modal-trigger').click(function(e) { 1611 var url = $(this).attr('href'); 1612 url = url.replace(/\/$/, ''); 1613 e.preventDefault(); 1614 1615 $('.easl-pub-modal-sso-login').data('pub_url', url); 1616 1617 $('.sp-modal-overlay').addClass('active'); 1618 }); 1619 1620 $('.sp-modal-close').click(function(e) { 1621 e.preventDefault(); 1622 $('.sp-modal-overlay').removeClass('active'); 1623 }); 1624 1625 $('.sp-login-from-trigger').click(function(e) { 1626 e.preventDefault(); 1627 $('.sp-modal-overlay').addClass('login-form-active'); 1628 }); 1629 1630 $('.easl-pub-modal-sso-login').on('click', function(e){ 1631 var pub_url = $(this).data('pub_url'); 1632 if(pub_url) {
1633 setCookie('pub_url_to_redirect', pub_url); 1634 } 1635 }); 1636 1637 // Gated CPG teaser CTAs (add the "easl-mz-sso-signin" CSS class to the 1638 // button/link in the Theme Builder template). Remembers the publication 1639 // URL so the SSO callback (EASL_MZ_SSO::handle_auth_code) sends the 1640 // visitor back here after Keycloak login. Set client-side because the 1641 // teaser page is served from the page cache. 1642 $(document).on('click', 'a.easl-mz-sso-signin, .easl-mz-sso-signin a', function () { 1643 document.cookie = 'pub_url_to_redirect=' + encodeURIComponent(window.location.href) + ';path=/'; 1644 }); 1645 }); 1646 1647})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.