| 1 |
var is_submitting = false; |
| 2 |
|
| 3 |
jQuery(document).ready(function($) |
| 4 |
{ |
| 5 |
toggleApplicantRegistrationDepartmentFields(); |
| 6 |
|
| 7 |
$('body').on('change', 'form.applicant-registration-form [name=\'department\'], form.account-requirements-form [name=\'department\']', function() |
| 8 |
{ |
| 9 |
toggleApplicantRegistrationDepartmentFields(); |
| 10 |
}); |
| 11 |
|
| 12 |
if ( jQuery('form.applicant-registration-form select.ph-form-multiselect').length > 0 ) |
| 13 |
{ |
| 14 |
jQuery('form.applicant-registration-form select.ph-form-multiselect').each(function() |
| 15 |
{ |
| 16 |
jQuery(this).multiselect({ |
| 17 |
texts: { |
| 18 |
placeholder: jQuery(this).data('blank-option') |
| 19 |
} |
| 20 |
}); |
| 21 |
}); |
| 22 |
} |
| 23 |
|
| 24 |
if ( jQuery('form.account-requirements-form select.ph-form-multiselect').length > 0 ) |
| 25 |
{ |
| 26 |
jQuery('form.account-requirements-form select.ph-form-multiselect').each(function() |
| 27 |
{ |
| 28 |
jQuery(this).multiselect({ |
| 29 |
texts: { |
| 30 |
placeholder: jQuery(this).data('blank-option') |
| 31 |
} |
| 32 |
}); |
| 33 |
}); |
| 34 |
} |
| 35 |
|
| 36 |
// Login form being submitted |
| 37 |
$('body').on('submit', 'form[name=\'ph_login_form\']', function() |
| 38 |
{ |
| 39 |
if (!is_submitting) |
| 40 |
{ |
| 41 |
is_submitting = true; |
| 42 |
|
| 43 |
var data = $(this).serialize() + '&'+$.param({ 'action': 'propertyhive_login', 'security': propertyhive_account_params.login_nonce }); |
| 44 |
|
| 45 |
var form_obj = $(this); |
| 46 |
|
| 47 |
form_obj.find('#loginError').hide(); |
| 48 |
|
| 49 |
$.post( propertyhive_account_params.ajax_url, data, function(response) |
| 50 |
{ |
| 51 |
if (response.success == true) |
| 52 |
{ |
| 53 |
if ( propertyhive_account_params.redirect_url && propertyhive_account_params.redirect_url != '' ) |
| 54 |
{ |
| 55 |
window.location.href = propertyhive_account_params.redirect_url; |
| 56 |
} |
| 57 |
else |
| 58 |
{ |
| 59 |
if ( propertyhive_account_params.my_account_url && propertyhive_account_params.my_account_url != '' ) |
| 60 |
{ |
| 61 |
window.location.href = propertyhive_account_params.my_account_url; |
| 62 |
} |
| 63 |
else |
| 64 |
{ |
| 65 |
alert('Sorry but no account page has been assigned. Therefore we are unable to redirect.'); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
else |
| 70 |
{ |
| 71 |
form_obj.find('#loginError').fadeIn(); |
| 72 |
} |
| 73 |
|
| 74 |
is_submitting = false; |
| 75 |
|
| 76 |
}); |
| 77 |
} |
| 78 |
|
| 79 |
return false; |
| 80 |
}); |
| 81 |
|
| 82 |
// Registration form being submitted |
| 83 |
$('body').on('submit', 'form[name=\'ph_applicant_registration_form\']', function() |
| 84 |
{ |
| 85 |
if ( !is_submitting ) |
| 86 |
{ |
| 87 |
form_obj = jQuery(this); |
| 88 |
|
| 89 |
if ( propertyhive_account_params.captcha_service == 'recaptcha-v3' && typeof grecaptcha !== 'undefined' ) |
| 90 |
{ |
| 91 |
grecaptcha.execute(propertyhive_account_params.recaptcha_site_key, { action: 'submit' }).then(function(token) |
| 92 |
{ |
| 93 |
jQuery('#g-recaptcha-response').val(token); |
| 94 |
ph_submit_applicant_registration_form(form_obj); // Submit form after getting the new token |
| 95 |
}); |
| 96 |
} |
| 97 |
else |
| 98 |
{ |
| 99 |
ph_submit_applicant_registration_form(form_obj); // If reCAPTCHA is undefined, still submit |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
return false; |
| 104 |
}); |
| 105 |
|
| 106 |
// Account details form being submitted |
| 107 |
$('body').on('submit', 'form[name=\'ph_account_details_form\']', function() |
| 108 |
{ |
| 109 |
if (!is_submitting) |
| 110 |
{ |
| 111 |
is_submitting = true; |
| 112 |
|
| 113 |
var data = $(this).serialize() + '&'+$.param({ 'action': 'propertyhive_save_account_details', 'ph_account_details_security': propertyhive_account_params.userdetails_nonce }); |
| 114 |
|
| 115 |
var form_obj = $(this); |
| 116 |
|
| 117 |
form_obj.find('#detailsSuccess').hide(); |
| 118 |
form_obj.find('#detailsValidation').hide(); |
| 119 |
form_obj.find('#detailsError').hide(); |
| 120 |
|
| 121 |
$.post( propertyhive_account_params.ajax_url, data, function(response) |
| 122 |
{ |
| 123 |
if (response.success == true) |
| 124 |
{ |
| 125 |
form_obj.find('#detailsSuccess').fadeIn(); |
| 126 |
} |
| 127 |
else |
| 128 |
{ |
| 129 |
if (response.reason == 'validation') |
| 130 |
{ |
| 131 |
form_obj.find('#detailsValidation').fadeIn(); |
| 132 |
} |
| 133 |
else |
| 134 |
{ |
| 135 |
form_obj.find('#detailsError').fadeIn(); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
if (response.new_details_nonce) |
| 140 |
{ |
| 141 |
propertyhive_account_params.userdetails_nonce = response.new_details_nonce; |
| 142 |
} |
| 143 |
|
| 144 |
is_submitting = false; |
| 145 |
|
| 146 |
}); |
| 147 |
} |
| 148 |
|
| 149 |
return false; |
| 150 |
}); |
| 151 |
|
| 152 |
// Account requirements form being submitted |
| 153 |
$('body').on('submit', 'form[name=\'ph_account_requirements_form\']', function() |
| 154 |
{ |
| 155 |
if (!is_submitting) |
| 156 |
{ |
| 157 |
is_submitting = true; |
| 158 |
|
| 159 |
var data = $(this).serialize() + '&'+$.param({ 'action': 'propertyhive_save_account_requirements', 'ph_account_requirements_security': propertyhive_account_params.requirements_nonce }); |
| 160 |
|
| 161 |
var form_obj = $(this); |
| 162 |
|
| 163 |
form_obj.find('#requirementsSuccess').hide(); |
| 164 |
form_obj.find('#requirementsValidation').hide(); |
| 165 |
form_obj.find('#requirementsError').hide(); |
| 166 |
|
| 167 |
$.post( propertyhive_account_params.ajax_url, data, function(response) |
| 168 |
{ |
| 169 |
if (response.success == true) |
| 170 |
{ |
| 171 |
form_obj.find('#requirementsSuccess').fadeIn(); |
| 172 |
} |
| 173 |
else |
| 174 |
{ |
| 175 |
if (response.reason == 'validation') |
| 176 |
{ |
| 177 |
form_obj.find('#requirementsValidation').fadeIn(); |
| 178 |
} |
| 179 |
else |
| 180 |
{ |
| 181 |
form_obj.find('#requirementsError').fadeIn(); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
if (response.new_requirements_nonce) |
| 186 |
{ |
| 187 |
propertyhive_account_params.requirements_nonce = response.new_requirements_nonce; |
| 188 |
} |
| 189 |
|
| 190 |
is_submitting = false; |
| 191 |
|
| 192 |
}); |
| 193 |
} |
| 194 |
|
| 195 |
return false; |
| 196 |
}); |
| 197 |
|
| 198 |
$('.my-account-navigation a[href^=\'#\']').on('click', function(e) |
| 199 |
{ |
| 200 |
e.preventDefault(); |
| 201 |
|
| 202 |
// Hide/show sections |
| 203 |
$('.my-account-sections > div').hide(); |
| 204 |
$('.my-account-sections ' + $(this).attr('href')).show(); |
| 205 |
|
| 206 |
// Remove/add active class on nav/tabs |
| 207 |
$('.my-account-navigation a').each(function() |
| 208 |
{ |
| 209 |
$(this).parent().removeClass('active'); |
| 210 |
}); |
| 211 |
$(this).parent().addClass('active'); |
| 212 |
}); |
| 213 |
|
| 214 |
$('a.ph-forgot-password').on('click', function(e) |
| 215 |
{ |
| 216 |
e.preventDefault(); |
| 217 |
|
| 218 |
$('form[name=\'ph_login_form\']').fadeOut(100, function() |
| 219 |
{ |
| 220 |
$('form[name=\'ph_lost_password_form\']').fadeIn(250); |
| 221 |
}); |
| 222 |
}); |
| 223 |
|
| 224 |
$('body').on('submit', 'form[name=\'ph_lost_password_form\']', function() |
| 225 |
{ |
| 226 |
if (!is_submitting) |
| 227 |
{ |
| 228 |
is_submitting = true; |
| 229 |
|
| 230 |
var data = $(this).serialize() + '&'+$.param({ 'action': 'propertyhive_lost_password', 'security': propertyhive_account_params.lost_password_nonce }); |
| 231 |
|
| 232 |
var form_obj = $(this); |
| 233 |
|
| 234 |
form_obj.find('#lostPasswordError').hide(); |
| 235 |
form_obj.find('#lostPasswordSuccess').hide(); |
| 236 |
|
| 237 |
$.post( propertyhive_account_params.ajax_url, data, function(response) |
| 238 |
{ |
| 239 |
if (response.success == true) |
| 240 |
{ |
| 241 |
form_obj.find('#lostPasswordSuccess').fadeIn(); |
| 242 |
} |
| 243 |
else |
| 244 |
{ |
| 245 |
form_obj.find('#lostPasswordError').fadeIn(); |
| 246 |
} |
| 247 |
|
| 248 |
is_submitting = false; |
| 249 |
|
| 250 |
}); |
| 251 |
} |
| 252 |
|
| 253 |
return false; |
| 254 |
}); |
| 255 |
|
| 256 |
$('body').on('submit', 'form[name=\'ph_reset_password_form\']', function() |
| 257 |
{ |
| 258 |
if (!is_submitting) |
| 259 |
{ |
| 260 |
is_submitting = true; |
| 261 |
|
| 262 |
var data = $(this).serialize() + '&'+$.param({ 'action': 'propertyhive_reset_password', 'security': propertyhive_account_params.reset_password_nonce }); |
| 263 |
|
| 264 |
var form_obj = $(this); |
| 265 |
|
| 266 |
form_obj.find('#resetPasswordError').hide(); |
| 267 |
form_obj.find('#resetPasswordSuccess').hide(); |
| 268 |
|
| 269 |
$.post( propertyhive_account_params.ajax_url, data, function(response) |
| 270 |
{ |
| 271 |
if (response.success == true) |
| 272 |
{ |
| 273 |
form_obj.find('#resetPasswordSuccess').fadeIn(); |
| 274 |
} |
| 275 |
else |
| 276 |
{ |
| 277 |
if ( response.errors.length > 0 ) |
| 278 |
{ |
| 279 |
for ( var i in response.errors ) |
| 280 |
{ |
| 281 |
form_obj.find('#resetPasswordError').html(response.errors[i]); |
| 282 |
} |
| 283 |
} |
| 284 |
form_obj.find('#resetPasswordError').fadeIn(); |
| 285 |
} |
| 286 |
|
| 287 |
is_submitting = false; |
| 288 |
|
| 289 |
}); |
| 290 |
} |
| 291 |
|
| 292 |
return false; |
| 293 |
}); |
| 294 |
}); |
| 295 |
|
| 296 |
function ph_submit_applicant_registration_form(form_obj) |
| 297 |
{ |
| 298 |
is_submitting = true; |
| 299 |
|
| 300 |
var data = form_obj.serialize() + '&' + jQuery.param({ 'action': 'propertyhive_applicant_registration', 'security': propertyhive_account_params.register_nonce }); |
| 301 |
|
| 302 |
form_obj.find('#registrationSuccess').hide(); |
| 303 |
form_obj.find('#registrationValidation').hide().text(propertyhive_account_params.default_validation_error_message); |
| 304 |
form_obj.find('#registrationError').hide(); |
| 305 |
|
| 306 |
jQuery.post( propertyhive_account_params.ajax_url, data, function(response) |
| 307 |
{ |
| 308 |
if (response.success == true) |
| 309 |
{ |
| 310 |
if ( propertyhive_account_params.redirect_url && propertyhive_account_params.redirect_url != '' ) |
| 311 |
{ |
| 312 |
window.location.href = propertyhive_account_params.redirect_url; |
| 313 |
} |
| 314 |
else |
| 315 |
{ |
| 316 |
if ( propertyhive_account_params.my_account_url && propertyhive_account_params.my_account_url != '' ) |
| 317 |
{ |
| 318 |
window.location.href = propertyhive_account_params.my_account_url; |
| 319 |
} |
| 320 |
else |
| 321 |
{ |
| 322 |
form_obj.find('#registrationSuccess').fadeIn(); |
| 323 |
|
| 324 |
jQuery('html,body').animate({ |
| 325 |
scrollTop: form_obj.find('#registrationSuccess').offset().top - 200 |
| 326 |
}); |
| 327 |
|
| 328 |
form_obj.trigger("reset"); |
| 329 |
} |
| 330 |
} |
| 331 |
} |
| 332 |
else |
| 333 |
{ |
| 334 |
if (response.reason == 'validation') |
| 335 |
{ |
| 336 |
if ( response.errors.length > 0 ) |
| 337 |
{ |
| 338 |
let error_html = ''; |
| 339 |
for ( var i in response.errors ) |
| 340 |
{ |
| 341 |
if ( error_html != '' ) { error_html += ', '; } |
| 342 |
error_html += response.errors[i]; |
| 343 |
} |
| 344 |
if ( error_html != '' ) |
| 345 |
{ |
| 346 |
form_obj.find('#registrationValidation').text(error_html); |
| 347 |
} |
| 348 |
} |
| 349 |
form_obj.find('#registrationValidation').fadeIn(); |
| 350 |
jQuery('html,body').scrollTop( form_obj.find('#registrationValidation').offset().top ); |
| 351 |
} |
| 352 |
else |
| 353 |
{ |
| 354 |
form_obj.find('#registrationError').fadeIn(); |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
is_submitting = false; |
| 359 |
|
| 360 |
if ( propertyhive_account_params.captcha_service == 'recaptcha' ) |
| 361 |
{ |
| 362 |
// Reset reCAPTCHA for v2 (checkbox version) |
| 363 |
if (typeof grecaptcha !== 'undefined' && typeof grecaptcha.reset === 'function') { |
| 364 |
grecaptcha.reset(); |
| 365 |
} |
| 366 |
} |
| 367 |
}); |
| 368 |
} |
| 369 |
|
| 370 |
jQuery(window).on('load', function() { |
| 371 |
|
| 372 |
if ( window.location.hash != '' ) |
| 373 |
{ |
| 374 |
if ( jQuery('.my-account-navigation a[href=\'' + window.location.hash + '\']').length > 0 ) |
| 375 |
{ |
| 376 |
var this_href = window.location.hash; |
| 377 |
// Hide/show sections |
| 378 |
jQuery('.my-account-sections > div').hide(); |
| 379 |
jQuery('.my-account-sections ' + this_href).show(); |
| 380 |
|
| 381 |
// Remove/add active class on nav/tabs |
| 382 |
jQuery('.my-account-navigation a').each(function() |
| 383 |
{ |
| 384 |
jQuery(this).parent().removeClass('active'); |
| 385 |
}); |
| 386 |
jQuery('.my-account-navigation a[href=\'' + window.location.hash + '\']').parent().addClass('active'); |
| 387 |
} |
| 388 |
} |
| 389 |
|
| 390 |
}); |
| 391 |
|
| 392 |
jQuery(window).resize(function() { |
| 393 |
toggleDepartmentFields(); |
| 394 |
}); |
| 395 |
|
| 396 |
function toggleApplicantRegistrationDepartmentFields() |
| 397 |
{ |
| 398 |
if (jQuery('form.applicant-registration-form').length > 0 || jQuery('form.account-requirements-form').length > 0) |
| 399 |
{ |
| 400 |
// There may be multiple forms on the page so treat each one individually |
| 401 |
jQuery('form.applicant-registration-form, form.account-requirements-form').each(function() |
| 402 |
{ |
| 403 |
var selectedDepartment = "residential-sales"; // TODO: Use default from settings |
| 404 |
|
| 405 |
var departmentEl = jQuery(this).find('[name=\'department\']') |
| 406 |
if (departmentEl.length > 0) |
| 407 |
{ |
| 408 |
switch (departmentEl.prop('tagName').toLowerCase()) |
| 409 |
{ |
| 410 |
case "select": |
| 411 |
{ |
| 412 |
var selected = departmentEl; |
| 413 |
break; |
| 414 |
} |
| 415 |
default: |
| 416 |
{ |
| 417 |
if ( departmentEl.attr('type') == 'hidden' ) |
| 418 |
{ |
| 419 |
var selected = departmentEl; |
| 420 |
} |
| 421 |
else |
| 422 |
{ |
| 423 |
var selected = departmentEl.filter(':checked'); |
| 424 |
} |
| 425 |
} |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
jQuery(this).find('.sales-only').hide(); |
| 430 |
jQuery(this).find('.lettings-only').hide(); |
| 431 |
jQuery(this).find('.residential-only').hide(); |
| 432 |
jQuery(this).find('.commercial-only').hide(); |
| 433 |
|
| 434 |
if (selected.length > 0) |
| 435 |
{ |
| 436 |
selectedDepartment = selected.val(); |
| 437 |
|
| 438 |
// controls won't always be display:block so we should get the |
| 439 |
// first visible component (that isnt sales/lettings-only) and |
| 440 |
// use that display |
| 441 |
var display = 'block'; |
| 442 |
jQuery(this).find('.control').each(function() |
| 443 |
{ |
| 444 |
if (!jQuery(this).hasClass('.sales-only') && !jQuery(this).hasClass('.lettings-only') && !jQuery(this).hasClass('.residential-only') && !jQuery(this).hasClass('.commercial-only') && jQuery(this).css('display') != 'none') |
| 445 |
{ |
| 446 |
display = jQuery(this).css('display'); |
| 447 |
} |
| 448 |
}); |
| 449 |
|
| 450 |
if ( selectedDepartment == 'residential-sales' || ( propertyhive_account_params.custom_departments[selectedDepartment] && propertyhive_account_params.custom_departments[selectedDepartment].based_on == 'residential-sales' ) ) |
| 451 |
{ |
| 452 |
jQuery(this).find('.sales-only').css('display', display); |
| 453 |
jQuery(this).find('.residential-only').css('display', display); |
| 454 |
} |
| 455 |
else if ( selectedDepartment == 'residential-lettings' || ( propertyhive_account_params.custom_departments[selectedDepartment] && propertyhive_account_params.custom_departments[selectedDepartment].based_on == 'residential-lettings' ) ) |
| 456 |
{ |
| 457 |
jQuery(this).find('.lettings-only').css('display', display); |
| 458 |
jQuery(this).find('.residential-only').css('display', display); |
| 459 |
} |
| 460 |
else if ( selectedDepartment == 'commercial' || ( propertyhive_account_params.custom_departments[selectedDepartment] && propertyhive_account_params.custom_departments[selectedDepartment].based_on == 'commercial' ) ) |
| 461 |
{ |
| 462 |
jQuery(this).find('.commercial-only').css('display', display); |
| 463 |
} |
| 464 |
} |
| 465 |
}); |
| 466 |
} |
| 467 |
} |