| 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 |
// Login form being submitted |
| 13 |
$('body').on('submit', 'form[name=\'ph_login_form\']', function() |
| 14 |
{ |
| 15 |
if (!is_submitting) |
| 16 |
{ |
| 17 |
is_submitting = true; |
| 18 |
|
| 19 |
var data = $(this).serialize() + '&'+$.param({ 'action': 'propertyhive_login', 'security': propertyhive_account_params.login_nonce }); |
| 20 |
|
| 21 |
var form_obj = $(this); |
| 22 |
|
| 23 |
form_obj.find('#loginError').hide(); |
| 24 |
|
| 25 |
$.post( propertyhive_account_params.ajax_url, data, function(response) |
| 26 |
{ |
| 27 |
if (response.success == true) |
| 28 |
{ |
| 29 |
if ( propertyhive_account_params.redirect_url && propertyhive_account_params.redirect_url != '' ) |
| 30 |
{ |
| 31 |
window.location.href = propertyhive_account_params.redirect_url; |
| 32 |
} |
| 33 |
else |
| 34 |
{ |
| 35 |
if ( propertyhive_account_params.my_account_url && propertyhive_account_params.my_account_url != '' ) |
| 36 |
{ |
| 37 |
window.location.href = propertyhive_account_params.my_account_url; |
| 38 |
} |
| 39 |
else |
| 40 |
{ |
| 41 |
alert('Sorry but no account page has been assigned. Therefore we are unable to redirect.'); |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
else |
| 46 |
{ |
| 47 |
form_obj.find('#loginError').fadeIn(); |
| 48 |
} |
| 49 |
|
| 50 |
is_submitting = false; |
| 51 |
|
| 52 |
}); |
| 53 |
} |
| 54 |
|
| 55 |
return false; |
| 56 |
}); |
| 57 |
|
| 58 |
// Registration form being submitted |
| 59 |
$('body').on('submit', 'form[name=\'ph_applicant_registration_form\']', function() |
| 60 |
{ |
| 61 |
if (!is_submitting) |
| 62 |
{ |
| 63 |
is_submitting = true; |
| 64 |
|
| 65 |
var data = $(this).serialize() + '&'+$.param({ 'action': 'propertyhive_applicant_registration', 'security': propertyhive_account_params.register_nonce }); |
| 66 |
|
| 67 |
var form_obj = $(this); |
| 68 |
|
| 69 |
form_obj.find('#registrationSuccess').hide(); |
| 70 |
form_obj.find('#registrationValidation').hide(); |
| 71 |
form_obj.find('#registrationError').hide(); |
| 72 |
|
| 73 |
$.post( propertyhive_account_params.ajax_url, data, function(response) |
| 74 |
{ |
| 75 |
if (response.success == true) |
| 76 |
{ |
| 77 |
if ( propertyhive_account_params.redirect_url && propertyhive_account_params.redirect_url != '' ) |
| 78 |
{ |
| 79 |
window.location.href = propertyhive_account_params.redirect_url; |
| 80 |
} |
| 81 |
else |
| 82 |
{ |
| 83 |
if ( propertyhive_account_params.my_account_url && propertyhive_account_params.my_account_url != '' ) |
| 84 |
{ |
| 85 |
window.location.href = propertyhive_account_params.my_account_url; |
| 86 |
} |
| 87 |
else |
| 88 |
{ |
| 89 |
form_obj.find('#registrationSuccess').fadeIn(); |
| 90 |
|
| 91 |
$('html,body').animate({ |
| 92 |
scrollTop: form_obj.find('#registrationSuccess').offset().top - 200 |
| 93 |
}); |
| 94 |
|
| 95 |
form_obj.trigger("reset"); |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
else |
| 100 |
{ |
| 101 |
form_obj.find('#registrationValidation').html('Please ensure all required fields have been completed'); |
| 102 |
if (response.reason == 'validation') |
| 103 |
{ |
| 104 |
if ( response.errors.length > 0 ) |
| 105 |
{ |
| 106 |
var error_html = ''; |
| 107 |
for ( var i in response.errors ) |
| 108 |
{ |
| 109 |
error_html += response.errors[i] + '<br>'; |
| 110 |
} |
| 111 |
if ( error_html != '' ) |
| 112 |
{ |
| 113 |
form_obj.find('#registrationValidation').html(error_html); |
| 114 |
} |
| 115 |
} |
| 116 |
form_obj.find('#registrationValidation').fadeIn(); |
| 117 |
} |
| 118 |
else |
| 119 |
{ |
| 120 |
form_obj.find('#registrationError').fadeIn(); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
is_submitting = false; |
| 125 |
|
| 126 |
if ( typeof grecaptcha != 'undefined' ) |
| 127 |
{ |
| 128 |
grecaptcha.reset(); |
| 129 |
} |
| 130 |
|
| 131 |
}); |
| 132 |
} |
| 133 |
|
| 134 |
return false; |
| 135 |
}); |
| 136 |
|
| 137 |
// Account details form being submitted |
| 138 |
$('body').on('submit', 'form[name=\'ph_account_details_form\']', function() |
| 139 |
{ |
| 140 |
if (!is_submitting) |
| 141 |
{ |
| 142 |
is_submitting = true; |
| 143 |
|
| 144 |
var data = $(this).serialize() + '&'+$.param({ 'action': 'propertyhive_save_account_details', 'security': propertyhive_account_params.details_nonce }); |
| 145 |
|
| 146 |
var form_obj = $(this); |
| 147 |
|
| 148 |
form_obj.find('#detailsSuccess').hide(); |
| 149 |
form_obj.find('#detailsValidation').hide(); |
| 150 |
form_obj.find('#detailsError').hide(); |
| 151 |
|
| 152 |
$.post( propertyhive_account_params.ajax_url, data, function(response) |
| 153 |
{ |
| 154 |
if (response.success == true) |
| 155 |
{ |
| 156 |
form_obj.find('#detailsSuccess').fadeIn(); |
| 157 |
} |
| 158 |
else |
| 159 |
{ |
| 160 |
if (response.reason == 'validation') |
| 161 |
{ |
| 162 |
form_obj.find('#detailsValidation').fadeIn(); |
| 163 |
} |
| 164 |
else |
| 165 |
{ |
| 166 |
form_obj.find('#detailsError').fadeIn(); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
is_submitting = false; |
| 171 |
|
| 172 |
}); |
| 173 |
} |
| 174 |
|
| 175 |
return false; |
| 176 |
}); |
| 177 |
|
| 178 |
// Account requirements form being submitted |
| 179 |
$('body').on('submit', 'form[name=\'ph_account_requirements_form\']', function() |
| 180 |
{ |
| 181 |
if (!is_submitting) |
| 182 |
{ |
| 183 |
is_submitting = true; |
| 184 |
|
| 185 |
var data = $(this).serialize() + '&'+$.param({ 'action': 'propertyhive_save_account_requirements', 'security': propertyhive_account_params.requirements_nonce }); |
| 186 |
|
| 187 |
var form_obj = $(this); |
| 188 |
|
| 189 |
form_obj.find('#requirementsSuccess').hide(); |
| 190 |
form_obj.find('#requirementsValidation').hide(); |
| 191 |
form_obj.find('#requirementsError').hide(); |
| 192 |
|
| 193 |
$.post( propertyhive_account_params.ajax_url, data, function(response) |
| 194 |
{ |
| 195 |
if (response.success == true) |
| 196 |
{ |
| 197 |
form_obj.find('#requirementsSuccess').fadeIn(); |
| 198 |
} |
| 199 |
else |
| 200 |
{ |
| 201 |
if (response.reason == 'validation') |
| 202 |
{ |
| 203 |
form_obj.find('#requirementsValidation').fadeIn(); |
| 204 |
} |
| 205 |
else |
| 206 |
{ |
| 207 |
form_obj.find('#requirementsError').fadeIn(); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
is_submitting = false; |
| 212 |
|
| 213 |
}); |
| 214 |
} |
| 215 |
|
| 216 |
return false; |
| 217 |
}); |
| 218 |
|
| 219 |
$('.my-account-navigation a[href^=\'#\']').click(function(e) |
| 220 |
{ |
| 221 |
e.preventDefault(); |
| 222 |
|
| 223 |
// Hide/show sections |
| 224 |
$('.my-account-sections > div').hide(); |
| 225 |
$('.my-account-sections ' + $(this).attr('href')).show(); |
| 226 |
|
| 227 |
// Remove/add active class on nav/tabs |
| 228 |
$('.my-account-navigation a').each(function() |
| 229 |
{ |
| 230 |
$(this).parent().removeClass('active'); |
| 231 |
}); |
| 232 |
$(this).parent().addClass('active'); |
| 233 |
}); |
| 234 |
}); |
| 235 |
|
| 236 |
jQuery(window).resize(function() { |
| 237 |
toggleDepartmentFields(); |
| 238 |
}); |
| 239 |
|
| 240 |
function toggleApplicantRegistrationDepartmentFields() |
| 241 |
{ |
| 242 |
if (jQuery('form.applicant-registration-form').length > 0 || jQuery('form.account-requirements-form').length > 0) |
| 243 |
{ |
| 244 |
// There may be multiple forms on the page so treat each one individually |
| 245 |
jQuery('form.applicant-registration-form, form.account-requirements-form').each(function() |
| 246 |
{ |
| 247 |
var selectedDepartment = "residential-sales"; // TODO: Use default from settings |
| 248 |
|
| 249 |
var departmentEl = jQuery(this).find('[name=\'department\']') |
| 250 |
if (departmentEl.length > 0) |
| 251 |
{ |
| 252 |
switch (departmentEl.prop('tagName').toLowerCase()) |
| 253 |
{ |
| 254 |
case "select": |
| 255 |
{ |
| 256 |
var selected = departmentEl; |
| 257 |
break; |
| 258 |
} |
| 259 |
default: |
| 260 |
{ |
| 261 |
if ( departmentEl.attr('type') == 'hidden' ) |
| 262 |
{ |
| 263 |
var selected = departmentEl; |
| 264 |
} |
| 265 |
else |
| 266 |
{ |
| 267 |
var selected = departmentEl.filter(':checked'); |
| 268 |
} |
| 269 |
} |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
jQuery(this).find('.sales-only').hide(); |
| 274 |
jQuery(this).find('.lettings-only').hide(); |
| 275 |
jQuery(this).find('.residential-only').hide(); |
| 276 |
jQuery(this).find('.commercial-only').hide(); |
| 277 |
|
| 278 |
if (selected.length > 0) |
| 279 |
{ |
| 280 |
selectedDepartment = selected.val(); |
| 281 |
|
| 282 |
// controls won't always be display:block so we should get the |
| 283 |
// first visible component (that isnt sales/lettings-only) and |
| 284 |
// use that display |
| 285 |
var display = 'block'; |
| 286 |
jQuery(this).find('.control').each(function() |
| 287 |
{ |
| 288 |
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') |
| 289 |
{ |
| 290 |
display = jQuery(this).css('display'); |
| 291 |
} |
| 292 |
}); |
| 293 |
|
| 294 |
if (selectedDepartment == 'residential-sales') |
| 295 |
{ |
| 296 |
jQuery(this).find('.sales-only').css('display', display); |
| 297 |
jQuery(this).find('.residential-only').css('display', display); |
| 298 |
} |
| 299 |
else if (selectedDepartment == 'residential-lettings') |
| 300 |
{ |
| 301 |
jQuery(this).find('.lettings-only').css('display', display); |
| 302 |
jQuery(this).find('.residential-only').css('display', display); |
| 303 |
} |
| 304 |
else if (selectedDepartment == 'commercial') |
| 305 |
{ |
| 306 |
jQuery(this).find('.commercial-only').css('display', display); |
| 307 |
} |
| 308 |
} |
| 309 |
}); |
| 310 |
} |
| 311 |
} |