// Availability table function abcFormatDate(date) { var d = new Date(date), month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear(); if (month.length < 2) month = '0' + month; if (day.length < 2) day = '0' + day; return [year, month, day].join('-'); } function abcTriggerButtons(trigger){ jQuery('.abc-availability-table-button-right').attr('disabled',trigger); jQuery('.abc-availability-table-button-left').attr('disabled',trigger); jQuery('.abcMonthWrapper').attr('disabled',trigger); jQuery('.abcYearWrapper').attr('disabled',trigger); } jQuery('.abc-availability-table-button-right').live('click', function(){ var startdate = new Date(+new Date(jQuery(this).data('startdate')) + 12096e5); // + 14 days abcTriggerButtons(true); data = { action: 'abc_booking_getAvailabilityTable', abc_bookings_nonce: ajax_abc_bookings.abc_bookings_nonce, startdate: abcFormatDate(startdate) }; jQuery.post(ajax_abc_bookings.ajaxurl, data, function (response){ jQuery('#abc_AvailabilityTable').html(response); abcTriggerButtons(false); }); return false; }); jQuery('.abc-availability-table-button-left').live('click', function(){ var startdate = new Date(+new Date(jQuery(this).data('startdate')) - 12096e5); // - 14 days abcTriggerButtons(true); data = { action: 'abc_booking_getAvailabilityTable', abc_bookings_nonce: ajax_abc_bookings.abc_bookings_nonce, startdate: abcFormatDate(startdate) }; jQuery.post(ajax_abc_bookings.ajaxurl, data, function (response){ jQuery('#abc_AvailabilityTable').html(response); abcTriggerButtons(false); }); return false; }); jQuery('.abcMonthSelector').live('click', function(){ var startdate = jQuery(this).data('startdate'); abcTriggerButtons(true); data = { action: 'abc_booking_getAvailabilityTable', abc_bookings_nonce: ajax_abc_bookings.abc_bookings_nonce, startdate: startdate }; jQuery.post(ajax_abc_bookings.ajaxurl, data, function (response){ jQuery('#abc_AvailabilityTable').html(response); abcTriggerButtons(false); }); return false; }); jQuery('.abcYearSelector').live('click', function(){ var startdate = jQuery(this).data('startdate'); abcTriggerButtons(true); data = { action: 'abc_booking_getAvailabilityTable', abc_bookings_nonce: ajax_abc_bookings.abc_bookings_nonce, startdate: startdate }; jQuery.post(ajax_abc_bookings.ajaxurl, data, function (response){ jQuery('#abc_AvailabilityTable').html(response); abcTriggerButtons(false); }); return false; }); // Search function jQuery('#abcBookingSearchButton').live('click', function(){ jQuery('#abcBookingSearchText').attr('disabled',true); jQuery('#abcBookingSearchButton').attr('disabled',true); var search = jQuery( "#abcBookingSearchText").val(); data = { action: 'abc_booking_getSearchResults', abc_bookings_nonce: ajax_abc_bookings.abc_bookings_nonce, search: search }; jQuery.post(ajax_abc_bookings.ajaxurl, data, function (response){ jQuery('#abcBookingSearchResult').html(response); jQuery('#abcBookingSearchText').attr('disabled',false); jQuery('#abcBookingSearchButton').attr('disabled',false); }); return false; }); // Booking form jQuery( "#calendar_id").on('change', function () { abc_checkDates(); }); jQuery( "#end").on('change', function () { abc_checkDates(); }); jQuery( "#start").on('change', function () { abc_checkDates(); }); jQuery( "select[name='calendar_id']").on('change', function () { jQuery('#persons').attr('disabled',true); var calId = jQuery( "select[name='calendar_id']").val(); data = { action: 'abc_booking_getPersonList', abc_bookings_nonce: ajax_abc_bookings.abc_bookings_nonce, calId: calId }; jQuery.post(ajax_abc_bookings.ajaxurl, data, function (response){ jQuery('#persons').html(jQuery(response)); jQuery('#persons').attr('disabled',false); }); return false; }); jQuery(document).on('click', '#postAbcBooking', function(){ jQuery('#abc-booking-form').validate({ rules: { email: { required: { depends: function(element) { return jQuery("#radio-yes").is(":checked"); } }, email: { depends: function(element) { return jQuery("#radio-yes").is(":checked"); } } } }, submitHandler: function (form) { form.submit(); } }); }); function abc_checkDates() { if( jQuery("#start").val() && jQuery("#end").val() && jQuery( "select[name='calendar_id']").val() ){ jQuery('#abc_dateStatus').html('Loading...'); var calId = jQuery( "select[name='calendar_id']").val(); var from = jQuery( "#start").val(); var to = jQuery( "#end").val(); var persons = jQuery( "#persons").val(); data = { action: 'abc_booking_checkDates', abc_bookings_nonce: ajax_abc_bookings.abc_bookings_nonce, from: from, to: to, calId: calId }; jQuery.post(ajax_abc_bookings.ajaxurl, data, function (response){ jQuery('#abc_dateStatus').html(response); }); return false; } } // Pagination for overview jQuery('[data-uk-pagination]').on('select.uk.pagination', function(e, pageIndex){ var itemsOnPage = jQuery(this).data('abc-itemsonpage'); var offset = (pageIndex)*itemsOnPage; var divid = '#' + jQuery(this).data('abc-divid'); jQuery(divid).fadeOut('medium'); data = { action: 'abc_booking_getBookingContent', abc_bookings_nonce: ajax_abc_bookings.abc_bookings_nonce, state: jQuery(this).data('abc-state'), offset: offset, itemsOnPage: itemsOnPage }; jQuery.post(ajax_abc_bookings.ajaxurl, data, function (response){ jQuery(divid).html(jQuery(response)); jQuery(divid).fadeIn('fast'); }); return false; }); jQuery( document ).ready(function() { if(ajax_abc_bookings.nlAsked){ UIkit.modal.prompt( ajax_abc_bookings.nlText, ajax_abc_bookings.nlEmail, function(val){ data = { action: 'abc_setAbcNewsletter', abc_bookings_nonce: ajax_abc_bookings.abc_bookings_nonce, email: val }; jQuery.post(ajax_abc_bookings.ajaxurl, data, function (response){}); }); } });