| @@ -1,6 +1,88 @@ | ||
| 1 | +var initial_save_changes_value = ''; | |
| 2 | + | |
| 1 | 3 | jQuery( function($){ |
| 2 | 4 | |
| 5 | + // sortable custom field tables | |
| 6 | + | |
| 7 | + $('.ph_customfields.sortable-custom-field').each(function() | |
| 8 | + { | |
| 9 | + var taxonomy = $(this).data('taxonomy'); | |
| 10 | + | |
| 11 | + if ( taxonomy == '' ) | |
| 12 | + { | |
| 13 | + return; | |
| 14 | + } | |
| 15 | + | |
| 16 | + $(this).find('tbody').sortable({ | |
| 17 | + axis: 'y', | |
| 18 | + update: function (event, ui) | |
| 19 | + { | |
| 20 | + var data = $(this).sortable('serialize') + '&'+ $.param({ 'action': 'propertyhive_save_term_order', 'taxonomy': taxonomy, 'security': propertyhive_admin_settings.ajax_nonce }); | |
| 21 | + | |
| 22 | + $.ajax({ | |
| 23 | + data: data, | |
| 24 | + type: 'POST', | |
| 25 | + url: ajaxurl | |
| 26 | + }); | |
| 27 | + } | |
| 28 | + }); | |
| 29 | + }); | |
| 30 | + | |
| 31 | + // | |
| 32 | + | |
| 33 | + initial_save_changes_value = (jQuery('p.submit button.button-primary').length > 0) ? jQuery('p.submit button.button-primary').text() : ''; | |
| 34 | + | |
| 35 | + $('a#add_department').click(function(e) | |
| 36 | + { | |
| 37 | + e.preventDefault(); | |
| 38 | + | |
| 39 | + var new_department_html = $('#active_department_template').html(); | |
| 40 | + | |
| 41 | + new_department_html = new_department_html.replace(/template/g, 'phnew-' + $('#propertyhive_new_custom_departments').val()); | |
| 42 | + | |
| 43 | + $('#active_departments').append(new_department_html); | |
| 44 | + | |
| 45 | + var new_custom_departments = $('#propertyhive_custom_departments').val(); | |
| 46 | + if ( new_custom_departments != '' ) | |
| 47 | + { | |
| 48 | + new_custom_departments += ','; | |
| 49 | + } | |
| 50 | + new_custom_departments += 'phnew-' + $('#propertyhive_new_custom_departments').val(); | |
| 51 | + $('#propertyhive_custom_departments').val( new_custom_departments ); | |
| 52 | + | |
| 53 | + $('#propertyhive_new_custom_departments').val( parseInt($('#propertyhive_new_custom_departments').val()) + 1 ); | |
| 54 | + }); | |
| 55 | + | |
| 56 | + $(document).on('click', 'a.delete-department', function(e) | |
| 57 | + { | |
| 58 | + e.preventDefault(); | |
| 59 | + | |
| 60 | + var confirmBox = confirm('Are you sure you wish to delete this department?'); | |
| 61 | + | |
| 62 | + if (confirmBox) | |
| 63 | + { | |
| 64 | + var custom_department_key = $(this).attr('data-department'); | |
| 65 | + | |
| 66 | + $('#propertyhive_active_department_fieldset_' + custom_department_key).remove(); | |
| 67 | + | |
| 68 | + var new_custom_departments = ''; | |
| 69 | + var existing_new_custom_departments = $('#propertyhive_custom_departments').val().split(","); | |
| 70 | + for ( var i in existing_new_custom_departments ) | |
| 71 | + { | |
| 72 | + if ( existing_new_custom_departments[i] != custom_department_key ) | |
| 73 | + { | |
| 74 | + if ( new_custom_departments != '' ) | |
| 75 | + { | |
| 76 | + new_custom_departments += ','; | |
| 77 | + } | |
| 78 | + new_custom_departments += existing_new_custom_departments[i]; | |
| 79 | + } | |
| 80 | + } | |
| 81 | + $('#propertyhive_custom_departments').val( new_custom_departments ); | |
| 82 | + } | |
| 83 | + }); | |
| 84 | + | |
| 3 | 85 | $('input.colorpick').wpColorPicker(); |
| 4 | 86 | |
| 5 | 87 | $('form').submit(function() |
| 6 | 88 | { |
| @@ -104,8 +186,29 @@ | ||
| 104 | 186 | |
| 105 | 187 | return false; |
| 106 | 188 | }); |
| 107 | 189 | |
| 190 | + $('.select_all').change(function() | |
| 191 | + { | |
| 192 | + if ( this.checked ) | |
| 193 | + { | |
| 194 | + $('input[name=\'term_id[]\']').attr('checked', 'checked'); | |
| 195 | + | |
| 196 | + // If at least one has been checked, enable Delete Selected button | |
| 197 | + if ( $('input[name=\'term_id[]\']:checked').length > 0 ) | |
| 198 | + { | |
| 199 | + $('a.batch-delete').attr('disabled', false); | |
| 200 | + } | |
| 201 | + } | |
| 202 | + else | |
| 203 | + { | |
| 204 | + $('input[name=\'term_id[]\']').removeAttr('checked'); | |
| 205 | + | |
| 206 | + // Disable Delete Selected button | |
| 207 | + $('a.batch-delete').attr('disabled', 'disabled'); | |
| 208 | + } | |
| 209 | + }); | |
| 210 | + | |
| 108 | 211 | $('input[name=\'term_id[]\']').change(function() |
| 109 | 212 | { |
| 110 | 213 | if ( $('input[name=\'term_id[]\']:checked').length > 0 ) |
| 111 | 214 | { |
| @@ -114,8 +217,14 @@ | ||
| 114 | 217 | else |
| 115 | 218 | { |
| 116 | 219 | $('a.batch-delete').attr('disabled', 'disabled'); |
| 117 | 220 | } |
| 221 | + | |
| 222 | + // If we're unchecking a term, uncheck the Select All box | |
| 223 | + if ( !this.checked ) | |
| 224 | + { | |
| 225 | + $('.select_all').removeAttr('checked'); | |
| 226 | + } | |
| 118 | 227 | }); |
| 119 | 228 | |
| 120 | 229 | jQuery('select[name=\'propertyhive_countries[]\']').change(function() |
| 121 | 230 | { |
| @@ -127,9 +236,252 @@ | ||
| 127 | 236 | { |
| 128 | 237 | toggle_department_specific_options(); |
| 129 | 238 | }); |
| 130 | 239 | toggle_department_specific_options(); |
| 240 | + | |
| 241 | + jQuery('[name=\'propertyhive_maps_provider\']').change(function() | |
| 242 | + { | |
| 243 | + ph_toggle_maps_provider_options(); | |
| 244 | + }); | |
| 245 | + ph_toggle_maps_provider_options(); | |
| 246 | + | |
| 247 | + jQuery('[name=\'propertyhive_geocoding_provider\']').change(function() | |
| 248 | + { | |
| 249 | + ph_toggle_geocoding_provider_options(); | |
| 250 | + }); | |
| 251 | + ph_toggle_geocoding_provider_options(); | |
| 252 | + | |
| 253 | + jQuery('[name=\'propertyhive_auto_incremental_reference_numbers\']').change(function() | |
| 254 | + { | |
| 255 | + ph_toggle_auto_incremental_reference_number_options(); | |
| 256 | + }); | |
| 257 | + ph_toggle_auto_incremental_reference_number_options(); | |
| 258 | + | |
| 259 | + jQuery('.pro-feature-settings .pro-filters ul li a').click(function(e) | |
| 260 | + { | |
| 261 | + e.preventDefault(); | |
| 262 | + | |
| 263 | + var data_filter = jQuery(this).data('filter'); | |
| 264 | + | |
| 265 | + jQuery('.pro-feature-settings .pro-filters ul li').removeClass('active'); | |
| 266 | + jQuery(this).parent().addClass('active'); | |
| 267 | + | |
| 268 | + if ( data_filter == '' ) | |
| 269 | + { | |
| 270 | + jQuery('.pro-feature-settings .pro-features ul li').hide(); | |
| 271 | + jQuery('.pro-feature-settings .pro-features ul li').fadeIn('fast'); | |
| 272 | + } | |
| 273 | + else | |
| 274 | + { | |
| 275 | + jQuery('.pro-feature-settings .pro-features ul li').hide(); | |
| 276 | + jQuery('.pro-feature-settings .pro-features ul li.' + data_filter).fadeIn('fast'); | |
| 277 | + } | |
| 278 | + | |
| 279 | + ph_resize_pro_features_list(); | |
| 280 | + }); | |
| 281 | + | |
| 282 | + if ( jQuery('.pro-feature-settings .pro-filters').length > 0 ) | |
| 283 | + { | |
| 284 | + jQuery('.pro-feature-settings .pro-filters ul li.active a').trigger('click'); | |
| 285 | + } | |
| 286 | + | |
| 287 | + jQuery('.pro-feature-settings input[name=\'active_plugins[]\']').change(function() | |
| 288 | + { | |
| 289 | + var parent_el = jQuery(this); | |
| 290 | + var is_checked = parent_el.is(':checked'); | |
| 291 | + | |
| 292 | + var slug = parent_el.val(); | |
| 293 | + | |
| 294 | + jQuery(this).parent().next('.loading').show(); | |
| 295 | + jQuery(this).parent().hide(); | |
| 296 | + | |
| 297 | + if ( is_checked ) | |
| 298 | + { | |
| 299 | + // need to install/activate plugin | |
| 300 | + jQuery.ajax({ | |
| 301 | + url : ajaxurl, | |
| 302 | + method: 'POST', | |
| 303 | + data : { | |
| 304 | + action: "propertyhive_activate_pro_feature", | |
| 305 | + slug : slug, | |
| 306 | + _ajax_nonce: propertyhive_admin_settings.ajax_nonce | |
| 307 | + }, | |
| 308 | + dataType : "json", | |
| 309 | + success: function(response) | |
| 310 | + { | |
| 311 | + if ( response.success === true ) | |
| 312 | + { | |
| 313 | + if ( typeof response.data !== 'undefined' && typeof response.data.activateUrl !== 'undefined' ) | |
| 314 | + { | |
| 315 | + jQuery.ajax({ | |
| 316 | + url : response.data.activateUrl, | |
| 317 | + method: 'GET', | |
| 318 | + data : {}, | |
| 319 | + success: function(response) | |
| 320 | + { | |
| 321 | + window.location.href = propertyhive_admin_settings.features_settings_url + '&successmessage=1' + ( (jQuery('.pro-filters li.active a').data('filter') != '') ? '&profilter=' + jQuery('.pro-filters li.active a').data('filter') : '' ); | |
| 322 | + } | |
| 323 | + }); | |
| 324 | + } | |
| 325 | + else | |
| 326 | + { | |
| 327 | + window.location.href = propertyhive_admin_settings.features_settings_url + '&successmessage=1' + ( (jQuery('.pro-filters li.active a').data('filter') != '') ? '&profilter=' + jQuery('.pro-filters li.active a').data('filter') : '' ); | |
| 328 | + } | |
| 329 | + } | |
| 330 | + else | |
| 331 | + { | |
| 332 | + parent_el.prop('checked', false); | |
| 333 | + parent_el.parent().next('.loading').hide(); | |
| 334 | + parent_el.parent().show(); | |
| 335 | + alert(response.data.errorMessage); | |
| 336 | + } | |
| 337 | + } | |
| 338 | + }); | |
| 339 | + } | |
| 340 | + else | |
| 341 | + { | |
| 342 | + // need to deactivate plugin | |
| 343 | + jQuery.ajax({ | |
| 344 | + url : ajaxurl, | |
| 345 | + method: 'POST', | |
| 346 | + data : { | |
| 347 | + action: "propertyhive_deactivate_pro_feature", | |
| 348 | + slug : slug, | |
| 349 | + _ajax_nonce: propertyhive_admin_settings.ajax_nonce | |
| 350 | + }, | |
| 351 | + dataType : "json", | |
| 352 | + success: function(response) | |
| 353 | + { | |
| 354 | + if ( response.success === true ) | |
| 355 | + { | |
| 356 | + window.location.href = propertyhive_admin_settings.features_settings_url + '&successmessage=2' + ( (jQuery('.pro-filters li.active a').data('filter') != '') ? '&profilter=' + jQuery('.pro-filters li.active a').data('filter') : '' ); | |
| 357 | + } | |
| 358 | + else | |
| 359 | + { | |
| 360 | + parent_el.prop('checked', 'checked'); | |
| 361 | + parent_el.parent().next('.loading').hide(); | |
| 362 | + parent_el.parent().show(); | |
| 363 | + alert(response.data.errorMessage); | |
| 364 | + } | |
| 365 | + } | |
| 366 | + }); | |
| 367 | + } | |
| 368 | + }); | |
| 369 | + | |
| 370 | + if ( jQuery('[name=\'propertyhive_license_type\']').length > 0 ) | |
| 371 | + { | |
| 372 | + ph_toggle_license_key_settings(); | |
| 373 | + | |
| 374 | + jQuery('[name=\'propertyhive_license_type\']').change(function() | |
| 375 | + { | |
| 376 | + ph_toggle_license_key_settings(); | |
| 377 | + }); | |
| 378 | + } | |
| 379 | + | |
| 380 | + ph_resize_pro_features_list(); | |
| 131 | 381 | }); |
| 382 | + | |
| 383 | +jQuery(window).on( "resize", function() | |
| 384 | +{ | |
| 385 | + ph_resize_pro_features_list(); | |
| 386 | +}); | |
| 387 | + | |
| 388 | +function ph_resize_pro_features_list() | |
| 389 | +{ | |
| 390 | + if ( jQuery('.pro-features').length > 0 ) | |
| 391 | + { | |
| 392 | + jQuery('.pro-features ul li .inner').css('height', 'auto'); | |
| 393 | + | |
| 394 | + var max_height = 0; | |
| 395 | + jQuery('.pro-features ul li .inner').each(function() | |
| 396 | + { | |
| 397 | + if ( jQuery(this).parent().css('display') != 'none' && jQuery(this).height() > max_height ) | |
| 398 | + { | |
| 399 | + max_height = jQuery(this).height(); | |
| 400 | + } | |
| 401 | + }); | |
| 402 | + | |
| 403 | + jQuery('.pro-features ul li .inner').css('height', max_height + 'px'); | |
| 404 | + jQuery('.pro-features ul li').css('visibility', 'visible'); | |
| 405 | + } | |
| 406 | +} | |
| 407 | + | |
| 408 | +function ph_toggle_license_key_settings() | |
| 409 | +{ | |
| 410 | + if ( jQuery('[name=\'propertyhive_license_type\']:checked').val() == 'old' ) | |
| 411 | + { | |
| 412 | + jQuery('#row_pro_license_key_info').hide(); | |
| 413 | + jQuery('#row_pro_license_key_display').hide(); | |
| 414 | + jQuery('#row_propertyhive_pro_license_key').hide(); | |
| 415 | + jQuery('#row_license_key_info').show(); | |
| 416 | + jQuery('#row_propertyhive_license_key').show(); | |
| 417 | + jQuery('p.submit button.button-primary').text(initial_save_changes_value); | |
| 418 | + } | |
| 419 | + else | |
| 420 | + { | |
| 421 | + jQuery('#row_pro_license_key_info').show(); | |
| 422 | + jQuery('#row_propertyhive_pro_license_key').show(); | |
| 423 | + jQuery('#row_pro_license_key_display').show(); | |
| 424 | + jQuery('#row_license_key_info').hide(); | |
| 425 | + jQuery('#row_propertyhive_license_key').hide(); | |
| 426 | + | |
| 427 | + if ( propertyhive_admin_settings.valid_pro_license_key ) | |
| 428 | + { | |
| 429 | + jQuery('p.submit button.button-primary').text('Deactivate key'); | |
| 430 | + } | |
| 431 | + else | |
| 432 | + { | |
| 433 | + jQuery('p.submit button.button-primary').text('Activate key'); | |
| 434 | + } | |
| 435 | + } | |
| 436 | +} | |
| 437 | + | |
| 438 | +function ph_toggle_maps_provider_options() | |
| 439 | +{ | |
| 440 | + jQuery('#row_propertyhive_google_maps_api_key').hide(); | |
| 441 | + jQuery('#row_propertyhive_mapbox_api_key').hide(); | |
| 442 | + | |
| 443 | + if ( jQuery('[name=\'propertyhive_maps_provider\']:checked').val() == 'mapbox' ) | |
| 444 | + { | |
| 445 | + jQuery('#row_propertyhive_mapbox_api_key').show(); | |
| 446 | + } | |
| 447 | + if ( jQuery('[name=\'propertyhive_maps_provider\']:checked').val() == '' ) | |
| 448 | + { | |
| 449 | + jQuery('#row_propertyhive_google_maps_api_key').show(); | |
| 450 | + } | |
| 451 | +} | |
| 452 | + | |
| 453 | +function ph_toggle_geocoding_provider_options() | |
| 454 | +{ | |
| 455 | + jQuery('#row_propertyhive_google_maps_geocoding_api_key').hide(); | |
| 456 | + jQuery('#row_propertyhive_mapbox_geocoding_api_key').hide(); | |
| 457 | + jQuery('#row_propertyhive_osm_html').hide(); | |
| 458 | + | |
| 459 | + if ( jQuery('[name=\'propertyhive_geocoding_provider\']:checked').val() == 'mapbox' ) | |
| 460 | + { | |
| 461 | + jQuery('#row_propertyhive_mapbox_geocoding_api_key').show(); | |
| 462 | + } | |
| 463 | + if ( jQuery('[name=\'propertyhive_geocoding_provider\']:checked').val() == 'osm' ) | |
| 464 | + { | |
| 465 | + jQuery('#row_propertyhive_osm_html').show(); | |
| 466 | + } | |
| 467 | + if ( jQuery('[name=\'propertyhive_geocoding_provider\']:checked').val() == '' ) | |
| 468 | + { | |
| 469 | + jQuery('#row_propertyhive_google_maps_geocoding_api_key').show(); | |
| 470 | + } | |
| 471 | +} | |
| 472 | + | |
| 473 | +function ph_toggle_auto_incremental_reference_number_options() | |
| 474 | +{ | |
| 475 | + if ( jQuery('[name=\'propertyhive_auto_incremental_reference_numbers\']').is(":checked") ) | |
| 476 | + { | |
| 477 | + jQuery('#row_propertyhive_auto_incremental_next').show(); | |
| 478 | + } | |
| 479 | + else | |
| 480 | + { | |
| 481 | + jQuery('#row_propertyhive_auto_incremental_next').hide(); | |
| 482 | + } | |
| 483 | +} | |
| 132 | 484 | |
| 133 | 485 | function fill_search_form_currency_options() |
| 134 | 486 | { |
| 135 | 487 | var selected_countries = jQuery('select[name=\'propertyhive_countries[]\']').val(); |