| 1 |
jQuery( function($){ |
| 2 |
|
| 3 |
$('.propertyhive_meta_box #property_rooms').sortable({ |
| 4 |
opacity: 0.8, |
| 5 |
revert: true, |
| 6 |
handle: 'h3' |
| 7 |
}); |
| 8 |
|
| 9 |
$('.propertyhive_meta_box #property_features').sortable({ |
| 10 |
opacity: 0.8, |
| 11 |
revert: true, |
| 12 |
handle: 'label' |
| 13 |
}); |
| 14 |
|
| 15 |
$('.propertyhive_meta_box #property_photo_urls').sortable({ |
| 16 |
opacity: 0.8, |
| 17 |
revert: true, |
| 18 |
handle: 'label' |
| 19 |
}); |
| 20 |
|
| 21 |
$('.propertyhive_meta_box #property_floorplan_urls').sortable({ |
| 22 |
opacity: 0.8, |
| 23 |
revert: true, |
| 24 |
handle: 'label' |
| 25 |
}); |
| 26 |
|
| 27 |
$('.propertyhive_meta_box #property_brochure_urls').sortable({ |
| 28 |
opacity: 0.8, |
| 29 |
revert: true, |
| 30 |
handle: 'label' |
| 31 |
}); |
| 32 |
|
| 33 |
$('.propertyhive_meta_box #property_epc_urls').sortable({ |
| 34 |
opacity: 0.8, |
| 35 |
revert: true, |
| 36 |
handle: 'label' |
| 37 |
}); |
| 38 |
|
| 39 |
$('.propertyhive_meta_box #property_virtual_tours').sortable({ |
| 40 |
opacity: 0.8, |
| 41 |
revert: true, |
| 42 |
handle: 'label' |
| 43 |
}); |
| 44 |
|
| 45 |
initialise_datepicker(); |
| 46 |
|
| 47 |
// TABS |
| 48 |
$('ul.ph-tabs').show(); |
| 49 |
$('div.panel-wrap').each(function(){ |
| 50 |
$(this).find('div.panel:not(:first)').hide(); |
| 51 |
}); |
| 52 |
$('ul.ph-tabs a').click(function(){ |
| 53 |
var panel_wrap = $(this).closest('div.panel-wrap'); |
| 54 |
$('ul.ph-tabs li', panel_wrap).removeClass('active'); |
| 55 |
$(this).parent().addClass('active'); |
| 56 |
$('div.panel', panel_wrap).hide(); |
| 57 |
$( $(this).attr('href') ).show(); |
| 58 |
return false; |
| 59 |
}); |
| 60 |
$('ul.ph-tabs li:visible').eq(0).find('a').click(); |
| 61 |
|
| 62 |
// Notes |
| 63 |
//$('#propertyhive-property-notes, #propertyhive-contact-notes, #propertyhive-enquiry-notes, #propertyhive-viewing-notes, #propertyhive-offer-notes, #propertyhive-sale-notes').on( 'click', 'a.add_note', function() { |
| 64 |
$('[id^=\'propertyhive-\'][id$=\'-notes\']').on( 'click', 'a.add_note', function() { |
| 65 |
if ( ! $('textarea#add_note').val() ) return; |
| 66 |
|
| 67 |
var data = { |
| 68 |
action: 'propertyhive_add_note', |
| 69 |
post_id: propertyhive_admin_meta_boxes.post_id, |
| 70 |
note: $('textarea#add_note').val(), |
| 71 |
note_type: 'propertyhive_note', |
| 72 |
security: propertyhive_admin_meta_boxes.add_note_nonce, |
| 73 |
}; |
| 74 |
|
| 75 |
$.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) { |
| 76 |
$('ul.record_notes').prepend( response ); |
| 77 |
$('li#no_notes').hide(); |
| 78 |
$('#add_note').val(''); |
| 79 |
}); |
| 80 |
|
| 81 |
return false; |
| 82 |
|
| 83 |
}); |
| 84 |
|
| 85 |
$('[id^=\'propertyhive-\'][id$=\'-notes\']').on( 'click', 'a.delete_note', function() { |
| 86 |
|
| 87 |
var confirm_box = confirm('Are you sure you wish to delete this note?'); |
| 88 |
if (!confirm_box) |
| 89 |
{ |
| 90 |
return false; |
| 91 |
} |
| 92 |
|
| 93 |
var note = $(this).closest('li.note'); |
| 94 |
|
| 95 |
var data = { |
| 96 |
action: 'propertyhive_delete_note', |
| 97 |
note_id: $(note).attr('rel'), |
| 98 |
security: propertyhive_admin_meta_boxes.delete_note_nonce, |
| 99 |
}; |
| 100 |
|
| 101 |
$.post( propertyhive_admin_meta_boxes.ajax_url, data, function(response) { |
| 102 |
$(note).remove(); |
| 103 |
|
| 104 |
if ($('ul.record_notes li').length <= 1) |
| 105 |
{ |
| 106 |
$('li#no_notes').show(); |
| 107 |
} |
| 108 |
}); |
| 109 |
|
| 110 |
return false; |
| 111 |
}); |
| 112 |
|
| 113 |
// Multiselect |
| 114 |
$(".propertyhive_meta_box select.multiselect").chosen(); |
| 115 |
|
| 116 |
}); |
| 117 |
|
| 118 |
function initialise_datepicker() { |
| 119 |
jQuery( ".date-picker" ).datepicker({ |
| 120 |
dateFormat: "yy-mm-dd", |
| 121 |
numberOfMonths: 1, |
| 122 |
showButtonPanel: true |
| 123 |
}).on("change", function(e) { |
| 124 |
var curDate = jQuery(this).val(); |
| 125 |
var valid = true; |
| 126 |
|
| 127 |
if ( curDate != '' ) |
| 128 |
{ |
| 129 |
var splitDate = curDate.split("-") |
| 130 |
if ( splitDate.length != 3 ) |
| 131 |
{ |
| 132 |
valid = false; |
| 133 |
} |
| 134 |
else |
| 135 |
{ |
| 136 |
if ( splitDate[0].length != 4 || splitDate[1].length != 2 || splitDate[2].length != 2 ) |
| 137 |
{ |
| 138 |
valid = false; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
if (!valid) |
| 143 |
{ |
| 144 |
alert("Invalid date entered. Please select a date from the calendar and ensure date is in the format YYYY-MM-DD"); |
| 145 |
} |
| 146 |
} |
| 147 |
}); |
| 148 |
} |
| 149 |
|