| 1 |
var ph_lightbox_open = false; // Used to determine if a details lightbox is open and therefore which post ID (stored in ph_lightbox_post_id) to pass through to AJAX requests |
| 2 |
var ph_lightbox_post_id; |
| 3 |
var ph_viewing_negotiators_changed = false; |
| 4 |
|
| 5 |
function ph_init_description_editors() |
| 6 |
{ |
| 7 |
if (propertyhive_admin_meta_boxes.enable_description_editor != true) |
| 8 |
{ |
| 9 |
return; |
| 10 |
} |
| 11 |
|
| 12 |
jQuery('textarea[name=\'_description[]\']').each(function() |
| 13 |
{ |
| 14 |
var this_id = jQuery(this).attr('id'); |
| 15 |
this_id = this_id.replace("_description_", ""); |
| 16 |
|
| 17 |
if ( this_id != 'id' ) // ignore template room |
| 18 |
{ |
| 19 |
wp.editor.remove("_description_" + this_id); |
| 20 |
wp.editor.initialize( |
| 21 |
"_description_" + this_id, |
| 22 |
{ |
| 23 |
'tinymce' : { |
| 24 |
'toolbar1': 'formatselect,bold,italic,underline,undo,redo,link', |
| 25 |
}, |
| 26 |
mediaButtons: false, |
| 27 |
quicktags: false |
| 28 |
} |
| 29 |
); |
| 30 |
} |
| 31 |
}); |
| 32 |
|
| 33 |
jQuery('textarea[name=\'_room_description[]\']').each(function() |
| 34 |
{ |
| 35 |
var this_id = jQuery(this).attr('id'); |
| 36 |
this_id = this_id.replace("_room_description_", ""); |
| 37 |
|
| 38 |
if ( this_id != 'id' ) // ignore template room |
| 39 |
{ |
| 40 |
wp.editor.remove("_room_description_" + this_id); |
| 41 |
wp.editor.initialize( |
| 42 |
"_room_description_" + this_id, |
| 43 |
{ |
| 44 |
'tinymce' : { |
| 45 |
'toolbar1': 'formatselect,bold,italic,underline,undo,redo,link', |
| 46 |
}, |
| 47 |
mediaButtons: false, |
| 48 |
quicktags: false |
| 49 |
} |
| 50 |
); |
| 51 |
} |
| 52 |
}); |
| 53 |
} |
| 54 |
|
| 55 |
function ph_set_match_price_currency_symbol() |
| 56 |
{ |
| 57 |
jQuery('#propertyhive-contact-relationships div[id^=\'tab_applicant_data_\']').each(function() |
| 58 |
{ |
| 59 |
// loop through each relationship |
| 60 |
var department = jQuery(this).find('input[name^=\'_applicant_department_\']').filter(':checked').val(); |
| 61 |
|
| 62 |
if ( department == 'residential-sales' ) |
| 63 |
{ |
| 64 |
var selected_currency = jQuery(this).find('select[name^=\'_applicant_currency_sales_\'] :selected').text(); |
| 65 |
if ( selected_currency != '' ) |
| 66 |
{ |
| 67 |
jQuery(this).find('label[for^=\'_applicant_match_price_range_\'] .currency-symbol').html(selected_currency); |
| 68 |
} |
| 69 |
} |
| 70 |
if ( department == 'residential-lettings' ) |
| 71 |
{ |
| 72 |
// no match price in lettings |
| 73 |
} |
| 74 |
}); |
| 75 |
} |
| 76 |
|
| 77 |
function show_other_material_information_rows() |
| 78 |
{ |
| 79 |
jQuery('#propertyhive-property-material-information .form-field[class*=\'_other_field\']').hide(); |
| 80 |
|
| 81 |
jQuery('#propertyhive-property-material-information .form-field:not([class*=\'_other_field\'])').each(function() |
| 82 |
{ |
| 83 |
if ( jQuery(this).next('[class*="_other_field"]').length > 0 ) |
| 84 |
{ |
| 85 |
// If select is 'Other' then show row |
| 86 |
var selected_values = jQuery(this).find('select').val(); |
| 87 |
if (selected_values && jQuery.inArray('other', selected_values) !== -1) |
| 88 |
{ |
| 89 |
jQuery(this).next('[class*="_other_field"]').show(); |
| 90 |
} |
| 91 |
} |
| 92 |
}); |
| 93 |
} |
| 94 |
|
| 95 |
function ph_check_duplicate_reference_number() |
| 96 |
{ |
| 97 |
var data = { |
| 98 |
action: 'propertyhive_check_duplicate_reference_number', |
| 99 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 100 |
reference_number: jQuery('#propertyhive-property-address input[name=\'_reference_number\']').val(), |
| 101 |
security: propertyhive_admin_meta_boxes.check_duplicate_reference_number_nonce |
| 102 |
}; |
| 103 |
|
| 104 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 105 |
{ |
| 106 |
if ( response == '1' ) |
| 107 |
{ |
| 108 |
// exists already |
| 109 |
jQuery('#propertyhive-property-address input[name=\'_reference_number\']').after('<span class="duplicate-reference-number-warning"> <span class="dashicons dashicons-info" style="color:#72aee6; vertical-align:middle"></span> This reference number is already in use</span>'); |
| 110 |
} |
| 111 |
}); |
| 112 |
} |
| 113 |
|
| 114 |
jQuery( function($){ |
| 115 |
|
| 116 |
ph_init_description_editors(); |
| 117 |
|
| 118 |
ph_set_match_price_currency_symbol(); |
| 119 |
|
| 120 |
show_other_material_information_rows(); |
| 121 |
|
| 122 |
ph_check_duplicate_reference_number(); |
| 123 |
|
| 124 |
$('#propertyhive-property-address input[name=\'_reference_number\']').change(function() |
| 125 |
{ |
| 126 |
ph_check_duplicate_reference_number(); |
| 127 |
}); |
| 128 |
|
| 129 |
$('#propertyhive-property-address input[name=\'_reference_number\']').keydown(function() |
| 130 |
{ |
| 131 |
jQuery('#propertyhive-property-address .duplicate-reference-number-warning').remove(); |
| 132 |
}); |
| 133 |
|
| 134 |
$('#propertyhive-contact-relationships input[name^=\'_applicant_department_\']').change(function() |
| 135 |
{ |
| 136 |
ph_set_match_price_currency_symbol(); |
| 137 |
}); |
| 138 |
$('#propertyhive-contact-relationships select[name^=\'_applicant_currency_sales_\']').change(function() |
| 139 |
{ |
| 140 |
ph_set_match_price_currency_symbol(); |
| 141 |
}); |
| 142 |
|
| 143 |
$('#propertyhive-property-material-information .form-field:not([class*=\'_other_field\']) select').on('change', function() |
| 144 |
{ |
| 145 |
show_other_material_information_rows(); |
| 146 |
}); |
| 147 |
|
| 148 |
// Toggle list table rows on small screens. |
| 149 |
$( 'div[id^=\'propertyhive_\'][id$=\'_meta_box\'], div[id^=\'propertyhive_\'][id$=\'_grid\']' ).on( 'click', '.toggle-row', function() { |
| 150 |
$( this ).closest( 'tr' ).toggleClass( 'is-expanded' ); |
| 151 |
}); |
| 152 |
|
| 153 |
$('.propertyhive_meta_box #property_rooms').sortable({ |
| 154 |
opacity: 0.8, |
| 155 |
revert: true, |
| 156 |
handle: 'h3', |
| 157 |
update: function( event, ui ) { |
| 158 |
ph_init_description_editors(); |
| 159 |
} |
| 160 |
}); |
| 161 |
|
| 162 |
$('.propertyhive_meta_box #property_descriptions').sortable({ |
| 163 |
opacity: 0.8, |
| 164 |
revert: true, |
| 165 |
handle: 'h3', |
| 166 |
update: function( event, ui ) { |
| 167 |
ph_init_description_editors(); |
| 168 |
} |
| 169 |
}); |
| 170 |
|
| 171 |
$('.propertyhive_meta_box #property_features').sortable({ |
| 172 |
opacity: 0.8, |
| 173 |
revert: true, |
| 174 |
handle: 'label' |
| 175 |
}); |
| 176 |
|
| 177 |
$('.propertyhive_meta_box #property_photo_urls').sortable({ |
| 178 |
opacity: 0.8, |
| 179 |
revert: true, |
| 180 |
handle: 'label' |
| 181 |
}); |
| 182 |
|
| 183 |
$('.propertyhive_meta_box #property_floorplan_urls').sortable({ |
| 184 |
opacity: 0.8, |
| 185 |
revert: true, |
| 186 |
handle: 'label' |
| 187 |
}); |
| 188 |
|
| 189 |
$('.propertyhive_meta_box #property_brochure_urls').sortable({ |
| 190 |
opacity: 0.8, |
| 191 |
revert: true, |
| 192 |
handle: 'label' |
| 193 |
}); |
| 194 |
|
| 195 |
$('.propertyhive_meta_box #property_epc_urls').sortable({ |
| 196 |
opacity: 0.8, |
| 197 |
revert: true, |
| 198 |
handle: 'label' |
| 199 |
}); |
| 200 |
|
| 201 |
$('.propertyhive_meta_box #property_virtual_tours').sortable({ |
| 202 |
opacity: 0.8, |
| 203 |
revert: true, |
| 204 |
handle: 'label' |
| 205 |
}); |
| 206 |
|
| 207 |
initialise_datepicker(); |
| 208 |
|
| 209 |
// TABS |
| 210 |
$('ul.ph-tabs').show(); |
| 211 |
$('div.panel-wrap').each(function(){ |
| 212 |
$(this).find('div.panel:not(:first)').hide(); |
| 213 |
}); |
| 214 |
$('ul.ph-tabs a').click(function(){ |
| 215 |
var panel_wrap = $(this).closest('div.panel-wrap'); |
| 216 |
$('ul.ph-tabs li', panel_wrap).removeClass('active'); |
| 217 |
$(this).parent().addClass('active'); |
| 218 |
$('div.panel', panel_wrap).hide(); |
| 219 |
$( $(this).attr('href') ).show(); |
| 220 |
return false; |
| 221 |
}); |
| 222 |
$('ul.ph-tabs li:visible').eq(0).find('a').click(); |
| 223 |
|
| 224 |
// Notes |
| 225 |
$(document).on( 'click', '[id^=\'propertyhive_\'][id$=\'_notes_container\'] a.add_note', function() |
| 226 |
{ |
| 227 |
var section = $(this).attr('data-section'); |
| 228 |
|
| 229 |
if ( propertyhive_admin_meta_boxes.disable_notes_mention != true ) |
| 230 |
{ |
| 231 |
var content = tinymce.get('add_note').getContent(); |
| 232 |
if ( content === false || content === '' ) |
| 233 |
{ |
| 234 |
return; |
| 235 |
} |
| 236 |
} |
| 237 |
else |
| 238 |
{ |
| 239 |
if ( ! $('#propertyhive_' + section + '_notes_container textarea#add_note').val() ) return; |
| 240 |
content = $('#propertyhive_' + section + '_notes_container textarea#add_note').val(); |
| 241 |
} |
| 242 |
|
| 243 |
if ( $(this).text() == 'Adding...' ) { return false; } |
| 244 |
|
| 245 |
$(this).html('Adding...'); |
| 246 |
$(this).attr('disabled', 'disabled'); |
| 247 |
|
| 248 |
var data = { |
| 249 |
action: 'propertyhive_add_note', |
| 250 |
post_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 251 |
note: content.replace(/\\/g, ''), |
| 252 |
note_type: 'propertyhive_note', |
| 253 |
security: propertyhive_admin_meta_boxes.add_note_nonce, |
| 254 |
}; |
| 255 |
|
| 256 |
if ( $('#propertyhive_' + section + '_notes_container input[name=\'pinned\']').prop('checked') ) |
| 257 |
{ |
| 258 |
data.pinned = '1'; |
| 259 |
} |
| 260 |
|
| 261 |
$.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) { |
| 262 |
ph_redraw_notes_grid(section); |
| 263 |
}); |
| 264 |
|
| 265 |
return false; |
| 266 |
}); |
| 267 |
|
| 268 |
$(document).on( 'click', '[id^=\'propertyhive_\'][id$=\'_notes_container\'] a.delete_note', function() |
| 269 |
{ |
| 270 |
var section = $(this).attr('data-section'); |
| 271 |
|
| 272 |
if ( $(this).text() == 'Deleting...' ) { return; } |
| 273 |
|
| 274 |
var confirm_box = confirm('Are you sure you wish to delete this note?'); |
| 275 |
if (!confirm_box) |
| 276 |
{ |
| 277 |
return false; |
| 278 |
} |
| 279 |
|
| 280 |
$(this).html('Deleting...'); |
| 281 |
|
| 282 |
var note = $(this).closest('li.note'); |
| 283 |
|
| 284 |
var data = { |
| 285 |
action: 'propertyhive_delete_note', |
| 286 |
note_id: $(note).attr('rel'), |
| 287 |
security: propertyhive_admin_meta_boxes.delete_note_nonce, |
| 288 |
}; |
| 289 |
|
| 290 |
$.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) { |
| 291 |
ph_redraw_notes_grid(section); |
| 292 |
ph_redraw_pinned_notes_grid(section); |
| 293 |
}, 'json'); |
| 294 |
|
| 295 |
return false; |
| 296 |
}); |
| 297 |
|
| 298 |
$(document).on( 'click', '[id^=\'propertyhive_\'][id$=\'_notes_container\'] a.toggle_note_pinned', function() |
| 299 |
{ |
| 300 |
var section = $(this).attr('data-section'); |
| 301 |
|
| 302 |
if ( $(this).text().indexOf('...') >= 0 ) { return; } |
| 303 |
|
| 304 |
var note = $(this).closest('li.note'); |
| 305 |
|
| 306 |
if ( note.find('div.pinned').length > 0 ) |
| 307 |
{ |
| 308 |
var loading_text = 'Unpinning...'; |
| 309 |
} |
| 310 |
else |
| 311 |
{ |
| 312 |
var loading_text = 'Pinning...'; |
| 313 |
} |
| 314 |
$(this).html(loading_text); |
| 315 |
|
| 316 |
var data = { |
| 317 |
action: 'propertyhive_toggle_note_pinned', |
| 318 |
note_id: $(note).attr('rel'), |
| 319 |
security: propertyhive_admin_meta_boxes.pin_note_nonce |
| 320 |
}; |
| 321 |
|
| 322 |
$.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) { |
| 323 |
ph_redraw_notes_grid(section); |
| 324 |
ph_redraw_pinned_notes_grid(section); |
| 325 |
}, 'json'); |
| 326 |
|
| 327 |
return false; |
| 328 |
|
| 329 |
}); |
| 330 |
|
| 331 |
// Notes filter |
| 332 |
$('.notes-filter a').click(function(e) |
| 333 |
{ |
| 334 |
e.preventDefault(); |
| 335 |
|
| 336 |
var note_type = $(this).attr('data-filter-class'); |
| 337 |
var section = $(this).attr('data-section'); |
| 338 |
|
| 339 |
if ( note_type == '*' ) |
| 340 |
{ |
| 341 |
// show all notes |
| 342 |
$('#propertyhive_' + section + '_notes_container .record_notes li').show(); |
| 343 |
|
| 344 |
if ( $('#propertyhive_' + section + '_notes_container .record_notes li').length > 1 ) |
| 345 |
{ |
| 346 |
$('#propertyhive_' + section + '_notes_container .record_notes li#no_notes').hide(); |
| 347 |
} |
| 348 |
} |
| 349 |
else |
| 350 |
{ |
| 351 |
$('#propertyhive_' + section + '_notes_container .record_notes li').hide(); |
| 352 |
$('#propertyhive_' + section + '_notes_container .record_notes li.' + note_type).show(); |
| 353 |
} |
| 354 |
|
| 355 |
$(this).parent().parent().find('a').removeClass('current'); |
| 356 |
$(this).addClass('current'); |
| 357 |
}); |
| 358 |
|
| 359 |
// Key Dates |
| 360 |
var previous_key_date_type; |
| 361 |
$('[id=\'propertyhive-management-dates\']').on( 'focus', '#_add_key_date_type', function() { |
| 362 |
previous_key_date_type = $(this).find("option:selected").text(); |
| 363 |
}); |
| 364 |
|
| 365 |
$('[id=\'propertyhive-management-dates\']').on( 'change', '#_add_key_date_type', function() { |
| 366 |
var selected_key_date_type = $('#_add_key_date_type option:selected').text(); |
| 367 |
if( $('#_add_key_date_type').val() == '' ) |
| 368 |
{ |
| 369 |
$('#_add_key_date_description').val(''); |
| 370 |
} |
| 371 |
else |
| 372 |
{ |
| 373 |
var current_description = $('#_add_key_date_description').val(); |
| 374 |
|
| 375 |
if ( current_description == '' || current_description == previous_key_date_type ) |
| 376 |
{ |
| 377 |
$('#_add_key_date_description').val(selected_key_date_type); |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
previous_key_date_type = selected_key_date_type; |
| 382 |
}); |
| 383 |
|
| 384 |
$('[id=\'propertyhive-management-dates\']').on( 'click', 'a.add_key_date', function() { |
| 385 |
|
| 386 |
if ( !$('#_add_key_date_type').val() || !$('#_add_key_date_description').val() || !$('#_add_key_date_due').val() ) |
| 387 |
{ |
| 388 |
return false; |
| 389 |
} |
| 390 |
|
| 391 |
if ( $(this).text() == 'Adding...' ) { return false; } |
| 392 |
|
| 393 |
$(this).html('Adding...'); |
| 394 |
$(this).attr('disabled', 'disabled'); |
| 395 |
|
| 396 |
var data = { |
| 397 |
action: 'propertyhive_add_key_date', |
| 398 |
security: propertyhive_admin_meta_boxes.add_key_date_nonce, |
| 399 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 400 |
key_date_type: $('#_add_key_date_type').val(), |
| 401 |
key_date_description: $('#_add_key_date_description').val(), |
| 402 |
key_date_due: $('#_add_key_date_due').val(), |
| 403 |
key_date_hours: $('#_add_key_date_due_hours').val(), |
| 404 |
key_date_minutes: $('#_add_key_date_due_minutes').val(), |
| 405 |
key_date_notes: $('#_add_key_date_notes').val(), |
| 406 |
}; |
| 407 |
|
| 408 |
$.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) { |
| 409 |
var data = { |
| 410 |
action: 'propertyhive_get_management_dates_grid', |
| 411 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 412 |
}; |
| 413 |
|
| 414 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 415 |
{ |
| 416 |
jQuery('#propertyhive_management_dates_container').html(response); |
| 417 |
initialise_datepicker(); |
| 418 |
}, 'html'); |
| 419 |
}); |
| 420 |
|
| 421 |
return false; |
| 422 |
}); |
| 423 |
|
| 424 |
$('[id=\'propertyhive-management-dates\']').on( 'click', '#filter-key-dates-grid', function() { |
| 425 |
|
| 426 |
if ( $(this).val() == 'Updating...' ) { return false; } |
| 427 |
|
| 428 |
$(this).val('Updating...'); |
| 429 |
$(this).attr('disabled', 'disabled'); |
| 430 |
|
| 431 |
var data = { |
| 432 |
action: 'propertyhive_get_management_dates_grid', |
| 433 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 434 |
selected_type_id: $('#_type_id_filter').val(), |
| 435 |
selected_status: $('#_date_status_filter').val(), |
| 436 |
}; |
| 437 |
|
| 438 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 439 |
{ |
| 440 |
jQuery('#propertyhive_management_dates_container').html(response); |
| 441 |
initialise_datepicker(); |
| 442 |
}, 'html'); |
| 443 |
|
| 444 |
return false; |
| 445 |
}); |
| 446 |
|
| 447 |
$('[id=\'propertyhive-management-dates\']').on( 'click', '.meta-box-quick-edit', function() { |
| 448 |
|
| 449 |
var post_id = $(this).attr('id'); |
| 450 |
var original_row = $('.post-' + post_id); |
| 451 |
|
| 452 |
$('.quick-edit-row').hide(); |
| 453 |
$('.key-date-row').show(); |
| 454 |
original_row.hide(); |
| 455 |
|
| 456 |
if ( $('#quick-edit-' + post_id).length > 0 ) |
| 457 |
{ |
| 458 |
$('#quick-edit-' + post_id).show(); |
| 459 |
} |
| 460 |
else |
| 461 |
{ |
| 462 |
original_row.after('<tr id="quick-edit-' + post_id + '" class="quick-edit-row"><td colspan="4">Loading...</td></tr>'); |
| 463 |
|
| 464 |
var data = { |
| 465 |
action: 'propertyhive_get_key_dates_quick_edit_row', |
| 466 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 467 |
date_post_id: post_id, |
| 468 |
description: $('.post-' + post_id + ' .description .cell-main-content').text(), |
| 469 |
status: $('.post-' + post_id + ' .status .cell-main-content').text(), |
| 470 |
due_date_time: $('.post-' + post_id + ' .date_due .cell-main-content').text(), |
| 471 |
notes: $('.post-' + post_id + ' .notes .hidden-key-date-notes').text(), |
| 472 |
type: $('.post-' + post_id + ' .hidden-date-type-id').text(), |
| 473 |
}; |
| 474 |
|
| 475 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 476 |
{ |
| 477 |
$('#quick-edit-' + post_id).html(response); |
| 478 |
initialise_datepicker(); |
| 479 |
}, 'html'); |
| 480 |
} |
| 481 |
|
| 482 |
return false; |
| 483 |
|
| 484 |
}); |
| 485 |
|
| 486 |
$('[id=\'propertyhive-management-dates\']').on( 'click', '.meta-box-delete', function() { |
| 487 |
|
| 488 |
var confirm_box = confirm('Are you sure you wish to delete this key date?'); |
| 489 |
if (!confirm_box) |
| 490 |
{ |
| 491 |
return confirm_box; |
| 492 |
} |
| 493 |
|
| 494 |
var post_id = $(this).attr('id'); |
| 495 |
|
| 496 |
if ( $('#quick-edit-' + post_id).length > 0 ) |
| 497 |
{ |
| 498 |
$('#quick-edit-' + post_id).show(); |
| 499 |
} |
| 500 |
else |
| 501 |
{ |
| 502 |
var data = { |
| 503 |
action: 'propertyhive_delete_key_date', |
| 504 |
date_post_id: post_id, |
| 505 |
security: propertyhive_admin_meta_boxes.delete_key_date_nonce, |
| 506 |
}; |
| 507 |
|
| 508 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 509 |
{ |
| 510 |
var data = { |
| 511 |
action: 'propertyhive_get_management_dates_grid', |
| 512 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 513 |
}; |
| 514 |
|
| 515 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 516 |
{ |
| 517 |
jQuery('#propertyhive_management_dates_container').html(response); |
| 518 |
initialise_datepicker(); |
| 519 |
}, 'html'); |
| 520 |
}, 'json'); |
| 521 |
} |
| 522 |
|
| 523 |
return false; |
| 524 |
|
| 525 |
}); |
| 526 |
|
| 527 |
$('[id=\'propertyhive-management-dates\']').on( 'change', '#key_date_status', function() { |
| 528 |
|
| 529 |
var quick_edit_row = $(this).closest('tr'); |
| 530 |
var next_key_date_checkbox = quick_edit_row.find('#next_key_date_checkbox'); |
| 531 |
|
| 532 |
if (next_key_date_checkbox.length !== 0) |
| 533 |
{ |
| 534 |
if ( this.value == 'complete' ) |
| 535 |
{ |
| 536 |
// Show Book Next checkbox |
| 537 |
next_key_date_checkbox.removeClass('hidden'); |
| 538 |
} |
| 539 |
else |
| 540 |
{ |
| 541 |
if( !next_key_date_checkbox.hasClass('hidden') ) |
| 542 |
{ |
| 543 |
// Hide Book Next checkbox |
| 544 |
next_key_date_checkbox.addClass('hidden'); |
| 545 |
|
| 546 |
// Hide Next Key Date field, if visible |
| 547 |
var next_key_date_field = quick_edit_row.find('#next_key_date_field'); |
| 548 |
if( !next_key_date_field.hasClass('hidden') ) |
| 549 |
{ |
| 550 |
next_key_date_field.addClass('hidden'); |
| 551 |
} |
| 552 |
|
| 553 |
// Uncheck Book Next checkbox |
| 554 |
quick_edit_row.find('#book_next_key_date').prop( 'checked', false ); |
| 555 |
} |
| 556 |
} |
| 557 |
} |
| 558 |
}); |
| 559 |
|
| 560 |
$('[id=\'propertyhive-management-dates\']').on( 'click', '#book_next_key_date', function() { |
| 561 |
|
| 562 |
// Show/Hide Next Key Date field when checkbox is checked and unchecked |
| 563 |
var next_key_date_field = $(this).closest('tr').find('#next_key_date_field'); |
| 564 |
if( this.checked ) |
| 565 |
{ |
| 566 |
next_key_date_field.removeClass('hidden'); |
| 567 |
} |
| 568 |
else |
| 569 |
{ |
| 570 |
if( !next_key_date_field.hasClass('hidden') ) |
| 571 |
{ |
| 572 |
next_key_date_field.addClass('hidden'); |
| 573 |
} |
| 574 |
} |
| 575 |
}); |
| 576 |
|
| 577 |
$('[id=\'propertyhive-management-dates\']').on( 'click', '.save-quick-edit', function() { |
| 578 |
|
| 579 |
var date_post_id = $(this).attr('id'); |
| 580 |
|
| 581 |
if ( $(this).text() == 'Saving...' ) { return false; } |
| 582 |
|
| 583 |
$(this).text('Saving...'); |
| 584 |
$(this).attr('disabled', 'disabled'); |
| 585 |
|
| 586 |
var quick_edit_row = $('#quick-edit-' + date_post_id); |
| 587 |
|
| 588 |
var data = { |
| 589 |
action: 'propertyhive_save_key_date', |
| 590 |
post_id: date_post_id, |
| 591 |
description: quick_edit_row.find('#date_description').val(), |
| 592 |
status: quick_edit_row.find('#key_date_status').val(), |
| 593 |
due_date_time: quick_edit_row.find('#date_due_quick_edit').val() + ' ' + quick_edit_row.find('#date_due_hours_quick_edit').val() + ':' + quick_edit_row.find('#date_due_minutes_quick_edit').val(), |
| 594 |
type: quick_edit_row.find('#date_type').val(), |
| 595 |
notes: quick_edit_row.find('#date_notes_quick_edit').val(), |
| 596 |
security: propertyhive_admin_meta_boxes.save_key_date_nonce, |
| 597 |
}; |
| 598 |
|
| 599 |
if (quick_edit_row.find('#book_next_key_date').length !== 0) |
| 600 |
{ |
| 601 |
if ( quick_edit_row.find('#book_next_key_date').is(":checked") ) |
| 602 |
{ |
| 603 |
data.next_key_date = quick_edit_row.find('#next_key_date').val() + ' ' + quick_edit_row.find('#next_key_date_hours').val() + ':' + quick_edit_row.find('#next_key_date_minutes').val(); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 608 |
{ |
| 609 |
var data = { |
| 610 |
action: 'propertyhive_get_management_dates_grid', |
| 611 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 612 |
selected_type_id: $('#_type_id_filter').val(), |
| 613 |
selected_status: $('#_date_status_filter').val(), |
| 614 |
}; |
| 615 |
|
| 616 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 617 |
{ |
| 618 |
jQuery('#propertyhive_management_dates_container').html(response); |
| 619 |
initialise_datepicker(); |
| 620 |
}, 'html'); |
| 621 |
}, 'html'); |
| 622 |
|
| 623 |
}); |
| 624 |
|
| 625 |
$('[id=\'propertyhive-management-dates\']').on( 'click', '.cancel-quick-edit', function() { |
| 626 |
$('.quick-edit-row').hide(); |
| 627 |
$('.post-' + $(this).attr('id')).show(); |
| 628 |
}); |
| 629 |
|
| 630 |
$('[id=\'propertyhive-property-tenancies\']').on( 'click', '#filter-property-tenancies-grid', function() { |
| 631 |
|
| 632 |
if ( $(this).val() == 'Updating...' ) { return false; } |
| 633 |
|
| 634 |
$(this).val('Updating...'); |
| 635 |
$(this).attr('disabled', 'disabled'); |
| 636 |
|
| 637 |
var data = { |
| 638 |
action: 'propertyhive_get_property_tenancies_grid', |
| 639 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 640 |
selected_status: $('#_tenancy_status_filter').val(), |
| 641 |
}; |
| 642 |
|
| 643 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 644 |
{ |
| 645 |
jQuery('#propertyhive_property_tenancies_grid').html(response); |
| 646 |
}, 'html'); |
| 647 |
|
| 648 |
return false; |
| 649 |
}); |
| 650 |
|
| 651 |
$('[id=\'propertyhive-property-viewings\']').on( 'click', '#filter-property-viewings-grid', function() { |
| 652 |
|
| 653 |
if ( $(this).val() == 'Updating...' ) { return false; } |
| 654 |
|
| 655 |
$(this).val('Updating...'); |
| 656 |
$(this).attr('disabled', 'disabled'); |
| 657 |
|
| 658 |
var data = { |
| 659 |
action: 'propertyhive_get_property_viewings_meta_box', |
| 660 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 661 |
selected_status: $('#_viewing_status_filter').val(), |
| 662 |
}; |
| 663 |
|
| 664 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 665 |
{ |
| 666 |
jQuery('#propertyhive_property_viewings_meta_box').html(response); |
| 667 |
}, 'html'); |
| 668 |
|
| 669 |
return false; |
| 670 |
}); |
| 671 |
|
| 672 |
$('[id=\'propertyhive-contact-tenancies\']').on( 'click', '#filter-contact-tenancies-grid', function() { |
| 673 |
|
| 674 |
if ( $(this).val() == 'Updating...' ) { return false; } |
| 675 |
|
| 676 |
$(this).val('Updating...'); |
| 677 |
$(this).attr('disabled', 'disabled'); |
| 678 |
|
| 679 |
var data = { |
| 680 |
action: 'propertyhive_get_contact_tenancies_grid', |
| 681 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 682 |
selected_status: $('#_tenancy_status_filter').val(), |
| 683 |
}; |
| 684 |
|
| 685 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 686 |
{ |
| 687 |
jQuery('#propertyhive_contact_tenancies_grid').html(response); |
| 688 |
}, 'html'); |
| 689 |
|
| 690 |
return false; |
| 691 |
}); |
| 692 |
|
| 693 |
$('[id=\'propertyhive-contact-viewings\']').on( 'click', '#filter-contact-viewings-grid', function() { |
| 694 |
|
| 695 |
if ( $(this).val() == 'Updating...' ) { return false; } |
| 696 |
|
| 697 |
$(this).val('Updating...'); |
| 698 |
$(this).attr('disabled', 'disabled'); |
| 699 |
|
| 700 |
var data = { |
| 701 |
action: 'propertyhive_get_contact_viewings_meta_box', |
| 702 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 703 |
selected_status: $('#_viewing_status_filter').val(), |
| 704 |
}; |
| 705 |
|
| 706 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 707 |
{ |
| 708 |
jQuery('#propertyhive_contact_viewings_meta_box').html(response); |
| 709 |
}, 'html'); |
| 710 |
|
| 711 |
return false; |
| 712 |
}); |
| 713 |
|
| 714 |
$('[id=\'propertyhive-property-offers\']').on( 'click', '#filter-property-offers-grid', function() { |
| 715 |
|
| 716 |
if ( $(this).val() == 'Updating...' ) { return false; } |
| 717 |
|
| 718 |
$(this).val('Updating...'); |
| 719 |
$(this).attr('disabled', 'disabled'); |
| 720 |
|
| 721 |
var data = { |
| 722 |
action: 'propertyhive_get_property_offers_meta_box', |
| 723 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 724 |
selected_status: $('#_offer_status_filter').val(), |
| 725 |
}; |
| 726 |
|
| 727 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 728 |
{ |
| 729 |
jQuery('#propertyhive_property_offers_meta_box').html(response); |
| 730 |
}, 'html'); |
| 731 |
|
| 732 |
return false; |
| 733 |
}); |
| 734 |
|
| 735 |
$('[id=\'propertyhive-contact-offers\']').on( 'click', '#filter-contact-offers-grid', function() { |
| 736 |
|
| 737 |
if ( $(this).val() == 'Updating...' ) { return false; } |
| 738 |
|
| 739 |
$(this).val('Updating...'); |
| 740 |
$(this).attr('disabled', 'disabled'); |
| 741 |
|
| 742 |
var data = { |
| 743 |
action: 'propertyhive_get_contact_offers_meta_box', |
| 744 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 745 |
selected_status: $('#_offer_status_filter').val(), |
| 746 |
}; |
| 747 |
|
| 748 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 749 |
{ |
| 750 |
jQuery('#propertyhive_contact_offers_meta_box').html(response); |
| 751 |
}, 'html'); |
| 752 |
|
| 753 |
return false; |
| 754 |
}); |
| 755 |
|
| 756 |
$('[id=\'propertyhive-property-sales\']').on( 'click', '#filter-property-sales-grid', function() { |
| 757 |
|
| 758 |
if ( $(this).val() == 'Updating...' ) { return false; } |
| 759 |
|
| 760 |
$(this).val('Updating...'); |
| 761 |
$(this).attr('disabled', 'disabled'); |
| 762 |
|
| 763 |
var data = { |
| 764 |
action: 'propertyhive_get_property_sales_meta_box', |
| 765 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 766 |
selected_status: $('#_sale_status_filter').val(), |
| 767 |
}; |
| 768 |
|
| 769 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 770 |
{ |
| 771 |
jQuery('#propertyhive_property_sales_meta_box').html(response); |
| 772 |
}, 'html'); |
| 773 |
|
| 774 |
return false; |
| 775 |
}); |
| 776 |
|
| 777 |
$('[id=\'propertyhive-contact-sales\']').on( 'click', '#filter-contact-sales-grid', function() { |
| 778 |
|
| 779 |
if ( $(this).val() == 'Updating...' ) { return false; } |
| 780 |
|
| 781 |
$(this).val('Updating...'); |
| 782 |
$(this).attr('disabled', 'disabled'); |
| 783 |
|
| 784 |
var data = { |
| 785 |
action: 'propertyhive_get_contact_sales_meta_box', |
| 786 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 787 |
selected_status: $('#_sale_status_filter').val(), |
| 788 |
}; |
| 789 |
|
| 790 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 791 |
{ |
| 792 |
jQuery('#propertyhive_contact_sales_meta_box').html(response); |
| 793 |
}, 'html'); |
| 794 |
|
| 795 |
return false; |
| 796 |
}); |
| 797 |
|
| 798 |
$('[id=\'propertyhive-property-enquiries\']').on( 'click', '#filter-property-enquiries-grid', function() { |
| 799 |
|
| 800 |
if ( $(this).val() == 'Updating...' ) { return false; } |
| 801 |
|
| 802 |
$(this).val('Updating...'); |
| 803 |
$(this).attr('disabled', 'disabled'); |
| 804 |
|
| 805 |
var data = { |
| 806 |
action: 'propertyhive_get_property_enquiries_meta_box', |
| 807 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 808 |
selected_status: $('#_enquiry_status_filter').val(), |
| 809 |
}; |
| 810 |
|
| 811 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 812 |
{ |
| 813 |
jQuery('#propertyhive_property_enquiries_meta_box').html(response); |
| 814 |
}, 'html'); |
| 815 |
|
| 816 |
return false; |
| 817 |
}); |
| 818 |
|
| 819 |
$('[id=\'propertyhive-contact-enquiries\']').on( 'click', '#filter-contact-enquiries-grid', function() { |
| 820 |
|
| 821 |
if ( $(this).val() == 'Updating...' ) { return false; } |
| 822 |
|
| 823 |
$(this).val('Updating...'); |
| 824 |
$(this).attr('disabled', 'disabled'); |
| 825 |
|
| 826 |
var data = { |
| 827 |
action: 'propertyhive_get_contact_enquiries_meta_box', |
| 828 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 829 |
selected_status: $('#_enquiry_status_filter').val(), |
| 830 |
}; |
| 831 |
|
| 832 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 833 |
{ |
| 834 |
jQuery('#propertyhive_contact_enquiries_meta_box').html(response); |
| 835 |
}, 'html'); |
| 836 |
|
| 837 |
return false; |
| 838 |
}); |
| 839 |
|
| 840 |
$('.postbox').on( 'click', 'a[name=\'export_action\'][id^=\'export-\']', function(e) |
| 841 |
{ |
| 842 |
e.preventDefault(); |
| 843 |
|
| 844 |
var record_ids = []; |
| 845 |
|
| 846 |
$(this).parent().parent().parent().find('a[data-viewing-id]').each(function() |
| 847 |
{ |
| 848 |
record_ids.push( parseInt($(this).attr('data-viewing-id')) ); |
| 849 |
}); |
| 850 |
$(this).parent().parent().parent().find('a[data-offer-id]').each(function() |
| 851 |
{ |
| 852 |
record_ids.push( parseInt($(this).attr('data-offer-id')) ); |
| 853 |
}); |
| 854 |
$(this).parent().parent().parent().find('a[data-sale-id]').each(function() |
| 855 |
{ |
| 856 |
record_ids.push( parseInt($(this).attr('data-sale-id')) ); |
| 857 |
}); |
| 858 |
|
| 859 |
var new_location = window.location.href; |
| 860 |
new_location = new_location.split("#"); |
| 861 |
new_location = new_location[0]; |
| 862 |
|
| 863 |
if ( record_ids.length == 0 ) |
| 864 |
{ |
| 865 |
alert('No records to export'); |
| 866 |
return; |
| 867 |
} |
| 868 |
|
| 869 |
window.location.href = new_location + '&sub_grid=' + encodeURIComponent($(this).attr('id').replace("export-", "")) + '&record_ids=' + encodeURIComponent(record_ids.join("|")) + '&ph_export_nonce=' + encodeURIComponent(propertyhive_admin_meta_boxes.export_sub_grid_nonce); |
| 870 |
}); |
| 871 |
|
| 872 |
// Multiselect |
| 873 |
$(".propertyhive_meta_box select.multiselect").chosen(); |
| 874 |
|
| 875 |
$(".post-type-viewing #_negotiator_ids").on('change', function() |
| 876 |
{ |
| 877 |
ph_viewing_negotiators_changed = true; |
| 878 |
}); |
| 879 |
|
| 880 |
$( document ).on('click', '.viewing-lightbox', function(e) |
| 881 |
{ |
| 882 |
e.preventDefault(); |
| 883 |
|
| 884 |
ph_open_details_lightbox($(this).attr('data-viewing-id'), 'viewing'); |
| 885 |
}); |
| 886 |
|
| 887 |
$( document ).on('click', '.propertyhive-lightbox-buttons a.button-close', function(e) |
| 888 |
{ |
| 889 |
e.preventDefault(); |
| 890 |
|
| 891 |
$.fancybox.close(); |
| 892 |
}); |
| 893 |
|
| 894 |
$( document ).on('click', '.propertyhive-lightbox-buttons a.button-prev', function(e) |
| 895 |
{ |
| 896 |
e.preventDefault(); |
| 897 |
|
| 898 |
var previous_post_id = false; |
| 899 |
$('a[data-viewing-id]').each(function() |
| 900 |
{ |
| 901 |
var post_id = $(this).attr('data-viewing-id'); |
| 902 |
|
| 903 |
if ( post_id == ph_lightbox_post_id ) |
| 904 |
{ |
| 905 |
ph_open_details_lightbox(previous_post_id, 'viewing'); |
| 906 |
|
| 907 |
return; |
| 908 |
} |
| 909 |
|
| 910 |
previous_post_id = post_id; |
| 911 |
}); |
| 912 |
}); |
| 913 |
|
| 914 |
$( document ).on('click', '.propertyhive-lightbox-buttons a.button-next', function(e) |
| 915 |
{ |
| 916 |
e.preventDefault(); |
| 917 |
|
| 918 |
var use_next = false; |
| 919 |
$('a[data-viewing-id]').each(function() |
| 920 |
{ |
| 921 |
var post_id = $(this).attr('data-viewing-id'); |
| 922 |
|
| 923 |
if (use_next) |
| 924 |
{ |
| 925 |
ph_open_details_lightbox(post_id, 'viewing'); |
| 926 |
|
| 927 |
return false; |
| 928 |
} |
| 929 |
|
| 930 |
if ( post_id == ph_lightbox_post_id ) |
| 931 |
{ |
| 932 |
use_next = true; |
| 933 |
} |
| 934 |
}); |
| 935 |
}); |
| 936 |
|
| 937 |
$('#tenure_id').change(function() |
| 938 |
{ |
| 939 |
$('#leasehold_information').hide(); |
| 940 |
|
| 941 |
var selected_tenure = $(this).find('option:selected').text(); |
| 942 |
|
| 943 |
$.each(propertyhive_admin_meta_boxes.leasehold_tenures, function(index, value) |
| 944 |
{ |
| 945 |
if ( selected_tenure != '' && value.toLowerCase() === selected_tenure.toLowerCase() ) |
| 946 |
{ |
| 947 |
$('#leasehold_information').show(); |
| 948 |
} |
| 949 |
}); |
| 950 |
}); |
| 951 |
|
| 952 |
$('#_shared_ownership').change(function() |
| 953 |
{ |
| 954 |
if ( $(this).is(':checked') ) |
| 955 |
{ |
| 956 |
$('#shared_ownership_information').show(); |
| 957 |
} |
| 958 |
else |
| 959 |
{ |
| 960 |
$('#shared_ownership_information').hide(); |
| 961 |
} |
| 962 |
}); |
| 963 |
}); |
| 964 |
|
| 965 |
function ph_open_details_lightbox(post_id, section) |
| 966 |
{ |
| 967 |
ph_lightbox_post_id = post_id; |
| 968 |
|
| 969 |
jQuery.fancybox.close(); |
| 970 |
|
| 971 |
jQuery.fancybox.open({ |
| 972 |
src : ajaxurl + '?action=propertyhive_get_' + section + '_lightbox&post_id=' + ph_lightbox_post_id, |
| 973 |
type : 'ajax', |
| 974 |
beforeLoad: function() |
| 975 |
{ |
| 976 |
ph_lightbox_open = true; |
| 977 |
}, |
| 978 |
afterShow: function() |
| 979 |
{ |
| 980 |
// hide/show next/prev buttons |
| 981 |
var found_current = false; |
| 982 |
var previous_exist = false; |
| 983 |
var next_exist = false; |
| 984 |
jQuery('a[data-' + section + '-id]').each(function() |
| 985 |
{ |
| 986 |
var post_id = jQuery(this).attr('data-' + section + '-id'); |
| 987 |
|
| 988 |
if ( found_current ) |
| 989 |
{ |
| 990 |
next_exist = true; |
| 991 |
} |
| 992 |
|
| 993 |
if ( post_id == ph_lightbox_post_id ) |
| 994 |
{ |
| 995 |
// this is the lightbox being viewed |
| 996 |
found_current = true; |
| 997 |
} |
| 998 |
else |
| 999 |
{ |
| 1000 |
if ( !found_current ) |
| 1001 |
{ |
| 1002 |
previous_exist = true; |
| 1003 |
} |
| 1004 |
} |
| 1005 |
}); |
| 1006 |
|
| 1007 |
if ( previous_exist ) |
| 1008 |
{ |
| 1009 |
jQuery('.propertyhive-lightbox-buttons a.button-prev').show(); |
| 1010 |
} |
| 1011 |
if ( next_exist ) |
| 1012 |
{ |
| 1013 |
jQuery('.propertyhive-lightbox-buttons a.button-next').show(); |
| 1014 |
} |
| 1015 |
|
| 1016 |
if ( propertyhive_admin_meta_boxes.disable_notes_mention != true ) |
| 1017 |
{ |
| 1018 |
tinymce.remove('.propertyhive-lightbox-notes textarea#add_note'); |
| 1019 |
|
| 1020 |
tinymce.init({ |
| 1021 |
selector: '.propertyhive-lightbox-notes textarea#add_note', |
| 1022 |
menubar: false, |
| 1023 |
toolbar: false, |
| 1024 |
statusbar: false, |
| 1025 |
forced_root_block: '', // Disable the <p> tags |
| 1026 |
force_br_newlines: true, |
| 1027 |
force_p_newlines: false, |
| 1028 |
external_plugins: |
| 1029 |
{ |
| 1030 |
'mention' : propertyhive_admin_meta_boxes.plugin_url + '/assets/js/tinymce-mention-plugin/tinymce-mention-plugin.js', |
| 1031 |
'placeholder' : propertyhive_admin_meta_boxes.plugin_url + '/assets/js/tinymce-placeholder/mce.placeholder.js' |
| 1032 |
}, |
| 1033 |
setup: function(editor) |
| 1034 |
{ |
| 1035 |
editor.on('init', function() |
| 1036 |
{ |
| 1037 |
editor.getContainer().style.border = '1px solid #ccc'; |
| 1038 |
}); |
| 1039 |
}, |
| 1040 |
mentions: |
| 1041 |
{ |
| 1042 |
source: function (query, process, delimiter) |
| 1043 |
{ |
| 1044 |
// Do your ajax call |
| 1045 |
jQuery.ajax({ |
| 1046 |
url: ajaxurl, // Use WordPress AJAX URL |
| 1047 |
method: 'POST', |
| 1048 |
data: { |
| 1049 |
action: 'propertyhive_fetch_note_mentions', |
| 1050 |
query: query, |
| 1051 |
security: propertyhive_admin_meta_boxes.get_notes_nonce |
| 1052 |
}, |
| 1053 |
success: function(response) { |
| 1054 |
console.log(response); |
| 1055 |
process(response); |
| 1056 |
} |
| 1057 |
}); |
| 1058 |
} |
| 1059 |
}, |
| 1060 |
content_style: ` |
| 1061 |
html, body { |
| 1062 |
height: 100%; /* Set both html and body to 100% height */ |
| 1063 |
margin: 0; |
| 1064 |
padding: 0; |
| 1065 |
overflow: hidden; /* Prevent scrolling issues */ |
| 1066 |
} |
| 1067 |
.mce-content-body { |
| 1068 |
margin: 0; /* Replace margin with padding */ |
| 1069 |
padding: 1rem; /* Add padding */ |
| 1070 |
box-sizing: border-box; /* Include padding in height calculation */ |
| 1071 |
height: 100%; |
| 1072 |
overflow-y: auto; /* Allow vertical scrolling within the body */ |
| 1073 |
} |
| 1074 |
` |
| 1075 |
}); |
| 1076 |
} |
| 1077 |
}, |
| 1078 |
beforeClose: function() |
| 1079 |
{ |
| 1080 |
ph_lightbox_open = false; |
| 1081 |
} |
| 1082 |
}); |
| 1083 |
} |
| 1084 |
|
| 1085 |
// VIEWINGS // |
| 1086 |
jQuery(window).on('load', function() |
| 1087 |
{ |
| 1088 |
//redraw_viewing_details_meta_box(); // called from within redraw_viewing_actions() |
| 1089 |
redraw_viewing_actions(); |
| 1090 |
}); |
| 1091 |
|
| 1092 |
function redraw_viewing_details_meta_box() |
| 1093 |
{ |
| 1094 |
if ( jQuery('#propertyhive_viewing_details_meta_box_container').length > 0 ) |
| 1095 |
{ |
| 1096 |
jQuery('#propertyhive_viewing_details_meta_box_container').html('Loading...'); |
| 1097 |
|
| 1098 |
var data = { |
| 1099 |
action: 'propertyhive_get_viewing_details_meta_box', |
| 1100 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1101 |
security: propertyhive_admin_meta_boxes.viewing_details_meta_nonce, |
| 1102 |
readonly: ph_lightbox_open |
| 1103 |
}; |
| 1104 |
|
| 1105 |
jQuery.post( ajaxurl, data, function(response) |
| 1106 |
{ |
| 1107 |
jQuery('#propertyhive_viewing_details_meta_box_container').html(response); |
| 1108 |
}, 'html'); |
| 1109 |
} |
| 1110 |
} |
| 1111 |
|
| 1112 |
function redraw_viewing_actions() |
| 1113 |
{ |
| 1114 |
if ( jQuery('#propertyhive_viewing_actions_meta_box_container').length > 0 ) |
| 1115 |
{ |
| 1116 |
jQuery('#propertyhive_viewing_actions_meta_box_container').html('Loading...'); |
| 1117 |
|
| 1118 |
var data = { |
| 1119 |
action: 'propertyhive_get_viewing_actions', |
| 1120 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1121 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1122 |
}; |
| 1123 |
|
| 1124 |
jQuery.post( ajaxurl, data, function(response) |
| 1125 |
{ |
| 1126 |
jQuery('#propertyhive_viewing_actions_meta_box_container').html(response); |
| 1127 |
|
| 1128 |
jQuery(document).trigger('ph:adminViewingActionsRedrawn'); |
| 1129 |
jQuery(document).trigger('ph:adminPostActionsRedrawn', ['viewing']); |
| 1130 |
|
| 1131 |
ph_redraw_notes_grid('viewing'); |
| 1132 |
}, 'html'); |
| 1133 |
} |
| 1134 |
|
| 1135 |
redraw_viewing_details_meta_box(); |
| 1136 |
} |
| 1137 |
|
| 1138 |
jQuery(document).ready(function($) |
| 1139 |
{ |
| 1140 |
$(document).on('click', 'a.viewing-action', function(e) |
| 1141 |
{ |
| 1142 |
e.preventDefault(); |
| 1143 |
|
| 1144 |
var this_href = $(this).attr('href'); |
| 1145 |
|
| 1146 |
$(this).attr('disabled', 'disabled'); |
| 1147 |
|
| 1148 |
if ( this_href == '#action_panel_viewing_carried_out' ) |
| 1149 |
{ |
| 1150 |
var data = { |
| 1151 |
action: 'propertyhive_viewing_carried_out', |
| 1152 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1153 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1154 |
}; |
| 1155 |
jQuery.post( ajaxurl, data, function(response) |
| 1156 |
{ |
| 1157 |
redraw_viewing_actions(); |
| 1158 |
}, 'json'); |
| 1159 |
return; |
| 1160 |
} |
| 1161 |
|
| 1162 |
if ( this_href == '#action_panel_viewing_no_show' ) |
| 1163 |
{ |
| 1164 |
var data = { |
| 1165 |
action: 'propertyhive_viewing_no_show', |
| 1166 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1167 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1168 |
}; |
| 1169 |
jQuery.post( ajaxurl, data, function(response) |
| 1170 |
{ |
| 1171 |
redraw_viewing_actions(); |
| 1172 |
}, 'json'); |
| 1173 |
return; |
| 1174 |
} |
| 1175 |
|
| 1176 |
if ( this_href == '#action_panel_viewing_email_applicant_booking_confirmation' ) |
| 1177 |
{ |
| 1178 |
var data = { |
| 1179 |
action: 'propertyhive_viewing_email_applicant_booking_confirmation', |
| 1180 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1181 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1182 |
}; |
| 1183 |
jQuery.post( ajaxurl, data, function(response) |
| 1184 |
{ |
| 1185 |
if ( !response.success ) |
| 1186 |
{ |
| 1187 |
alert('Error: ' + response.data); |
| 1188 |
} |
| 1189 |
redraw_viewing_actions(); |
| 1190 |
}, 'json'); |
| 1191 |
return; |
| 1192 |
} |
| 1193 |
|
| 1194 |
if ( this_href == '#action_panel_viewing_email_owner_booking_confirmation' ) |
| 1195 |
{ |
| 1196 |
var data = { |
| 1197 |
action: 'propertyhive_viewing_email_owner_booking_confirmation', |
| 1198 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1199 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1200 |
}; |
| 1201 |
jQuery.post( ajaxurl, data, function(response) |
| 1202 |
{ |
| 1203 |
if ( !response.success ) |
| 1204 |
{ |
| 1205 |
alert('Error: ' + response.data); |
| 1206 |
} |
| 1207 |
redraw_viewing_actions(); |
| 1208 |
}, 'json'); |
| 1209 |
return; |
| 1210 |
} |
| 1211 |
|
| 1212 |
if ( this_href == '#action_panel_viewing_email_attending_negotiator_booking_confirmation' ) |
| 1213 |
{ |
| 1214 |
if ( ph_viewing_negotiators_changed ) |
| 1215 |
{ |
| 1216 |
alert("The negotiators have changed since the viewing was last saved. Please save the viewing then try again"); |
| 1217 |
return; |
| 1218 |
} |
| 1219 |
|
| 1220 |
var data = { |
| 1221 |
action: 'propertyhive_viewing_email_attending_negotiator_booking_confirmation', |
| 1222 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1223 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1224 |
}; |
| 1225 |
jQuery.post( ajaxurl, data, function(response) |
| 1226 |
{ |
| 1227 |
if ( !response.success ) |
| 1228 |
{ |
| 1229 |
alert('Error: ' + response.data); |
| 1230 |
} |
| 1231 |
redraw_viewing_actions(); |
| 1232 |
}, 'json'); |
| 1233 |
return; |
| 1234 |
} |
| 1235 |
|
| 1236 |
if ( this_href == '#action_panel_viewing_email_applicant_cancellation_notification' ) |
| 1237 |
{ |
| 1238 |
var data = { |
| 1239 |
action: 'propertyhive_viewing_email_applicant_cancellation_notification', |
| 1240 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1241 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1242 |
}; |
| 1243 |
jQuery.post( ajaxurl, data, function(response) |
| 1244 |
{ |
| 1245 |
if ( !response.success ) |
| 1246 |
{ |
| 1247 |
alert('Error: ' + response.data); |
| 1248 |
} |
| 1249 |
redraw_viewing_actions(); |
| 1250 |
}, 'json'); |
| 1251 |
return; |
| 1252 |
} |
| 1253 |
|
| 1254 |
if ( this_href == '#action_panel_viewing_email_owner_cancellation_notification' ) |
| 1255 |
{ |
| 1256 |
var data = { |
| 1257 |
action: 'propertyhive_viewing_email_owner_cancellation_notification', |
| 1258 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1259 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1260 |
}; |
| 1261 |
jQuery.post( ajaxurl, data, function(response) |
| 1262 |
{ |
| 1263 |
if ( !response.success ) |
| 1264 |
{ |
| 1265 |
alert('Error: ' + response.data); |
| 1266 |
} |
| 1267 |
redraw_viewing_actions(); |
| 1268 |
}, 'json'); |
| 1269 |
return; |
| 1270 |
} |
| 1271 |
|
| 1272 |
if ( this_href == '#action_panel_viewing_email_attending_negotiator_cancellation_notification' ) |
| 1273 |
{ |
| 1274 |
if ( ph_viewing_negotiators_changed ) |
| 1275 |
{ |
| 1276 |
alert("The negotiators have changed since the viewing was last saved. Please save the viewing then try again"); |
| 1277 |
return; |
| 1278 |
} |
| 1279 |
|
| 1280 |
var data = { |
| 1281 |
action: 'propertyhive_viewing_email_attending_negotiator_cancellation_notification', |
| 1282 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1283 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1284 |
}; |
| 1285 |
jQuery.post( ajaxurl, data, function(response) |
| 1286 |
{ |
| 1287 |
if ( !response.success ) |
| 1288 |
{ |
| 1289 |
alert('Error: ' + response.data); |
| 1290 |
} |
| 1291 |
redraw_viewing_actions(); |
| 1292 |
}, 'json'); |
| 1293 |
return; |
| 1294 |
} |
| 1295 |
|
| 1296 |
if ( this_href == '#action_panel_viewing_feedback_not_required' ) |
| 1297 |
{ |
| 1298 |
var data = { |
| 1299 |
action: 'propertyhive_viewing_feedback_not_required', |
| 1300 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1301 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1302 |
}; |
| 1303 |
jQuery.post( ajaxurl, data, function(response) |
| 1304 |
{ |
| 1305 |
redraw_viewing_actions(); |
| 1306 |
}, 'json'); |
| 1307 |
return; |
| 1308 |
} |
| 1309 |
|
| 1310 |
if ( this_href == '#action_panel_viewing_revert_feedback_passed_on' ) |
| 1311 |
{ |
| 1312 |
var data = { |
| 1313 |
action: 'propertyhive_viewing_feedback_passed_on', |
| 1314 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1315 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1316 |
}; |
| 1317 |
jQuery.post( ajaxurl, data, function(response) |
| 1318 |
{ |
| 1319 |
redraw_viewing_actions(); |
| 1320 |
}, 'json'); |
| 1321 |
return; |
| 1322 |
} |
| 1323 |
|
| 1324 |
if ( this_href == '#action_panel_viewing_revert_pending' ) |
| 1325 |
{ |
| 1326 |
var data = { |
| 1327 |
action: 'propertyhive_viewing_revert_pending', |
| 1328 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1329 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1330 |
}; |
| 1331 |
jQuery.post( ajaxurl, data, function(response) |
| 1332 |
{ |
| 1333 |
redraw_viewing_actions(); |
| 1334 |
}, 'json'); |
| 1335 |
return; |
| 1336 |
} |
| 1337 |
|
| 1338 |
if ( this_href == '#action_panel_viewing_revert_feedback_pending' ) |
| 1339 |
{ |
| 1340 |
var data = { |
| 1341 |
action: 'propertyhive_viewing_revert_feedback_pending', |
| 1342 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1343 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1344 |
}; |
| 1345 |
jQuery.post( ajaxurl, data, function(response) |
| 1346 |
{ |
| 1347 |
redraw_viewing_actions(); |
| 1348 |
}, 'json'); |
| 1349 |
return; |
| 1350 |
} |
| 1351 |
|
| 1352 |
$('#propertyhive_viewing_actions_meta_box').stop().fadeOut(300, function() |
| 1353 |
{ |
| 1354 |
$(this_href).stop().fadeIn(300, function() |
| 1355 |
{ |
| 1356 |
|
| 1357 |
}); |
| 1358 |
}); |
| 1359 |
}); |
| 1360 |
|
| 1361 |
$(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.action-cancel', function(e) |
| 1362 |
{ |
| 1363 |
e.preventDefault(); |
| 1364 |
|
| 1365 |
redraw_viewing_actions(); |
| 1366 |
}); |
| 1367 |
|
| 1368 |
$(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.owner-booking-confirmation-action-submit', function(e) |
| 1369 |
{ |
| 1370 |
e.preventDefault(); |
| 1371 |
|
| 1372 |
var ph_action_button = $(this); |
| 1373 |
ph_action_button.attr('disabled', 'disabled'); |
| 1374 |
|
| 1375 |
// Create FormData object and append data |
| 1376 |
var form_data = new FormData(); |
| 1377 |
form_data.append('action', 'propertyhive_viewing_email_owner_booking_confirmation'); |
| 1378 |
form_data.append('viewing_id', ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id )); |
| 1379 |
form_data.append('subject', $('#_owner_confirmation_email_subject').val()); |
| 1380 |
form_data.append('body', $('#_owner_confirmation_email_body').val()); |
| 1381 |
form_data.append('security', propertyhive_admin_meta_boxes.viewing_actions_nonce); |
| 1382 |
|
| 1383 |
// Get the file input element and the selected files |
| 1384 |
var file_input = $('#_owner_confirmation_email_attachment'); |
| 1385 |
var files = file_input.prop('files'); |
| 1386 |
|
| 1387 |
// Check if at least one file has been selected |
| 1388 |
if (files.length !== 0) |
| 1389 |
{ |
| 1390 |
// Append each file to the FormData object |
| 1391 |
$.each(files, function(index, file) |
| 1392 |
{ |
| 1393 |
form_data.append('attachments[]', file); |
| 1394 |
}); |
| 1395 |
} |
| 1396 |
|
| 1397 |
$.ajax({ |
| 1398 |
url: ajaxurl, // WordPress AJAX URL |
| 1399 |
type: 'POST', |
| 1400 |
data: form_data, |
| 1401 |
contentType: false, |
| 1402 |
processData: false, |
| 1403 |
dataType: 'json', // Expect JSON response |
| 1404 |
success: function(response) |
| 1405 |
{ |
| 1406 |
if (response.success) |
| 1407 |
{ |
| 1408 |
redraw_viewing_actions(); |
| 1409 |
} |
| 1410 |
else |
| 1411 |
{ |
| 1412 |
alert('Error: ' + response.data); |
| 1413 |
ph_action_button.attr('disabled', false); |
| 1414 |
} |
| 1415 |
}, |
| 1416 |
error: function(jqXHR, textStatus, errorThrown) { |
| 1417 |
console.log('AJAX error: ' + textStatus + ' : ' + errorThrown); |
| 1418 |
alert('An unexpected error occurred: ' + textStatus + ' : ' + errorThrown); |
| 1419 |
} |
| 1420 |
}); |
| 1421 |
return; |
| 1422 |
}); |
| 1423 |
|
| 1424 |
$(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.applicant-booking-confirmation-action-submit', function(e) |
| 1425 |
{ |
| 1426 |
e.preventDefault(); |
| 1427 |
|
| 1428 |
var ph_action_button = $(this); |
| 1429 |
ph_action_button.attr('disabled', 'disabled'); |
| 1430 |
|
| 1431 |
// Create FormData object and append data |
| 1432 |
var form_data = new FormData(); |
| 1433 |
form_data.append('action', 'propertyhive_viewing_email_applicant_booking_confirmation'); |
| 1434 |
form_data.append('viewing_id', ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id )); |
| 1435 |
form_data.append('subject', $('#_applicant_confirmation_email_subject').val()); |
| 1436 |
form_data.append('body', $('#_applicant_confirmation_email_body').val()); |
| 1437 |
form_data.append('security', propertyhive_admin_meta_boxes.viewing_actions_nonce); |
| 1438 |
|
| 1439 |
// Get the file input element and the selected files |
| 1440 |
var file_input = $('#_applicant_confirmation_email_attachment'); |
| 1441 |
var files = file_input.prop('files'); |
| 1442 |
|
| 1443 |
// Check if at least one file has been selected |
| 1444 |
if (files.length !== 0) |
| 1445 |
{ |
| 1446 |
// Append each file to the FormData object |
| 1447 |
$.each(files, function(index, file) |
| 1448 |
{ |
| 1449 |
form_data.append('attachments[]', file); |
| 1450 |
}); |
| 1451 |
} |
| 1452 |
|
| 1453 |
$.ajax({ |
| 1454 |
url: ajaxurl, // WordPress AJAX URL |
| 1455 |
type: 'POST', |
| 1456 |
data: form_data, |
| 1457 |
contentType: false, |
| 1458 |
processData: false, |
| 1459 |
dataType: 'json', // Expect JSON response |
| 1460 |
success: function(response) |
| 1461 |
{ |
| 1462 |
if (response.success) |
| 1463 |
{ |
| 1464 |
redraw_viewing_actions(); |
| 1465 |
} |
| 1466 |
else |
| 1467 |
{ |
| 1468 |
alert('Error: ' + response.data); |
| 1469 |
ph_action_button.attr('disabled', false); |
| 1470 |
} |
| 1471 |
}, |
| 1472 |
error: function(jqXHR, textStatus, errorThrown) { |
| 1473 |
console.log('AJAX error: ' + textStatus + ' : ' + errorThrown); |
| 1474 |
alert('An unexpected error occurred: ' + textStatus + ' : ' + errorThrown); |
| 1475 |
} |
| 1476 |
}); |
| 1477 |
return; |
| 1478 |
}); |
| 1479 |
|
| 1480 |
$(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.attending-negotiator-booking-confirmation-action-submit', function(e) |
| 1481 |
{ |
| 1482 |
e.preventDefault(); |
| 1483 |
|
| 1484 |
var ph_action_button = $(this); |
| 1485 |
ph_action_button.attr('disabled', 'disabled'); |
| 1486 |
|
| 1487 |
// Create FormData object and append data |
| 1488 |
var form_data = new FormData(); |
| 1489 |
form_data.append('action', 'propertyhive_viewing_email_attending_negotiator_booking_confirmation'); |
| 1490 |
form_data.append('viewing_id', ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id )); |
| 1491 |
form_data.append('subject', $('#_attending_negotiator_confirmation_email_subject').val()); |
| 1492 |
form_data.append('body', $('#_attending_negotiator_confirmation_email_body').val()); |
| 1493 |
form_data.append('security', propertyhive_admin_meta_boxes.viewing_actions_nonce); |
| 1494 |
|
| 1495 |
// Get the file input element and the selected files |
| 1496 |
var file_input = $('#_attending_negotiator_confirmation_email_attachment'); |
| 1497 |
var files = file_input.prop('files'); |
| 1498 |
|
| 1499 |
// Check if at least one file has been selected |
| 1500 |
if (files.length !== 0) |
| 1501 |
{ |
| 1502 |
// Append each file to the FormData object |
| 1503 |
$.each(files, function(index, file) |
| 1504 |
{ |
| 1505 |
form_data.append('attachments[]', file); |
| 1506 |
}); |
| 1507 |
} |
| 1508 |
|
| 1509 |
$.ajax({ |
| 1510 |
url: ajaxurl, // WordPress AJAX URL |
| 1511 |
type: 'POST', |
| 1512 |
data: form_data, |
| 1513 |
contentType: false, |
| 1514 |
processData: false, |
| 1515 |
dataType: 'json', // Expect JSON response |
| 1516 |
success: function(response) |
| 1517 |
{ |
| 1518 |
if (response.success) |
| 1519 |
{ |
| 1520 |
redraw_viewing_actions(); |
| 1521 |
} |
| 1522 |
else |
| 1523 |
{ |
| 1524 |
alert('Error: ' + response.data); |
| 1525 |
ph_action_button.attr('disabled', false); |
| 1526 |
} |
| 1527 |
}, |
| 1528 |
error: function(jqXHR, textStatus, errorThrown) { |
| 1529 |
console.log('AJAX error: ' + textStatus + ' : ' + errorThrown); |
| 1530 |
alert('An unexpected error occurred: ' + textStatus + ' : ' + errorThrown); |
| 1531 |
} |
| 1532 |
}); |
| 1533 |
|
| 1534 |
return; |
| 1535 |
}); |
| 1536 |
|
| 1537 |
$(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.owner-cancellation-notification-action-submit', function(e) |
| 1538 |
{ |
| 1539 |
e.preventDefault(); |
| 1540 |
|
| 1541 |
var ph_action_button = $(this); |
| 1542 |
ph_action_button.attr('disabled', 'disabled'); |
| 1543 |
|
| 1544 |
// Create FormData object and append data |
| 1545 |
var form_data = new FormData(); |
| 1546 |
form_data.append('action', 'propertyhive_viewing_email_owner_cancellation_notification'); |
| 1547 |
form_data.append('viewing_id', ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id )); |
| 1548 |
form_data.append('subject', $('#_owner_cancellation_notification_email_subject').val()); |
| 1549 |
form_data.append('body', $('#_owner_cancellation_notification_email_body').val()); |
| 1550 |
form_data.append('security', propertyhive_admin_meta_boxes.viewing_actions_nonce); |
| 1551 |
|
| 1552 |
// Get the file input element and the selected files |
| 1553 |
var file_input = $('#_owner_cancellation_notification_email_attachment'); |
| 1554 |
var files = file_input.prop('files'); |
| 1555 |
|
| 1556 |
// Check if at least one file has been selected |
| 1557 |
if (files.length !== 0) |
| 1558 |
{ |
| 1559 |
// Append each file to the FormData object |
| 1560 |
$.each(files, function(index, file) |
| 1561 |
{ |
| 1562 |
form_data.append('attachments[]', file); |
| 1563 |
}); |
| 1564 |
} |
| 1565 |
|
| 1566 |
$.ajax({ |
| 1567 |
url: ajaxurl, // WordPress AJAX URL |
| 1568 |
type: 'POST', |
| 1569 |
data: form_data, |
| 1570 |
contentType: false, |
| 1571 |
processData: false, |
| 1572 |
dataType: 'json', // Expect JSON response |
| 1573 |
success: function(response) |
| 1574 |
{ |
| 1575 |
if (response.success) |
| 1576 |
{ |
| 1577 |
redraw_viewing_actions(); |
| 1578 |
} |
| 1579 |
else |
| 1580 |
{ |
| 1581 |
alert('Error: ' + response.data); |
| 1582 |
ph_action_button.attr('disabled', false); |
| 1583 |
} |
| 1584 |
}, |
| 1585 |
error: function(jqXHR, textStatus, errorThrown) { |
| 1586 |
console.log('AJAX error: ' + textStatus + ' : ' + errorThrown); |
| 1587 |
alert('An unexpected error occurred: ' + textStatus + ' : ' + errorThrown); |
| 1588 |
} |
| 1589 |
}); |
| 1590 |
return; |
| 1591 |
}); |
| 1592 |
|
| 1593 |
$(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.applicant-cancellation-notification-action-submit', function(e) |
| 1594 |
{ |
| 1595 |
e.preventDefault(); |
| 1596 |
|
| 1597 |
var ph_action_button = $(this); |
| 1598 |
ph_action_button.attr('disabled', 'disabled'); |
| 1599 |
|
| 1600 |
// Create FormData object and append data |
| 1601 |
var form_data = new FormData(); |
| 1602 |
form_data.append('action', 'propertyhive_viewing_email_applicant_cancellation_notification'); |
| 1603 |
form_data.append('viewing_id', ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id )); |
| 1604 |
form_data.append('subject', $('#_applicant_cancellation_notification_email_subject').val()); |
| 1605 |
form_data.append('body', $('#_applicant_cancellation_notification_email_body').val()); |
| 1606 |
form_data.append('security', propertyhive_admin_meta_boxes.viewing_actions_nonce); |
| 1607 |
|
| 1608 |
// Get the file input element and the selected files |
| 1609 |
var file_input = $('#_applicant_cancellation_notification_email_attachment'); |
| 1610 |
var files = file_input.prop('files'); |
| 1611 |
|
| 1612 |
// Check if at least one file has been selected |
| 1613 |
if (files.length !== 0) |
| 1614 |
{ |
| 1615 |
// Append each file to the FormData object |
| 1616 |
$.each(files, function(index, file) |
| 1617 |
{ |
| 1618 |
form_data.append('attachments[]', file); |
| 1619 |
}); |
| 1620 |
} |
| 1621 |
|
| 1622 |
$.ajax({ |
| 1623 |
url: ajaxurl, // WordPress AJAX URL |
| 1624 |
type: 'POST', |
| 1625 |
data: form_data, |
| 1626 |
contentType: false, |
| 1627 |
processData: false, |
| 1628 |
dataType: 'json', // Expect JSON response |
| 1629 |
success: function(response) |
| 1630 |
{ |
| 1631 |
if (response.success) |
| 1632 |
{ |
| 1633 |
redraw_viewing_actions(); |
| 1634 |
} |
| 1635 |
else |
| 1636 |
{ |
| 1637 |
alert('Error: ' + response.data); |
| 1638 |
ph_action_button.attr('disabled', false); |
| 1639 |
} |
| 1640 |
}, |
| 1641 |
error: function(jqXHR, textStatus, errorThrown) { |
| 1642 |
console.log('AJAX error: ' + textStatus + ' : ' + errorThrown); |
| 1643 |
alert('An unexpected error occurred: ' + textStatus + ' : ' + errorThrown); |
| 1644 |
} |
| 1645 |
}); |
| 1646 |
return; |
| 1647 |
}); |
| 1648 |
|
| 1649 |
$(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.attending-negotiator-cancellation-notification-action-submit', function(e) |
| 1650 |
{ |
| 1651 |
e.preventDefault(); |
| 1652 |
|
| 1653 |
var ph_action_button = $(this); |
| 1654 |
ph_action_button.attr('disabled', 'disabled'); |
| 1655 |
|
| 1656 |
// Create FormData object and append data |
| 1657 |
var form_data = new FormData(); |
| 1658 |
form_data.append('action', 'propertyhive_viewing_email_attending_negotiator_cancellation_notification'); |
| 1659 |
form_data.append('viewing_id', ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id )); |
| 1660 |
form_data.append('subject', $('#_attending_negotiator_cancellation_notification_email_subject').val()); |
| 1661 |
form_data.append('body', $('#_attending_negotiator_cancellation_notification_email_body').val()); |
| 1662 |
form_data.append('security', propertyhive_admin_meta_boxes.viewing_actions_nonce); |
| 1663 |
|
| 1664 |
// Get the file input element and the selected files |
| 1665 |
var file_input = $('#_attending_negotiator_cancellation_notification_email_attachment'); |
| 1666 |
var files = file_input.prop('files'); |
| 1667 |
|
| 1668 |
// Check if at least one file has been selected |
| 1669 |
if (files.length !== 0) |
| 1670 |
{ |
| 1671 |
// Append each file to the FormData object |
| 1672 |
$.each(files, function(index, file) |
| 1673 |
{ |
| 1674 |
form_data.append('attachments[]', file); |
| 1675 |
}); |
| 1676 |
} |
| 1677 |
|
| 1678 |
$.ajax({ |
| 1679 |
url: ajaxurl, // WordPress AJAX URL |
| 1680 |
type: 'POST', |
| 1681 |
data: form_data, |
| 1682 |
contentType: false, |
| 1683 |
processData: false, |
| 1684 |
dataType: 'json', // Expect JSON response |
| 1685 |
success: function(response) |
| 1686 |
{ |
| 1687 |
if (response.success) |
| 1688 |
{ |
| 1689 |
redraw_viewing_actions(); |
| 1690 |
} |
| 1691 |
else |
| 1692 |
{ |
| 1693 |
alert('Error: ' + response.data); |
| 1694 |
ph_action_button.attr('disabled', false); |
| 1695 |
} |
| 1696 |
}, |
| 1697 |
error: function(jqXHR, textStatus, errorThrown) { |
| 1698 |
console.log('AJAX error: ' + textStatus + ' : ' + errorThrown); |
| 1699 |
alert('An unexpected error occurred: ' + textStatus + ' : ' + errorThrown); |
| 1700 |
} |
| 1701 |
}); |
| 1702 |
|
| 1703 |
return; |
| 1704 |
}); |
| 1705 |
|
| 1706 |
|
| 1707 |
$(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.cancelled-reason-action-submit', function(e) |
| 1708 |
{ |
| 1709 |
e.preventDefault(); |
| 1710 |
|
| 1711 |
$(this).attr('disabled', 'disabled'); |
| 1712 |
|
| 1713 |
// Submit interested feedback |
| 1714 |
var data = { |
| 1715 |
action: 'propertyhive_viewing_cancelled', |
| 1716 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1717 |
cancelled_reason: $('#_cancelled_reason').val(), |
| 1718 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1719 |
}; |
| 1720 |
|
| 1721 |
if ($('#_cancelled_reason_public').is(':checked')) |
| 1722 |
{ |
| 1723 |
data.cancelled_reason_public = $('#_cancelled_reason_public').val(); |
| 1724 |
} |
| 1725 |
|
| 1726 |
jQuery.post( ajaxurl, data, function(response) |
| 1727 |
{ |
| 1728 |
redraw_viewing_actions(); |
| 1729 |
}, 'json'); |
| 1730 |
}); |
| 1731 |
|
| 1732 |
$(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.interested-feedback-action-submit', function(e) |
| 1733 |
{ |
| 1734 |
e.preventDefault(); |
| 1735 |
|
| 1736 |
$(this).attr('disabled', 'disabled'); |
| 1737 |
|
| 1738 |
// Submit interested feedback |
| 1739 |
var data = { |
| 1740 |
action: 'propertyhive_viewing_interested_feedback', |
| 1741 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1742 |
feedback: $('#_interested_feedback').val(), |
| 1743 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1744 |
}; |
| 1745 |
|
| 1746 |
jQuery.post( ajaxurl, data, function(response) |
| 1747 |
{ |
| 1748 |
redraw_viewing_actions(); |
| 1749 |
}, 'json'); |
| 1750 |
}); |
| 1751 |
|
| 1752 |
$(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.not-interested-feedback-action-submit', function(e) |
| 1753 |
{ |
| 1754 |
e.preventDefault(); |
| 1755 |
|
| 1756 |
$(this).attr('disabled', 'disabled'); |
| 1757 |
|
| 1758 |
// Submit interested feedback |
| 1759 |
var data = { |
| 1760 |
action: 'propertyhive_viewing_not_interested_feedback', |
| 1761 |
viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1762 |
feedback: $('#_not_interested_feedback').val(), |
| 1763 |
security: propertyhive_admin_meta_boxes.viewing_actions_nonce, |
| 1764 |
}; |
| 1765 |
|
| 1766 |
jQuery.post( ajaxurl, data, function(response) |
| 1767 |
{ |
| 1768 |
redraw_viewing_actions(); |
| 1769 |
}, 'json'); |
| 1770 |
}) |
| 1771 |
}); |
| 1772 |
|
| 1773 |
function ph_redraw_notes_grid(section) |
| 1774 |
{ |
| 1775 |
var data = { |
| 1776 |
action: 'propertyhive_get_notes_grid', |
| 1777 |
post_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ), |
| 1778 |
section: section, |
| 1779 |
security: propertyhive_admin_meta_boxes.get_notes_nonce |
| 1780 |
}; |
| 1781 |
|
| 1782 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 1783 |
{ |
| 1784 |
if ( propertyhive_admin_meta_boxes.disable_notes_mention != true ) |
| 1785 |
{ |
| 1786 |
tinymce.remove('.propertyhive-lightbox-notes textarea#add_note'); |
| 1787 |
tinymce.remove('#propertyhive-' + section + '-history-notes textarea#add_note'); |
| 1788 |
} |
| 1789 |
|
| 1790 |
jQuery('#propertyhive_' + section + '_notes_container').html(response); |
| 1791 |
|
| 1792 |
if ( propertyhive_admin_meta_boxes.disable_notes_mention != true ) |
| 1793 |
{ |
| 1794 |
tinymce.init({ |
| 1795 |
selector: ( ph_lightbox_open ? '.propertyhive-lightbox-notes' : '#propertyhive-' + section + '-history-notes' ) + ' textarea#add_note', |
| 1796 |
menubar: false, |
| 1797 |
toolbar: false, |
| 1798 |
statusbar: false, |
| 1799 |
forced_root_block: '', // Disable the <p> tags |
| 1800 |
force_br_newlines: true, |
| 1801 |
force_p_newlines: false, |
| 1802 |
external_plugins: |
| 1803 |
{ |
| 1804 |
'mention' : propertyhive_admin_meta_boxes.plugin_url + '/assets/js/tinymce-mention-plugin/tinymce-mention-plugin.js', |
| 1805 |
'placeholder' : propertyhive_admin_meta_boxes.plugin_url + '/assets/js/tinymce-placeholder/mce.placeholder.js' |
| 1806 |
}, |
| 1807 |
setup: function(editor) |
| 1808 |
{ |
| 1809 |
editor.on('init', function() |
| 1810 |
{ |
| 1811 |
editor.getContainer().style.border = '1px solid #ccc'; |
| 1812 |
}); |
| 1813 |
}, |
| 1814 |
mentions: |
| 1815 |
{ |
| 1816 |
source: function (query, process, delimiter) |
| 1817 |
{ |
| 1818 |
// Do your ajax call |
| 1819 |
jQuery.ajax({ |
| 1820 |
url: ajaxurl, // Use WordPress AJAX URL |
| 1821 |
method: 'POST', |
| 1822 |
data: { |
| 1823 |
action: 'propertyhive_fetch_note_mentions', |
| 1824 |
query: query, |
| 1825 |
security: propertyhive_admin_meta_boxes.get_notes_nonce |
| 1826 |
}, |
| 1827 |
success: function(response) { |
| 1828 |
process(response); |
| 1829 |
} |
| 1830 |
}); |
| 1831 |
} |
| 1832 |
}, |
| 1833 |
content_style: ` |
| 1834 |
html, body { |
| 1835 |
height: 100%; /* Set both html and body to 100% height */ |
| 1836 |
margin: 0; |
| 1837 |
padding: 0; |
| 1838 |
overflow: hidden; /* Prevent scrolling issues */ |
| 1839 |
} |
| 1840 |
.mce-content-body { |
| 1841 |
margin: 0; /* Replace margin with padding */ |
| 1842 |
padding: 1rem; /* Add padding */ |
| 1843 |
box-sizing: border-box; /* Include padding in height calculation */ |
| 1844 |
height: 100%; |
| 1845 |
overflow-y: auto; /* Allow vertical scrolling within the body */ |
| 1846 |
} |
| 1847 |
` |
| 1848 |
}); |
| 1849 |
} |
| 1850 |
}, 'html'); |
| 1851 |
} |
| 1852 |
|
| 1853 |
function ph_redraw_pinned_notes_grid(section) |
| 1854 |
{ |
| 1855 |
var data = { |
| 1856 |
action: 'propertyhive_get_pinned_notes_grid', |
| 1857 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 1858 |
pinned: 1, |
| 1859 |
section: section, |
| 1860 |
security: propertyhive_admin_meta_boxes.get_notes_nonce |
| 1861 |
}; |
| 1862 |
|
| 1863 |
jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) |
| 1864 |
{ |
| 1865 |
jQuery('#propertyhive_' + section + '_pinned_notes_container').html(response); |
| 1866 |
}, 'html'); |
| 1867 |
} |
| 1868 |
|
| 1869 |
function initialise_datepicker() { |
| 1870 |
jQuery( ".date-picker" ).datepicker({ |
| 1871 |
dateFormat: "yy-mm-dd", |
| 1872 |
numberOfMonths: 1, |
| 1873 |
showButtonPanel: true |
| 1874 |
}).on("change", function(e) { |
| 1875 |
var curDate = jQuery(this).val(); |
| 1876 |
var valid = true; |
| 1877 |
|
| 1878 |
if ( curDate != '' ) |
| 1879 |
{ |
| 1880 |
var splitDate = curDate.split("-") |
| 1881 |
if ( splitDate.length != 3 ) |
| 1882 |
{ |
| 1883 |
valid = false; |
| 1884 |
} |
| 1885 |
else |
| 1886 |
{ |
| 1887 |
if ( splitDate[0].length != 4 || splitDate[1].length != 2 || splitDate[2].length != 2 ) |
| 1888 |
{ |
| 1889 |
valid = false; |
| 1890 |
} |
| 1891 |
} |
| 1892 |
|
| 1893 |
if (!valid) |
| 1894 |
{ |
| 1895 |
alert("Invalid date entered. Please select a date from the calendar and ensure date is in the format YYYY-MM-DD"); |
| 1896 |
} |
| 1897 |
} |
| 1898 |
}); |
| 1899 |
} |
| 1900 |
|
| 1901 |
function add_months(date, months) { |
| 1902 |
var d = date.getDate(); |
| 1903 |
date.setMonth(date.getMonth() + +months); |
| 1904 |
if (date.getDate() != d) |
| 1905 |
{ |
| 1906 |
date.setDate(0); |
| 1907 |
} |
| 1908 |
return date; |
| 1909 |
} |
| 1910 |
|