PluginProbe
Property Hive / 2.2.4
Property Hive v2.2.4
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / assets / js / admin / meta-boxes.js

meta-boxes.js in Property Hive 2.2.4, at assets/js/admin/meta-boxes.js

1,903 lines 66.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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">&nbsp; <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 post_id: propertyhive_admin_meta_boxes.post_id,
399 key_date_type: $('#_add_key_date_type').val(),
400 key_date_description: $('#_add_key_date_description').val(),
401 key_date_due: $('#_add_key_date_due').val(),
402 key_date_hours: $('#_add_key_date_due_hours').val(),
403 key_date_minutes: $('#_add_key_date_due_minutes').val(),
404 key_date_notes: $('#_add_key_date_notes').val(),
405 };
406
407 $.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) {
408 var data = {
409 action: 'propertyhive_get_management_dates_grid',
410 post_id: propertyhive_admin_meta_boxes.post_id,
411 };
412
413 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
414 {
415 jQuery('#propertyhive_management_dates_container').html(response);
416 initialise_datepicker();
417 }, 'html');
418 });
419
420 return false;
421 });
422
423 $('[id=\'propertyhive-management-dates\']').on( 'click', '#filter-key-dates-grid', function() {
424
425 if ( $(this).val() == 'Updating...' ) { return false; }
426
427 $(this).val('Updating...');
428 $(this).attr('disabled', 'disabled');
429
430 var data = {
431 action: 'propertyhive_get_management_dates_grid',
432 post_id: propertyhive_admin_meta_boxes.post_id,
433 selected_type_id: $('#_type_id_filter').val(),
434 selected_status: $('#_date_status_filter').val(),
435 };
436
437 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
438 {
439 jQuery('#propertyhive_management_dates_container').html(response);
440 initialise_datepicker();
441 }, 'html');
442
443 return false;
444 });
445
446 $('[id=\'propertyhive-management-dates\']').on( 'click', '.meta-box-quick-edit', function() {
447
448 var post_id = $(this).attr('id');
449 var original_row = $('.post-' + post_id);
450
451 $('.quick-edit-row').hide();
452 $('.key-date-row').show();
453 original_row.hide();
454
455 if ( $('#quick-edit-' + post_id).length > 0 )
456 {
457 $('#quick-edit-' + post_id).show();
458 }
459 else
460 {
461 original_row.after('<tr id="quick-edit-' + post_id + '" class="quick-edit-row"><td colspan="4">Loading...</td></tr>');
462
463 var data = {
464 action: 'propertyhive_get_key_dates_quick_edit_row',
465 post_id: propertyhive_admin_meta_boxes.post_id,
466 date_post_id: post_id,
467 description: $('.post-' + post_id + ' .description .cell-main-content').text(),
468 status: $('.post-' + post_id + ' .status .cell-main-content').text(),
469 due_date_time: $('.post-' + post_id + ' .date_due .cell-main-content').text(),
470 notes: $('.post-' + post_id + ' .notes .hidden-key-date-notes').text(),
471 type: $('.post-' + post_id + ' .hidden-date-type-id').text(),
472 };
473
474 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
475 {
476 $('#quick-edit-' + post_id).html(response);
477 initialise_datepicker();
478 }, 'html');
479 }
480
481 return false;
482
483 });
484
485 $('[id=\'propertyhive-management-dates\']').on( 'click', '.meta-box-delete', function() {
486
487 var confirm_box = confirm('Are you sure you wish to delete this key date?');
488 if (!confirm_box)
489 {
490 return confirm_box;
491 }
492
493 var post_id = $(this).attr('id');
494
495 if ( $('#quick-edit-' + post_id).length > 0 )
496 {
497 $('#quick-edit-' + post_id).show();
498 }
499 else
500 {
501 var data = {
502 action: 'propertyhive_delete_key_date',
503 date_post_id: post_id,
504 security: propertyhive_admin_meta_boxes.delete_key_date_nonce,
505 };
506
507 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
508 {
509 var data = {
510 action: 'propertyhive_get_management_dates_grid',
511 post_id: propertyhive_admin_meta_boxes.post_id,
512 };
513
514 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
515 {
516 jQuery('#propertyhive_management_dates_container').html(response);
517 initialise_datepicker();
518 }, 'html');
519 }, 'json');
520 }
521
522 return false;
523
524 });
525
526 $('[id=\'propertyhive-management-dates\']').on( 'change', '#key_date_status', function() {
527
528 var quick_edit_row = $(this).closest('tr');
529 var next_key_date_checkbox = quick_edit_row.find('#next_key_date_checkbox');
530
531 if (next_key_date_checkbox.length !== 0)
532 {
533 if ( this.value == 'complete' )
534 {
535 // Show Book Next checkbox
536 next_key_date_checkbox.removeClass('hidden');
537 }
538 else
539 {
540 if( !next_key_date_checkbox.hasClass('hidden') )
541 {
542 // Hide Book Next checkbox
543 next_key_date_checkbox.addClass('hidden');
544
545 // Hide Next Key Date field, if visible
546 var next_key_date_field = quick_edit_row.find('#next_key_date_field');
547 if( !next_key_date_field.hasClass('hidden') )
548 {
549 next_key_date_field.addClass('hidden');
550 }
551
552 // Uncheck Book Next checkbox
553 quick_edit_row.find('#book_next_key_date').prop( 'checked', false );
554 }
555 }
556 }
557 });
558
559 $('[id=\'propertyhive-management-dates\']').on( 'click', '#book_next_key_date', function() {
560
561 // Show/Hide Next Key Date field when checkbox is checked and unchecked
562 var next_key_date_field = $(this).closest('tr').find('#next_key_date_field');
563 if( this.checked )
564 {
565 next_key_date_field.removeClass('hidden');
566 }
567 else
568 {
569 if( !next_key_date_field.hasClass('hidden') )
570 {
571 next_key_date_field.addClass('hidden');
572 }
573 }
574 });
575
576 $('[id=\'propertyhive-management-dates\']').on( 'click', '.save-quick-edit', function() {
577
578 var date_post_id = $(this).attr('id');
579
580 if ( $(this).text() == 'Saving...' ) { return false; }
581
582 $(this).text('Saving...');
583 $(this).attr('disabled', 'disabled');
584
585 var quick_edit_row = $('#quick-edit-' + date_post_id);
586
587 var data = {
588 action: 'propertyhive_save_key_date',
589 post_id: date_post_id,
590 description: quick_edit_row.find('#date_description').val(),
591 status: quick_edit_row.find('#key_date_status').val(),
592 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(),
593 type: quick_edit_row.find('#date_type').val(),
594 notes: quick_edit_row.find('#date_notes_quick_edit').val(),
595 security: propertyhive_admin_meta_boxes.save_key_date_nonce,
596 };
597
598 if (quick_edit_row.find('#book_next_key_date').length !== 0)
599 {
600 if ( quick_edit_row.find('#book_next_key_date').is(":checked") )
601 {
602 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();
603 }
604 }
605
606 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
607 {
608 var data = {
609 action: 'propertyhive_get_management_dates_grid',
610 post_id: propertyhive_admin_meta_boxes.post_id,
611 selected_type_id: $('#_type_id_filter').val(),
612 selected_status: $('#_date_status_filter').val(),
613 };
614
615 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
616 {
617 jQuery('#propertyhive_management_dates_container').html(response);
618 initialise_datepicker();
619 }, 'html');
620 }, 'html');
621
622 });
623
624 $('[id=\'propertyhive-management-dates\']').on( 'click', '.cancel-quick-edit', function() {
625 $('.quick-edit-row').hide();
626 $('.post-' + $(this).attr('id')).show();
627 });
628
629 $('[id=\'propertyhive-property-tenancies\']').on( 'click', '#filter-property-tenancies-grid', function() {
630
631 if ( $(this).val() == 'Updating...' ) { return false; }
632
633 $(this).val('Updating...');
634 $(this).attr('disabled', 'disabled');
635
636 var data = {
637 action: 'propertyhive_get_property_tenancies_grid',
638 post_id: propertyhive_admin_meta_boxes.post_id,
639 selected_status: $('#_tenancy_status_filter').val(),
640 };
641
642 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
643 {
644 jQuery('#propertyhive_property_tenancies_grid').html(response);
645 }, 'html');
646
647 return false;
648 });
649
650 $('[id=\'propertyhive-property-viewings\']').on( 'click', '#filter-property-viewings-grid', function() {
651
652 if ( $(this).val() == 'Updating...' ) { return false; }
653
654 $(this).val('Updating...');
655 $(this).attr('disabled', 'disabled');
656
657 var data = {
658 action: 'propertyhive_get_property_viewings_meta_box',
659 post_id: propertyhive_admin_meta_boxes.post_id,
660 selected_status: $('#_viewing_status_filter').val(),
661 };
662
663 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
664 {
665 jQuery('#propertyhive_property_viewings_meta_box').html(response);
666 }, 'html');
667
668 return false;
669 });
670
671 $('[id=\'propertyhive-contact-tenancies\']').on( 'click', '#filter-contact-tenancies-grid', function() {
672
673 if ( $(this).val() == 'Updating...' ) { return false; }
674
675 $(this).val('Updating...');
676 $(this).attr('disabled', 'disabled');
677
678 var data = {
679 action: 'propertyhive_get_contact_tenancies_grid',
680 post_id: propertyhive_admin_meta_boxes.post_id,
681 selected_status: $('#_tenancy_status_filter').val(),
682 };
683
684 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
685 {
686 jQuery('#propertyhive_contact_tenancies_grid').html(response);
687 }, 'html');
688
689 return false;
690 });
691
692 $('[id=\'propertyhive-contact-viewings\']').on( 'click', '#filter-contact-viewings-grid', function() {
693
694 if ( $(this).val() == 'Updating...' ) { return false; }
695
696 $(this).val('Updating...');
697 $(this).attr('disabled', 'disabled');
698
699 var data = {
700 action: 'propertyhive_get_contact_viewings_meta_box',
701 post_id: propertyhive_admin_meta_boxes.post_id,
702 selected_status: $('#_viewing_status_filter').val(),
703 };
704
705 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
706 {
707 jQuery('#propertyhive_contact_viewings_meta_box').html(response);
708 }, 'html');
709
710 return false;
711 });
712
713 $('[id=\'propertyhive-property-offers\']').on( 'click', '#filter-property-offers-grid', function() {
714
715 if ( $(this).val() == 'Updating...' ) { return false; }
716
717 $(this).val('Updating...');
718 $(this).attr('disabled', 'disabled');
719
720 var data = {
721 action: 'propertyhive_get_property_offers_meta_box',
722 post_id: propertyhive_admin_meta_boxes.post_id,
723 selected_status: $('#_offer_status_filter').val(),
724 };
725
726 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
727 {
728 jQuery('#propertyhive_property_offers_meta_box').html(response);
729 }, 'html');
730
731 return false;
732 });
733
734 $('[id=\'propertyhive-contact-offers\']').on( 'click', '#filter-contact-offers-grid', function() {
735
736 if ( $(this).val() == 'Updating...' ) { return false; }
737
738 $(this).val('Updating...');
739 $(this).attr('disabled', 'disabled');
740
741 var data = {
742 action: 'propertyhive_get_contact_offers_meta_box',
743 post_id: propertyhive_admin_meta_boxes.post_id,
744 selected_status: $('#_offer_status_filter').val(),
745 };
746
747 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
748 {
749 jQuery('#propertyhive_contact_offers_meta_box').html(response);
750 }, 'html');
751
752 return false;
753 });
754
755 $('[id=\'propertyhive-property-sales\']').on( 'click', '#filter-property-sales-grid', function() {
756
757 if ( $(this).val() == 'Updating...' ) { return false; }
758
759 $(this).val('Updating...');
760 $(this).attr('disabled', 'disabled');
761
762 var data = {
763 action: 'propertyhive_get_property_sales_meta_box',
764 post_id: propertyhive_admin_meta_boxes.post_id,
765 selected_status: $('#_sale_status_filter').val(),
766 };
767
768 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
769 {
770 jQuery('#propertyhive_property_sales_meta_box').html(response);
771 }, 'html');
772
773 return false;
774 });
775
776 $('[id=\'propertyhive-contact-sales\']').on( 'click', '#filter-contact-sales-grid', function() {
777
778 if ( $(this).val() == 'Updating...' ) { return false; }
779
780 $(this).val('Updating...');
781 $(this).attr('disabled', 'disabled');
782
783 var data = {
784 action: 'propertyhive_get_contact_sales_meta_box',
785 post_id: propertyhive_admin_meta_boxes.post_id,
786 selected_status: $('#_sale_status_filter').val(),
787 };
788
789 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
790 {
791 jQuery('#propertyhive_contact_sales_meta_box').html(response);
792 }, 'html');
793
794 return false;
795 });
796
797 $('[id=\'propertyhive-property-enquiries\']').on( 'click', '#filter-property-enquiries-grid', function() {
798
799 if ( $(this).val() == 'Updating...' ) { return false; }
800
801 $(this).val('Updating...');
802 $(this).attr('disabled', 'disabled');
803
804 var data = {
805 action: 'propertyhive_get_property_enquiries_meta_box',
806 post_id: propertyhive_admin_meta_boxes.post_id,
807 selected_status: $('#_enquiry_status_filter').val(),
808 };
809
810 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
811 {
812 jQuery('#propertyhive_property_enquiries_meta_box').html(response);
813 }, 'html');
814
815 return false;
816 });
817
818 $('[id=\'propertyhive-contact-enquiries\']').on( 'click', '#filter-contact-enquiries-grid', function() {
819
820 if ( $(this).val() == 'Updating...' ) { return false; }
821
822 $(this).val('Updating...');
823 $(this).attr('disabled', 'disabled');
824
825 var data = {
826 action: 'propertyhive_get_contact_enquiries_meta_box',
827 post_id: propertyhive_admin_meta_boxes.post_id,
828 selected_status: $('#_enquiry_status_filter').val(),
829 };
830
831 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
832 {
833 jQuery('#propertyhive_contact_enquiries_meta_box').html(response);
834 }, 'html');
835
836 return false;
837 });
838
839 $('.postbox').on( 'click', 'a[name=\'export_action\'][id^=\'export-\']', function(e)
840 {
841 e.preventDefault();
842
843 var record_ids = [];
844
845 $(this).parent().parent().parent().find('a[data-viewing-id]').each(function()
846 {
847 record_ids.push( parseInt($(this).attr('data-viewing-id')) );
848 });
849 $(this).parent().parent().parent().find('a[data-offer-id]').each(function()
850 {
851 record_ids.push( parseInt($(this).attr('data-offer-id')) );
852 });
853 $(this).parent().parent().parent().find('a[data-sale-id]').each(function()
854 {
855 record_ids.push( parseInt($(this).attr('data-sale-id')) );
856 });
857
858 var new_location = window.location.href;
859 new_location = new_location.split("#");
860 new_location = new_location[0];
861
862 window.location.href = new_location + '&sub_grid=' + $(this).attr('id').replace("export-", "") + '&record_ids=' + record_ids.join("|")
863 });
864
865 // Multiselect
866 $(".propertyhive_meta_box select.multiselect").chosen();
867
868 $(".post-type-viewing #_negotiator_ids").on('change', function()
869 {
870 ph_viewing_negotiators_changed = true;
871 });
872
873 $( document ).on('click', '.viewing-lightbox', function(e)
874 {
875 e.preventDefault();
876
877 ph_open_details_lightbox($(this).attr('data-viewing-id'), 'viewing');
878 });
879
880 $( document ).on('click', '.propertyhive-lightbox-buttons a.button-close', function(e)
881 {
882 e.preventDefault();
883
884 $.fancybox.close();
885 });
886
887 $( document ).on('click', '.propertyhive-lightbox-buttons a.button-prev', function(e)
888 {
889 e.preventDefault();
890
891 var previous_post_id = false;
892 $('a[data-viewing-id]').each(function()
893 {
894 var post_id = $(this).attr('data-viewing-id');
895
896 if ( post_id == ph_lightbox_post_id )
897 {
898 ph_open_details_lightbox(previous_post_id, 'viewing');
899
900 return;
901 }
902
903 previous_post_id = post_id;
904 });
905 });
906
907 $( document ).on('click', '.propertyhive-lightbox-buttons a.button-next', function(e)
908 {
909 e.preventDefault();
910
911 var use_next = false;
912 $('a[data-viewing-id]').each(function()
913 {
914 var post_id = $(this).attr('data-viewing-id');
915
916 if (use_next)
917 {
918 ph_open_details_lightbox(post_id, 'viewing');
919
920 return false;
921 }
922
923 if ( post_id == ph_lightbox_post_id )
924 {
925 use_next = true;
926 }
927 });
928 });
929
930 $('#tenure_id').change(function()
931 {
932 $('#leasehold_information').hide();
933
934 var selected_tenure = $(this).find('option:selected').text();
935
936 $.each(propertyhive_admin_meta_boxes.leasehold_tenures, function(index, value)
937 {
938 if ( selected_tenure != '' && value.toLowerCase() === selected_tenure.toLowerCase() )
939 {
940 $('#leasehold_information').show();
941 }
942 });
943 });
944
945 $('#_shared_ownership').change(function()
946 {
947 if ( $(this).is(':checked') )
948 {
949 $('#shared_ownership_information').show();
950 }
951 else
952 {
953 $('#shared_ownership_information').hide();
954 }
955 });
956 });
957
958 function ph_open_details_lightbox(post_id, section)
959 {
960 ph_lightbox_post_id = post_id;
961
962 jQuery.fancybox.close();
963
964 jQuery.fancybox.open({
965 src : ajaxurl + '?action=propertyhive_get_' + section + '_lightbox&post_id=' + ph_lightbox_post_id,
966 type : 'ajax',
967 beforeLoad: function()
968 {
969 ph_lightbox_open = true;
970 },
971 afterShow: function()
972 {
973 // hide/show next/prev buttons
974 var found_current = false;
975 var previous_exist = false;
976 var next_exist = false;
977 jQuery('a[data-' + section + '-id]').each(function()
978 {
979 var post_id = jQuery(this).attr('data-' + section + '-id');
980
981 if ( found_current )
982 {
983 next_exist = true;
984 }
985
986 if ( post_id == ph_lightbox_post_id )
987 {
988 // this is the lightbox being viewed
989 found_current = true;
990 }
991 else
992 {
993 if ( !found_current )
994 {
995 previous_exist = true;
996 }
997 }
998 });
999
1000 if ( previous_exist )
1001 {
1002 jQuery('.propertyhive-lightbox-buttons a.button-prev').show();
1003 }
1004 if ( next_exist )
1005 {
1006 jQuery('.propertyhive-lightbox-buttons a.button-next').show();
1007 }
1008
1009 if ( propertyhive_admin_meta_boxes.disable_notes_mention != true )
1010 {
1011 tinymce.remove('.propertyhive-lightbox-notes textarea#add_note');
1012
1013 tinymce.init({
1014 selector: '.propertyhive-lightbox-notes textarea#add_note',
1015 menubar: false,
1016 toolbar: false,
1017 statusbar: false,
1018 forced_root_block: '', // Disable the <p> tags
1019 force_br_newlines: true,
1020 force_p_newlines: false,
1021 external_plugins:
1022 {
1023 'mention' : propertyhive_admin_meta_boxes.plugin_url + '/assets/js/tinymce-mention-plugin/tinymce-mention-plugin.js',
1024 'placeholder' : propertyhive_admin_meta_boxes.plugin_url + '/assets/js/tinymce-placeholder/mce.placeholder.js'
1025 },
1026 setup: function(editor)
1027 {
1028 editor.on('init', function()
1029 {
1030 editor.getContainer().style.border = '1px solid #ccc';
1031 });
1032 },
1033 mentions:
1034 {
1035 source: function (query, process, delimiter)
1036 {
1037 // Do your ajax call
1038 jQuery.ajax({
1039 url: ajaxurl, // Use WordPress AJAX URL
1040 method: 'POST',
1041 data: {
1042 action: 'propertyhive_fetch_note_mentions',
1043 query: query,
1044 security: propertyhive_admin_meta_boxes.get_notes_nonce
1045 },
1046 success: function(response) {
1047 console.log(response);
1048 process(response);
1049 }
1050 });
1051 }
1052 },
1053 content_style: `
1054 html, body {
1055 height: 100%; /* Set both html and body to 100% height */
1056 margin: 0;
1057 padding: 0;
1058 overflow: hidden; /* Prevent scrolling issues */
1059 }
1060 .mce-content-body {
1061 margin: 0; /* Replace margin with padding */
1062 padding: 1rem; /* Add padding */
1063 box-sizing: border-box; /* Include padding in height calculation */
1064 height: 100%;
1065 overflow-y: auto; /* Allow vertical scrolling within the body */
1066 }
1067 `
1068 });
1069 }
1070 },
1071 beforeClose: function()
1072 {
1073 ph_lightbox_open = false;
1074 }
1075 });
1076 }
1077
1078 // VIEWINGS //
1079 jQuery(window).on('load', function()
1080 {
1081 //redraw_viewing_details_meta_box(); // called from within redraw_viewing_actions()
1082 redraw_viewing_actions();
1083 });
1084
1085 function redraw_viewing_details_meta_box()
1086 {
1087 if ( jQuery('#propertyhive_viewing_details_meta_box_container').length > 0 )
1088 {
1089 jQuery('#propertyhive_viewing_details_meta_box_container').html('Loading...');
1090
1091 var data = {
1092 action: 'propertyhive_get_viewing_details_meta_box',
1093 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1094 security: propertyhive_admin_meta_boxes.viewing_details_meta_nonce,
1095 readonly: ph_lightbox_open
1096 };
1097
1098 jQuery.post( ajaxurl, data, function(response)
1099 {
1100 jQuery('#propertyhive_viewing_details_meta_box_container').html(response);
1101 }, 'html');
1102 }
1103 }
1104
1105 function redraw_viewing_actions()
1106 {
1107 if ( jQuery('#propertyhive_viewing_actions_meta_box_container').length > 0 )
1108 {
1109 jQuery('#propertyhive_viewing_actions_meta_box_container').html('Loading...');
1110
1111 var data = {
1112 action: 'propertyhive_get_viewing_actions',
1113 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1114 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1115 };
1116
1117 jQuery.post( ajaxurl, data, function(response)
1118 {
1119 jQuery('#propertyhive_viewing_actions_meta_box_container').html(response);
1120
1121 jQuery(document).trigger('ph:adminViewingActionsRedrawn');
1122 jQuery(document).trigger('ph:adminPostActionsRedrawn', ['viewing']);
1123
1124 ph_redraw_notes_grid('viewing');
1125 }, 'html');
1126 }
1127
1128 redraw_viewing_details_meta_box();
1129 }
1130
1131 jQuery(document).ready(function($)
1132 {
1133 $(document).on('click', 'a.viewing-action', function(e)
1134 {
1135 e.preventDefault();
1136
1137 var this_href = $(this).attr('href');
1138
1139 $(this).attr('disabled', 'disabled');
1140
1141 if ( this_href == '#action_panel_viewing_carried_out' )
1142 {
1143 var data = {
1144 action: 'propertyhive_viewing_carried_out',
1145 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1146 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1147 };
1148 jQuery.post( ajaxurl, data, function(response)
1149 {
1150 redraw_viewing_actions();
1151 }, 'json');
1152 return;
1153 }
1154
1155 if ( this_href == '#action_panel_viewing_no_show' )
1156 {
1157 var data = {
1158 action: 'propertyhive_viewing_no_show',
1159 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1160 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1161 };
1162 jQuery.post( ajaxurl, data, function(response)
1163 {
1164 redraw_viewing_actions();
1165 }, 'json');
1166 return;
1167 }
1168
1169 if ( this_href == '#action_panel_viewing_email_applicant_booking_confirmation' )
1170 {
1171 var data = {
1172 action: 'propertyhive_viewing_email_applicant_booking_confirmation',
1173 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1174 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1175 };
1176 jQuery.post( ajaxurl, data, function(response)
1177 {
1178 if ( !response.success )
1179 {
1180 alert('Error: ' + response.data);
1181 }
1182 redraw_viewing_actions();
1183 }, 'json');
1184 return;
1185 }
1186
1187 if ( this_href == '#action_panel_viewing_email_owner_booking_confirmation' )
1188 {
1189 var data = {
1190 action: 'propertyhive_viewing_email_owner_booking_confirmation',
1191 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1192 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1193 };
1194 jQuery.post( ajaxurl, data, function(response)
1195 {
1196 if ( !response.success )
1197 {
1198 alert('Error: ' + response.data);
1199 }
1200 redraw_viewing_actions();
1201 }, 'json');
1202 return;
1203 }
1204
1205 if ( this_href == '#action_panel_viewing_email_attending_negotiator_booking_confirmation' )
1206 {
1207 if ( ph_viewing_negotiators_changed )
1208 {
1209 alert("The negotiators have changed since the viewing was last saved. Please save the viewing then try again");
1210 return;
1211 }
1212
1213 var data = {
1214 action: 'propertyhive_viewing_email_attending_negotiator_booking_confirmation',
1215 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1216 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1217 };
1218 jQuery.post( ajaxurl, data, function(response)
1219 {
1220 if ( !response.success )
1221 {
1222 alert('Error: ' + response.data);
1223 }
1224 redraw_viewing_actions();
1225 }, 'json');
1226 return;
1227 }
1228
1229 if ( this_href == '#action_panel_viewing_email_applicant_cancellation_notification' )
1230 {
1231 var data = {
1232 action: 'propertyhive_viewing_email_applicant_cancellation_notification',
1233 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1234 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1235 };
1236 jQuery.post( ajaxurl, data, function(response)
1237 {
1238 if ( !response.success )
1239 {
1240 alert('Error: ' + response.data);
1241 }
1242 redraw_viewing_actions();
1243 }, 'json');
1244 return;
1245 }
1246
1247 if ( this_href == '#action_panel_viewing_email_owner_cancellation_notification' )
1248 {
1249 var data = {
1250 action: 'propertyhive_viewing_email_owner_cancellation_notification',
1251 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1252 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1253 };
1254 jQuery.post( ajaxurl, data, function(response)
1255 {
1256 if ( !response.success )
1257 {
1258 alert('Error: ' + response.data);
1259 }
1260 redraw_viewing_actions();
1261 }, 'json');
1262 return;
1263 }
1264
1265 if ( this_href == '#action_panel_viewing_email_attending_negotiator_cancellation_notification' )
1266 {
1267 if ( ph_viewing_negotiators_changed )
1268 {
1269 alert("The negotiators have changed since the viewing was last saved. Please save the viewing then try again");
1270 return;
1271 }
1272
1273 var data = {
1274 action: 'propertyhive_viewing_email_attending_negotiator_cancellation_notification',
1275 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1276 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1277 };
1278 jQuery.post( ajaxurl, data, function(response)
1279 {
1280 if ( !response.success )
1281 {
1282 alert('Error: ' + response.data);
1283 }
1284 redraw_viewing_actions();
1285 }, 'json');
1286 return;
1287 }
1288
1289 if ( this_href == '#action_panel_viewing_feedback_not_required' )
1290 {
1291 var data = {
1292 action: 'propertyhive_viewing_feedback_not_required',
1293 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1294 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1295 };
1296 jQuery.post( ajaxurl, data, function(response)
1297 {
1298 redraw_viewing_actions();
1299 }, 'json');
1300 return;
1301 }
1302
1303 if ( this_href == '#action_panel_viewing_revert_feedback_passed_on' )
1304 {
1305 var data = {
1306 action: 'propertyhive_viewing_feedback_passed_on',
1307 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1308 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1309 };
1310 jQuery.post( ajaxurl, data, function(response)
1311 {
1312 redraw_viewing_actions();
1313 }, 'json');
1314 return;
1315 }
1316
1317 if ( this_href == '#action_panel_viewing_revert_pending' )
1318 {
1319 var data = {
1320 action: 'propertyhive_viewing_revert_pending',
1321 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1322 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1323 };
1324 jQuery.post( ajaxurl, data, function(response)
1325 {
1326 redraw_viewing_actions();
1327 }, 'json');
1328 return;
1329 }
1330
1331 if ( this_href == '#action_panel_viewing_revert_feedback_pending' )
1332 {
1333 var data = {
1334 action: 'propertyhive_viewing_revert_feedback_pending',
1335 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1336 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1337 };
1338 jQuery.post( ajaxurl, data, function(response)
1339 {
1340 redraw_viewing_actions();
1341 }, 'json');
1342 return;
1343 }
1344
1345 $('#propertyhive_viewing_actions_meta_box').stop().fadeOut(300, function()
1346 {
1347 $(this_href).stop().fadeIn(300, function()
1348 {
1349
1350 });
1351 });
1352 });
1353
1354 $(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.action-cancel', function(e)
1355 {
1356 e.preventDefault();
1357
1358 redraw_viewing_actions();
1359 });
1360
1361 $(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.owner-booking-confirmation-action-submit', function(e)
1362 {
1363 e.preventDefault();
1364
1365 var ph_action_button = $(this);
1366 ph_action_button.attr('disabled', 'disabled');
1367
1368 // Create FormData object and append data
1369 var form_data = new FormData();
1370 form_data.append('action', 'propertyhive_viewing_email_owner_booking_confirmation');
1371 form_data.append('viewing_id', ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ));
1372 form_data.append('subject', $('#_owner_confirmation_email_subject').val());
1373 form_data.append('body', $('#_owner_confirmation_email_body').val());
1374 form_data.append('security', propertyhive_admin_meta_boxes.viewing_actions_nonce);
1375
1376 // Get the file input element and the selected files
1377 var file_input = $('#_owner_confirmation_email_attachment');
1378 var files = file_input.prop('files');
1379
1380 // Check if at least one file has been selected
1381 if (files.length !== 0)
1382 {
1383 // Append each file to the FormData object
1384 $.each(files, function(index, file)
1385 {
1386 form_data.append('attachments[]', file);
1387 });
1388 }
1389
1390 $.ajax({
1391 url: ajaxurl, // WordPress AJAX URL
1392 type: 'POST',
1393 data: form_data,
1394 contentType: false,
1395 processData: false,
1396 dataType: 'json', // Expect JSON response
1397 success: function(response)
1398 {
1399 if (response.success)
1400 {
1401 redraw_viewing_actions();
1402 }
1403 else
1404 {
1405 alert('Error: ' + response.data);
1406 ph_action_button.attr('disabled', false);
1407 }
1408 },
1409 error: function(jqXHR, textStatus, errorThrown) {
1410 console.log('AJAX error: ' + textStatus + ' : ' + errorThrown);
1411 alert('An unexpected error occurred: ' + textStatus + ' : ' + errorThrown);
1412 }
1413 });
1414 return;
1415 });
1416
1417 $(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.applicant-booking-confirmation-action-submit', function(e)
1418 {
1419 e.preventDefault();
1420
1421 var ph_action_button = $(this);
1422 ph_action_button.attr('disabled', 'disabled');
1423
1424 // Create FormData object and append data
1425 var form_data = new FormData();
1426 form_data.append('action', 'propertyhive_viewing_email_applicant_booking_confirmation');
1427 form_data.append('viewing_id', ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ));
1428 form_data.append('subject', $('#_applicant_confirmation_email_subject').val());
1429 form_data.append('body', $('#_applicant_confirmation_email_body').val());
1430 form_data.append('security', propertyhive_admin_meta_boxes.viewing_actions_nonce);
1431
1432 // Get the file input element and the selected files
1433 var file_input = $('#_applicant_confirmation_email_attachment');
1434 var files = file_input.prop('files');
1435
1436 // Check if at least one file has been selected
1437 if (files.length !== 0)
1438 {
1439 // Append each file to the FormData object
1440 $.each(files, function(index, file)
1441 {
1442 form_data.append('attachments[]', file);
1443 });
1444 }
1445
1446 $.ajax({
1447 url: ajaxurl, // WordPress AJAX URL
1448 type: 'POST',
1449 data: form_data,
1450 contentType: false,
1451 processData: false,
1452 dataType: 'json', // Expect JSON response
1453 success: function(response)
1454 {
1455 if (response.success)
1456 {
1457 redraw_viewing_actions();
1458 }
1459 else
1460 {
1461 alert('Error: ' + response.data);
1462 ph_action_button.attr('disabled', false);
1463 }
1464 },
1465 error: function(jqXHR, textStatus, errorThrown) {
1466 console.log('AJAX error: ' + textStatus + ' : ' + errorThrown);
1467 alert('An unexpected error occurred: ' + textStatus + ' : ' + errorThrown);
1468 }
1469 });
1470 return;
1471 });
1472
1473 $(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.attending-negotiator-booking-confirmation-action-submit', function(e)
1474 {
1475 e.preventDefault();
1476
1477 var ph_action_button = $(this);
1478 ph_action_button.attr('disabled', 'disabled');
1479
1480 // Create FormData object and append data
1481 var form_data = new FormData();
1482 form_data.append('action', 'propertyhive_viewing_email_attending_negotiator_booking_confirmation');
1483 form_data.append('viewing_id', ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ));
1484 form_data.append('subject', $('#_attending_negotiator_confirmation_email_subject').val());
1485 form_data.append('body', $('#_attending_negotiator_confirmation_email_body').val());
1486 form_data.append('security', propertyhive_admin_meta_boxes.viewing_actions_nonce);
1487
1488 // Get the file input element and the selected files
1489 var file_input = $('#_attending_negotiator_confirmation_email_attachment');
1490 var files = file_input.prop('files');
1491
1492 // Check if at least one file has been selected
1493 if (files.length !== 0)
1494 {
1495 // Append each file to the FormData object
1496 $.each(files, function(index, file)
1497 {
1498 form_data.append('attachments[]', file);
1499 });
1500 }
1501
1502 $.ajax({
1503 url: ajaxurl, // WordPress AJAX URL
1504 type: 'POST',
1505 data: form_data,
1506 contentType: false,
1507 processData: false,
1508 dataType: 'json', // Expect JSON response
1509 success: function(response)
1510 {
1511 if (response.success)
1512 {
1513 redraw_viewing_actions();
1514 }
1515 else
1516 {
1517 alert('Error: ' + response.data);
1518 ph_action_button.attr('disabled', false);
1519 }
1520 },
1521 error: function(jqXHR, textStatus, errorThrown) {
1522 console.log('AJAX error: ' + textStatus + ' : ' + errorThrown);
1523 alert('An unexpected error occurred: ' + textStatus + ' : ' + errorThrown);
1524 }
1525 });
1526
1527 return;
1528 });
1529
1530 $(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.owner-cancellation-notification-action-submit', function(e)
1531 {
1532 e.preventDefault();
1533
1534 var ph_action_button = $(this);
1535 ph_action_button.attr('disabled', 'disabled');
1536
1537 // Create FormData object and append data
1538 var form_data = new FormData();
1539 form_data.append('action', 'propertyhive_viewing_email_owner_cancellation_notification');
1540 form_data.append('viewing_id', ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ));
1541 form_data.append('subject', $('#_owner_cancellation_notification_email_subject').val());
1542 form_data.append('body', $('#_owner_cancellation_notification_email_body').val());
1543 form_data.append('security', propertyhive_admin_meta_boxes.viewing_actions_nonce);
1544
1545 // Get the file input element and the selected files
1546 var file_input = $('#_owner_cancellation_notification_email_attachment');
1547 var files = file_input.prop('files');
1548
1549 // Check if at least one file has been selected
1550 if (files.length !== 0)
1551 {
1552 // Append each file to the FormData object
1553 $.each(files, function(index, file)
1554 {
1555 form_data.append('attachments[]', file);
1556 });
1557 }
1558
1559 $.ajax({
1560 url: ajaxurl, // WordPress AJAX URL
1561 type: 'POST',
1562 data: form_data,
1563 contentType: false,
1564 processData: false,
1565 dataType: 'json', // Expect JSON response
1566 success: function(response)
1567 {
1568 if (response.success)
1569 {
1570 redraw_viewing_actions();
1571 }
1572 else
1573 {
1574 alert('Error: ' + response.data);
1575 ph_action_button.attr('disabled', false);
1576 }
1577 },
1578 error: function(jqXHR, textStatus, errorThrown) {
1579 console.log('AJAX error: ' + textStatus + ' : ' + errorThrown);
1580 alert('An unexpected error occurred: ' + textStatus + ' : ' + errorThrown);
1581 }
1582 });
1583 return;
1584 });
1585
1586 $(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.applicant-cancellation-notification-action-submit', function(e)
1587 {
1588 e.preventDefault();
1589
1590 var ph_action_button = $(this);
1591 ph_action_button.attr('disabled', 'disabled');
1592
1593 // Create FormData object and append data
1594 var form_data = new FormData();
1595 form_data.append('action', 'propertyhive_viewing_email_applicant_cancellation_notification');
1596 form_data.append('viewing_id', ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ));
1597 form_data.append('subject', $('#_applicant_cancellation_notification_email_subject').val());
1598 form_data.append('body', $('#_applicant_cancellation_notification_email_body').val());
1599 form_data.append('security', propertyhive_admin_meta_boxes.viewing_actions_nonce);
1600
1601 // Get the file input element and the selected files
1602 var file_input = $('#_applicant_cancellation_notification_email_attachment');
1603 var files = file_input.prop('files');
1604
1605 // Check if at least one file has been selected
1606 if (files.length !== 0)
1607 {
1608 // Append each file to the FormData object
1609 $.each(files, function(index, file)
1610 {
1611 form_data.append('attachments[]', file);
1612 });
1613 }
1614
1615 $.ajax({
1616 url: ajaxurl, // WordPress AJAX URL
1617 type: 'POST',
1618 data: form_data,
1619 contentType: false,
1620 processData: false,
1621 dataType: 'json', // Expect JSON response
1622 success: function(response)
1623 {
1624 if (response.success)
1625 {
1626 redraw_viewing_actions();
1627 }
1628 else
1629 {
1630 alert('Error: ' + response.data);
1631 ph_action_button.attr('disabled', false);
1632 }
1633 },
1634 error: function(jqXHR, textStatus, errorThrown) {
1635 console.log('AJAX error: ' + textStatus + ' : ' + errorThrown);
1636 alert('An unexpected error occurred: ' + textStatus + ' : ' + errorThrown);
1637 }
1638 });
1639 return;
1640 });
1641
1642 $(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.attending-negotiator-cancellation-notification-action-submit', function(e)
1643 {
1644 e.preventDefault();
1645
1646 var ph_action_button = $(this);
1647 ph_action_button.attr('disabled', 'disabled');
1648
1649 // Create FormData object and append data
1650 var form_data = new FormData();
1651 form_data.append('action', 'propertyhive_viewing_email_attending_negotiator_cancellation_notification');
1652 form_data.append('viewing_id', ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ));
1653 form_data.append('subject', $('#_attending_negotiator_cancellation_notification_email_subject').val());
1654 form_data.append('body', $('#_attending_negotiator_cancellation_notification_email_body').val());
1655 form_data.append('security', propertyhive_admin_meta_boxes.viewing_actions_nonce);
1656
1657 // Get the file input element and the selected files
1658 var file_input = $('#_attending_negotiator_cancellation_notification_email_attachment');
1659 var files = file_input.prop('files');
1660
1661 // Check if at least one file has been selected
1662 if (files.length !== 0)
1663 {
1664 // Append each file to the FormData object
1665 $.each(files, function(index, file)
1666 {
1667 form_data.append('attachments[]', file);
1668 });
1669 }
1670
1671 $.ajax({
1672 url: ajaxurl, // WordPress AJAX URL
1673 type: 'POST',
1674 data: form_data,
1675 contentType: false,
1676 processData: false,
1677 dataType: 'json', // Expect JSON response
1678 success: function(response)
1679 {
1680 if (response.success)
1681 {
1682 redraw_viewing_actions();
1683 }
1684 else
1685 {
1686 alert('Error: ' + response.data);
1687 ph_action_button.attr('disabled', false);
1688 }
1689 },
1690 error: function(jqXHR, textStatus, errorThrown) {
1691 console.log('AJAX error: ' + textStatus + ' : ' + errorThrown);
1692 alert('An unexpected error occurred: ' + textStatus + ' : ' + errorThrown);
1693 }
1694 });
1695
1696 return;
1697 });
1698
1699
1700 $(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.cancelled-reason-action-submit', function(e)
1701 {
1702 e.preventDefault();
1703
1704 $(this).attr('disabled', 'disabled');
1705
1706 // Submit interested feedback
1707 var data = {
1708 action: 'propertyhive_viewing_cancelled',
1709 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1710 cancelled_reason: $('#_cancelled_reason').val(),
1711 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1712 };
1713
1714 if ($('#_cancelled_reason_public').is(':checked'))
1715 {
1716 data.cancelled_reason_public = $('#_cancelled_reason_public').val();
1717 }
1718
1719 jQuery.post( ajaxurl, data, function(response)
1720 {
1721 redraw_viewing_actions();
1722 }, 'json');
1723 });
1724
1725 $(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.interested-feedback-action-submit', function(e)
1726 {
1727 e.preventDefault();
1728
1729 $(this).attr('disabled', 'disabled');
1730
1731 // Submit interested feedback
1732 var data = {
1733 action: 'propertyhive_viewing_interested_feedback',
1734 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1735 feedback: $('#_interested_feedback').val(),
1736 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1737 };
1738
1739 jQuery.post( ajaxurl, data, function(response)
1740 {
1741 redraw_viewing_actions();
1742 }, 'json');
1743 });
1744
1745 $(document).on('click', '#propertyhive_viewing_actions_meta_box_container a.not-interested-feedback-action-submit', function(e)
1746 {
1747 e.preventDefault();
1748
1749 $(this).attr('disabled', 'disabled');
1750
1751 // Submit interested feedback
1752 var data = {
1753 action: 'propertyhive_viewing_not_interested_feedback',
1754 viewing_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1755 feedback: $('#_not_interested_feedback').val(),
1756 security: propertyhive_admin_meta_boxes.viewing_actions_nonce,
1757 };
1758
1759 jQuery.post( ajaxurl, data, function(response)
1760 {
1761 redraw_viewing_actions();
1762 }, 'json');
1763 })
1764 });
1765
1766 function ph_redraw_notes_grid(section)
1767 {
1768 var data = {
1769 action: 'propertyhive_get_notes_grid',
1770 post_id: ( ph_lightbox_open ? ph_lightbox_post_id : propertyhive_admin_meta_boxes.post_id ),
1771 section: section,
1772 security: propertyhive_admin_meta_boxes.get_notes_nonce
1773 };
1774
1775 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
1776 {
1777 if ( propertyhive_admin_meta_boxes.disable_notes_mention != true )
1778 {
1779 tinymce.remove('.propertyhive-lightbox-notes textarea#add_note');
1780 tinymce.remove('#propertyhive-' + section + '-history-notes textarea#add_note');
1781 }
1782
1783 jQuery('#propertyhive_' + section + '_notes_container').html(response);
1784
1785 if ( propertyhive_admin_meta_boxes.disable_notes_mention != true )
1786 {
1787 tinymce.init({
1788 selector: ( ph_lightbox_open ? '.propertyhive-lightbox-notes' : '#propertyhive-' + section + '-history-notes' ) + ' textarea#add_note',
1789 menubar: false,
1790 toolbar: false,
1791 statusbar: false,
1792 forced_root_block: '', // Disable the <p> tags
1793 force_br_newlines: true,
1794 force_p_newlines: false,
1795 external_plugins:
1796 {
1797 'mention' : propertyhive_admin_meta_boxes.plugin_url + '/assets/js/tinymce-mention-plugin/tinymce-mention-plugin.js',
1798 'placeholder' : propertyhive_admin_meta_boxes.plugin_url + '/assets/js/tinymce-placeholder/mce.placeholder.js'
1799 },
1800 setup: function(editor)
1801 {
1802 editor.on('init', function()
1803 {
1804 editor.getContainer().style.border = '1px solid #ccc';
1805 });
1806 },
1807 mentions:
1808 {
1809 source: function (query, process, delimiter)
1810 {
1811 // Do your ajax call
1812 jQuery.ajax({
1813 url: ajaxurl, // Use WordPress AJAX URL
1814 method: 'POST',
1815 data: {
1816 action: 'propertyhive_fetch_note_mentions',
1817 query: query,
1818 security: propertyhive_admin_meta_boxes.get_notes_nonce
1819 },
1820 success: function(response) {
1821 process(response);
1822 }
1823 });
1824 }
1825 },
1826 content_style: `
1827 html, body {
1828 height: 100%; /* Set both html and body to 100% height */
1829 margin: 0;
1830 padding: 0;
1831 overflow: hidden; /* Prevent scrolling issues */
1832 }
1833 .mce-content-body {
1834 margin: 0; /* Replace margin with padding */
1835 padding: 1rem; /* Add padding */
1836 box-sizing: border-box; /* Include padding in height calculation */
1837 height: 100%;
1838 overflow-y: auto; /* Allow vertical scrolling within the body */
1839 }
1840 `
1841 });
1842 }
1843 }, 'html');
1844 }
1845
1846 function ph_redraw_pinned_notes_grid(section)
1847 {
1848 var data = {
1849 action: 'propertyhive_get_pinned_notes_grid',
1850 post_id: propertyhive_admin_meta_boxes.post_id,
1851 pinned: 1,
1852 section: section,
1853 security: propertyhive_admin_meta_boxes.get_notes_nonce
1854 };
1855
1856 jQuery.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response)
1857 {
1858 jQuery('#propertyhive_' + section + '_pinned_notes_container').html(response);
1859 }, 'html');
1860 }
1861
1862 function initialise_datepicker() {
1863 jQuery( ".date-picker" ).datepicker({
1864 dateFormat: "yy-mm-dd",
1865 numberOfMonths: 1,
1866 showButtonPanel: true
1867 }).on("change", function(e) {
1868 var curDate = jQuery(this).val();
1869 var valid = true;
1870
1871 if ( curDate != '' )
1872 {
1873 var splitDate = curDate.split("-")
1874 if ( splitDate.length != 3 )
1875 {
1876 valid = false;
1877 }
1878 else
1879 {
1880 if ( splitDate[0].length != 4 || splitDate[1].length != 2 || splitDate[2].length != 2 )
1881 {
1882 valid = false;
1883 }
1884 }
1885
1886 if (!valid)
1887 {
1888 alert("Invalid date entered. Please select a date from the calendar and ensure date is in the format YYYY-MM-DD");
1889 }
1890 }
1891 });
1892 }
1893
1894 function add_months(date, months) {
1895 var d = date.getDate();
1896 date.setMonth(date.getMonth() + +months);
1897 if (date.getDate() != d)
1898 {
1899 date.setDate(0);
1900 }
1901 return date;
1902 }
1903