Hotel Raxa - Advanced Booking System Implementation
🏨 Hotel Booking Enhancements: - Implemented Eagle Booking Advanced Pricing add-on - Added Booking.com-style rate management system - Created professional calendar interface for pricing - Integrated deals and discounts functionality 💰 Advanced Pricing Features: - Dynamic pricing models (per room, per person, per adult) - Base rates, adult rates, and child rates management - Length of stay discounts and early bird deals - Mobile rates and secret deals implementation - Seasonal promotions and flash sales 📅 Availability Management: - Real-time availability tracking - Stop sell and restriction controls - Closed to arrival/departure functionality - Minimum/maximum stay requirements - Automatic sold-out management 💳 Payment Integration: - Maintained Redsys payment gateway integration - Seamless integration with existing Eagle Booking - No modifications to core Eagle Booking plugin 🛠️ Technical Implementation: - Custom database tables for advanced pricing - WordPress hooks and filters integration - AJAX-powered admin interface - Data migration from existing Eagle Booking - Professional calendar view for revenue management 📊 Admin Interface: - Booking.com-style management dashboard - Visual rate and availability calendar - Bulk operations for date ranges - Statistics and analytics dashboard - Modal dialogs for quick editing 🔧 Code Quality: - WordPress coding standards compliance - Secure database operations with prepared statements - Proper input validation and sanitization - Error handling and logging - Responsive admin interface 🤖 Generated with Claude Code (https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
452
wp-content/plugins/eagle-booking/assets/js/admin/bookings.js
Normal file
452
wp-content/plugins/eagle-booking/assets/js/admin/bookings.js
Normal file
@@ -0,0 +1,452 @@
|
||||
(function ($) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Button Animation
|
||||
* Version: 1.0
|
||||
* Can be called externally
|
||||
*/
|
||||
function eb_button_loading( btn_id, btn_action = '' ) {
|
||||
|
||||
var btn = $( btn_id );
|
||||
|
||||
if ( btn_action === 'hide' ) {
|
||||
|
||||
btn.find('.eb-btn-loader').remove();
|
||||
btn.find('.eb-btn-text').show();
|
||||
btn.css('pointer-events','');
|
||||
btn.blur();
|
||||
|
||||
} else {
|
||||
|
||||
var eb_loader_dom = '<span class="eb-btn-loader"><span class="eb-spinner spinner1"></span><span class="eb-spinner spinner2"></span><span class="eb-spinner spinner3"></span><span class="eb-spinner spinner4"></span><span class="eb-spinner spinner5"></span></span>';
|
||||
|
||||
btn.append( eb_loader_dom );
|
||||
btn.find('.eb-btn-text').hide();
|
||||
btn.css('pointer-events','none');
|
||||
|
||||
}
|
||||
|
||||
// Firefox fix: on "Go Back"
|
||||
$(window).unload(function () { $(window).unbind('unload'); });
|
||||
|
||||
}
|
||||
|
||||
/* Document is Raedy */
|
||||
$(document).ready(function () {
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Open Delete Confirmation [Admin]
|
||||
/*----------------------------------------------------*/
|
||||
|
||||
$(document).on('click', '.eb-delete-booking, #eb_delete_booking', function(event) {
|
||||
|
||||
event.preventDefault(event);
|
||||
event.stopPropagation(event);
|
||||
|
||||
var eb_popup = $('.eb-popup');
|
||||
|
||||
eb_popup.addClass('open');
|
||||
var booking_line = $(this).closest( "tr" );
|
||||
|
||||
var booking_id = booking_line.data('booking-id');
|
||||
|
||||
$('#eb_booking_id_text').text(booking_id);
|
||||
$('#eb_delete_booking_confirmation').data('booking-id', booking_id);
|
||||
|
||||
// Close PopUp
|
||||
$(".eb-close-popup").on('click', function() {
|
||||
$('.eb-popup').removeClass('open');
|
||||
});
|
||||
|
||||
// Cose on click outside of the popup
|
||||
$(window).on('click', function() {
|
||||
eb_popup.removeClass('open');
|
||||
});
|
||||
|
||||
// Avoid Close on inner click
|
||||
$(".eb-popup-inner").on('click', function(event) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Delete Booking [Admin]
|
||||
/*----------------------------------------------------*/
|
||||
|
||||
$('#eb_delete_booking_confirmation').on('click', function(event) {
|
||||
|
||||
eb_button_loading(this);
|
||||
|
||||
event.preventDefault(event);
|
||||
|
||||
var eb_popup = $('.eb-popup');
|
||||
var booking_id = $(this).data('booking-id');
|
||||
var booking_line = $('*[data-booking-id='+booking_id+']');
|
||||
|
||||
// Handler to the ajax request
|
||||
var eb_delete_booking = null;
|
||||
|
||||
// If there is a previous ajax request, then abort it
|
||||
if( eb_delete_booking != null ) {
|
||||
eb_delete_booking.abort();
|
||||
eb_delete_booking = null;
|
||||
}
|
||||
|
||||
// Set the data
|
||||
var data = {
|
||||
action: 'admin_delete',
|
||||
nonce: booking_variables.nonce,
|
||||
booking_id: booking_id
|
||||
}
|
||||
|
||||
eb_delete_booking = $.ajax({
|
||||
type: 'POST',
|
||||
url: booking_variables.ajaxurl,
|
||||
data: data
|
||||
|
||||
})
|
||||
|
||||
// Always
|
||||
.always( function (response) { })
|
||||
|
||||
// Done
|
||||
.done( function (response) {
|
||||
|
||||
// Check if booking deleted successfully
|
||||
if ( response.status === 'success' ) {
|
||||
|
||||
// Remove Line
|
||||
booking_line.fadeOut(300);
|
||||
|
||||
// Booking details page redeirect to the booking page
|
||||
if ( $('.eb-admin-booking-details').length ) {
|
||||
setTimeout( function() {
|
||||
document.location.href = response.redirect_url;
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
var response_class = 'success';
|
||||
|
||||
} else {
|
||||
|
||||
var response_class = 'error';
|
||||
|
||||
}
|
||||
|
||||
// Close popup
|
||||
eb_popup.removeClass('open');
|
||||
|
||||
// Show notification box & and remove it after 3s
|
||||
var eb_notice = $('<div class="eb-notice eb-'+ response_class +'">'+ response.mssg +'</div>');
|
||||
|
||||
$(eb_notice).hide().appendTo("body").fadeIn(300);
|
||||
|
||||
// Remove Button Loader
|
||||
setTimeout( function() {
|
||||
eb_button_loading('#eb_delete_booking_confirmation', 'hide');
|
||||
}, 1000);
|
||||
|
||||
// Remove Notice
|
||||
setTimeout( function() {
|
||||
$('.eb-notice').fadeOut(300);
|
||||
}, 3000);
|
||||
|
||||
})
|
||||
|
||||
// Fail
|
||||
.fail( function (response) { console.log('Request Failed'); })
|
||||
|
||||
});
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Confirmation PopUp [Admin]
|
||||
/*----------------------------------------------------*/
|
||||
function eb_confirmation_popup(popup_heading, popup_text, popup_status) {
|
||||
|
||||
var eb_popup = $('.eb-popup');
|
||||
|
||||
// Open PopUp on call
|
||||
eb_popup.toggleClass('open');
|
||||
|
||||
// Set heading if set
|
||||
$('#eb_popup_heading', this).text(popup_heading);
|
||||
|
||||
// Set text if set
|
||||
$('#eb_popup_text', this).text(popup_text);
|
||||
|
||||
// Close PopUp
|
||||
$(".eb-close-popup", this).on('click', function() {
|
||||
$('.eb-popup').removeClass('open');
|
||||
});
|
||||
|
||||
// Avoid Close on inner click
|
||||
$(".eb-popup-inner", this).on('click', function(event) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
// Cose on click outside of the popup
|
||||
$(window).on('click', function() {
|
||||
eb_popup.removeClass('open');
|
||||
});
|
||||
|
||||
// New Booking
|
||||
if ( popup_status === 'available' ) {
|
||||
|
||||
$('#eb_popup_heading').prepend('<div class="eb-popup-icon success"><i class="far fa-calendar-check"></i></div>')
|
||||
|
||||
} else {
|
||||
|
||||
$('#eb_popup_heading').prepend('<div class="eb-popup-icon failed"><i class="far fa-calendar-times"></i></div>')
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/*----------------------------------------------------*/
|
||||
/* Check Availablity [Admin]
|
||||
/*----------------------------------------------------*/
|
||||
|
||||
$("#eb_check_availability").on('click', function(event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
var eb_form_has_error = false;
|
||||
|
||||
var form_field = {
|
||||
room_id: $('#eb_room_id'),
|
||||
dates: $('.eb-datepicker'),
|
||||
price: $('#eb_price'),
|
||||
firstname: $('#eb_firstname'),
|
||||
lastname: $('#eb_lastname')
|
||||
}
|
||||
|
||||
// Check if any required field is empty
|
||||
form_field.room_id.add(form_field.dates).add(form_field.firstname).add(form_field.lastname).add(form_field.price).each( function() {
|
||||
|
||||
if( !this.value ) {
|
||||
eb_form_has_error = true;
|
||||
$(this).addClass("empty");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if ( eb_form_has_error == false ) {
|
||||
|
||||
eb_button_loading(this);
|
||||
|
||||
// Handler to the ajax request
|
||||
var check_availability = null;
|
||||
|
||||
// If there is a previous ajax request, then abort it
|
||||
if( check_availability != null ) {
|
||||
check_availability.abort();
|
||||
check_availability = null;
|
||||
}
|
||||
|
||||
// Set the data
|
||||
var data = {
|
||||
action: 'admin_availability',
|
||||
nonce: booking_variables.nonce,
|
||||
room_id: form_field.room_id.val(),
|
||||
checkin: $('.eb_checkin').val(),
|
||||
checkout: $('.eb_checkout').val(),
|
||||
}
|
||||
|
||||
check_availability = $.ajax({
|
||||
type: 'POST',
|
||||
url: booking_variables.ajaxurl,
|
||||
data: data
|
||||
|
||||
})
|
||||
|
||||
.always( function (response) {})
|
||||
|
||||
.done( function (response) {
|
||||
|
||||
// Check if room is available
|
||||
if ( response.status === 'available' ) {
|
||||
|
||||
// Show Delete Button
|
||||
$('#eb_create_booking_confirmation').show();
|
||||
|
||||
} else {
|
||||
|
||||
// Hide Delete Button
|
||||
$('#eb_create_booking_confirmation').hide();
|
||||
}
|
||||
|
||||
eb_button_loading('#eb_check_availability', 'hide');
|
||||
|
||||
// Open Confirmation Box
|
||||
eb_confirmation_popup(response.heading, response.text, response.status);
|
||||
|
||||
})
|
||||
|
||||
.fail( function (response) {})
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Create Booking [Admin]
|
||||
/*----------------------------------------------------*/
|
||||
|
||||
$("#eb_create_booking_confirmation").on('click', function(event) {
|
||||
|
||||
eb_button_loading(this);
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
var eb_form_has_error = false;
|
||||
|
||||
var form_field = {
|
||||
room_id: $('#eb_room_id'),
|
||||
dates: $('#eagle_booking_datepicker'),
|
||||
adults: $('#eagle_booking_adults'),
|
||||
children: $('#eagle_booking_children'),
|
||||
guests: $('#eagle_booking_guests'),
|
||||
price: $('#eb_price'),
|
||||
deposit: $('#eb_deposit'),
|
||||
firstname: $('#eb_firstname'),
|
||||
lastname: $('#eb_lastname')
|
||||
}
|
||||
|
||||
// Check if any required field is empty
|
||||
form_field.room_id.add(form_field.dates).add(form_field.firstname).add(form_field.lastname).add(form_field.price).each( function() {
|
||||
|
||||
if( !this.value ) {
|
||||
eb_form_has_error = true;
|
||||
$(this).addClass("empty");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if ( eb_form_has_error == false ) {
|
||||
|
||||
// Handler to the ajax request
|
||||
var eb_cretate_booking = null;
|
||||
|
||||
// If there is a previous ajax request, then abort it
|
||||
if( eb_cretate_booking != null ) {
|
||||
eb_cretate_booking.abort();
|
||||
eb_cretate_booking = null;
|
||||
}
|
||||
|
||||
// Set the data
|
||||
var data = {
|
||||
action: 'admin_create',
|
||||
nonce: booking_variables.nonce,
|
||||
room_id: form_field.room_id.val(),
|
||||
checkin: $('.eb_checkin').val(),
|
||||
checkout: $('.eb_checkout').val(),
|
||||
adults: form_field.adults.val(),
|
||||
children: form_field.children.val(),
|
||||
guests: form_field.guests.val(),
|
||||
price: form_field.price.val(),
|
||||
deposit: form_field.deposit.val(),
|
||||
firstname: form_field.firstname.val(),
|
||||
lastname: form_field.lastname.val(),
|
||||
email: $('#eb_email').val(),
|
||||
phone: $('#eb_phone').val(),
|
||||
address: $('#eb_address').val(),
|
||||
city: $('#eb_city').val(),
|
||||
country: $('#eb_country').val(),
|
||||
zip: $('#eb_zip').val(),
|
||||
arrival: $('#eb_arrival').val(),
|
||||
requests: $('#eb_requests').val(),
|
||||
services: $('#eb_services').val(),
|
||||
status: $('#eb_status').val(),
|
||||
payment: $('#eb_payment_method').val(),
|
||||
|
||||
}
|
||||
|
||||
eb_cretate_booking = $.ajax({
|
||||
type: 'POST',
|
||||
url: booking_variables.ajaxurl,
|
||||
data: data
|
||||
|
||||
})
|
||||
|
||||
.always( function (response) {
|
||||
|
||||
console.log(response);
|
||||
|
||||
})
|
||||
|
||||
.done( function (response) {
|
||||
|
||||
// Check if booking deleted successfully
|
||||
if ( response.status === 'success' ) {
|
||||
|
||||
var response_class = 'success';
|
||||
|
||||
setTimeout( function() {
|
||||
document.location.href = response.redirect_url;
|
||||
|
||||
}, 3000);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
var response_class = 'error';
|
||||
|
||||
}
|
||||
|
||||
// Close PopUp Confirmation
|
||||
$('.eb-popup').toggleClass('open');
|
||||
|
||||
eb_button_loading(this, 'hide');
|
||||
|
||||
// Show notification box & and remove it after 3s
|
||||
var eb_notice = $('<div class="eb-notice eb-'+ response_class +'">'+ response.mssg +'</div>');
|
||||
|
||||
$(eb_notice).hide().appendTo("body").fadeIn(300);
|
||||
|
||||
setTimeout( function() {
|
||||
$('.eb-notice').fadeOut(300);
|
||||
}, 3000);
|
||||
|
||||
|
||||
})
|
||||
|
||||
.fail( function (response) { })
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Remove 'empty' class on focus
|
||||
/*----------------------------------------------------*/
|
||||
|
||||
$('input').on("focus", function(){
|
||||
|
||||
$(this).removeClass("empty");
|
||||
})
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Additional Services
|
||||
/*----------------------------------------------------*/
|
||||
|
||||
$( ".eb-additional-service" ).change(function() {
|
||||
|
||||
if ( $( this ).is( ":checked" ) ) {
|
||||
|
||||
var eb_service_value = $( this ).val();
|
||||
var eb_service_previous_value = $("#eb_services").val();
|
||||
$( "#eb_services" ).val( eb_service_value + eb_service_previous_value );
|
||||
|
||||
} else {
|
||||
var eb_service_value = $( this ).val();
|
||||
var eb_service_previous_value = $("#eb_services").val();
|
||||
var eb_checkbox_services = eb_service_previous_value.replace(eb_service_value, "");
|
||||
$( "#eb_services" ).val( eb_checkbox_services );
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
454
wp-content/plugins/eagle-booking/assets/js/admin/eb-admin.js
Normal file
454
wp-content/plugins/eagle-booking/assets/js/admin/eb-admin.js
Normal file
@@ -0,0 +1,454 @@
|
||||
/*================================================
|
||||
* Plugin Name: Eagle Booking
|
||||
* Version: 1.1.6
|
||||
* Author Name: Jomin Muskaj (Eagle-Themes)
|
||||
* Author URI: eagle-themes.com
|
||||
=================================================*/
|
||||
|
||||
(function ($) {
|
||||
"use strict";
|
||||
|
||||
/* Document is Raedy */
|
||||
$(document).ready(function () {
|
||||
|
||||
// =============================================
|
||||
// DATERANGEPICKER
|
||||
// =============================================
|
||||
var eb_calendar_min_date = new Date();
|
||||
var eb_calendar_max_date = moment(eb_calendar_min_date).add(eb_js_settings.eb_calendar_availability_period, 'M').endOf('month');
|
||||
var eagle_booking_date_format = eb_js_settings.eagle_booking_date_format.toUpperCase();
|
||||
|
||||
var eb_signle_room = false;
|
||||
|
||||
// Check if calendar is on single room
|
||||
if ( $('form').hasClass('room-booking-form') ) {
|
||||
|
||||
eb_signle_room = true;
|
||||
|
||||
}
|
||||
|
||||
$(".eb-datepicker").each(function () {
|
||||
|
||||
var calendar = $(this);
|
||||
|
||||
$(calendar).daterangepicker({
|
||||
autoUpdateInput: false,
|
||||
autoApply: true,
|
||||
alwaysShowCalendars: true,
|
||||
linkedCalendars: true,
|
||||
|
||||
isInvalidDate: function(date) {
|
||||
|
||||
if ( typeof eb_booked_dates!== 'undefined' && eb_booked_dates != '' ) {
|
||||
|
||||
return !!(eb_booked_dates.indexOf(date.format('YYYY/MM/DD')) > 0);
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
minDate: eb_calendar_min_date,
|
||||
maxDate: eb_calendar_max_date,
|
||||
locale: {
|
||||
format: eagle_booking_date_format,
|
||||
separator: " → ",
|
||||
"daysOfWeek": [
|
||||
eb_js_settings.eb_calendar_sunday,
|
||||
eb_js_settings.eb_calendar_monday,
|
||||
eb_js_settings.eb_calendar_tuesday,
|
||||
eb_js_settings.eb_calendar_wednesday,
|
||||
eb_js_settings.eb_calendar_thursday,
|
||||
eb_js_settings.eb_calendar_friday,
|
||||
eb_js_settings.eb_calendar_saturday,
|
||||
],
|
||||
"monthNames": [
|
||||
eb_js_settings.eb_calendar_january,
|
||||
eb_js_settings.eb_calendar_february,
|
||||
eb_js_settings.eb_calendar_march,
|
||||
eb_js_settings.eb_calendar_april,
|
||||
eb_js_settings.eb_calendar_may,
|
||||
eb_js_settings.eb_calendar_june,
|
||||
eb_js_settings.eb_calendar_july,
|
||||
eb_js_settings.eb_calendar_august,
|
||||
eb_js_settings.eb_calendar_september,
|
||||
eb_js_settings.eb_calendar_october,
|
||||
eb_js_settings.eb_calendar_november,
|
||||
eb_js_settings.eb_calendar_december,
|
||||
],
|
||||
"firstDay": 1
|
||||
}
|
||||
}),
|
||||
|
||||
$(calendar).on("apply.daterangepicker", function () {
|
||||
|
||||
// Displayd Format
|
||||
var checkin = $(calendar).data('daterangepicker').startDate.format(eagle_booking_date_format);
|
||||
var checkout = $(calendar).data('daterangepicker').endDate.format(eagle_booking_date_format);
|
||||
|
||||
// Display Date
|
||||
$(this).val(checkin + " " + " " + " → " + " " + " " + checkout);
|
||||
|
||||
// Add value to hidden inouts
|
||||
$('.eb_checkin').val(checkin);
|
||||
$('.eb_checkout').val(checkout);
|
||||
|
||||
// Update Booking Filters only for the search page (filters)
|
||||
if ($("div").hasClass("search-filters")) {
|
||||
eb_search_filters();
|
||||
}
|
||||
|
||||
if ($("div").hasClass("search-filters") || $("div").hasClass("calendar")) {
|
||||
eb_get_nights(calendar);
|
||||
}
|
||||
|
||||
// Disable all booked & blocked room on the signle room calendar
|
||||
if ( eb_signle_room == true ) {
|
||||
|
||||
var i, eb_booked_date;
|
||||
|
||||
// Loop all booked dates until the condition
|
||||
for( i = 0; i < eb_booked_dates.length; i++ ) {
|
||||
|
||||
eb_booked_date = moment(eb_booked_dates[i]).format('YYYY/MM/DD');
|
||||
|
||||
var checkin_new = $(calendar).data('daterangepicker').startDate.format('YYYY-MM-DD');
|
||||
var checkout_new = $(calendar).data('daterangepicker').endDate.format('YYYY-MM-DD');
|
||||
|
||||
if ( moment(eb_booked_date).isBetween(checkin_new, checkout_new) ) {
|
||||
|
||||
$(this).data('daterangepicker').setStartDate(checkout);
|
||||
$(this).val("").focus();
|
||||
|
||||
// Break loop on the first match
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
// =============================================
|
||||
// CALCULATE NIGHTS NUMBER
|
||||
// =============================================
|
||||
function eb_get_nights( calendar ) {
|
||||
|
||||
var eagle_booking_checkin = $(calendar).parent().find('.eb_checkin').val();
|
||||
var eagle_booking_checkout = $(calendar).parent().find('.eb_checkout').val();
|
||||
|
||||
var eagle_booking_start_date = moment(eagle_booking_checkin, eb_js_settings.eagle_booking_date_format.toUpperCase()).format('YYYY-MM-DD');;
|
||||
var eagle_booking_end_date = moment(eagle_booking_checkout, eb_js_settings.eagle_booking_date_format.toUpperCase()).format('YYYY-MM-DD');;
|
||||
|
||||
var booking_nights = (new Date(eagle_booking_end_date)) - (new Date(eagle_booking_start_date));
|
||||
var eagle_booking_nights_number = booking_nights / (1000 * 60 * 60 * 24);
|
||||
if (eagle_booking_nights_number < 0) {
|
||||
var eagle_booking_nights_number = '0';
|
||||
}
|
||||
|
||||
return eagle_booking_nights_number;
|
||||
|
||||
}
|
||||
|
||||
// =============================================
|
||||
// GUESTS SELECT
|
||||
// =============================================
|
||||
$('.eb-guestspicker .guestspicker').on('click', function (event) {
|
||||
$('.eb-guestspicker').toggleClass('active');
|
||||
event.preventDefault();
|
||||
});
|
||||
$(window).click(function () {
|
||||
$('.eb-guestspicker').removeClass('active');
|
||||
});
|
||||
$('.eb-guestspicker').on('click', function (event) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
function guestsSum() {
|
||||
var arr = $('.booking-guests');
|
||||
var guests = 0;
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (parseInt(arr[i].value, 10))
|
||||
guests += parseInt(arr[i].value, 10);
|
||||
}
|
||||
if (guests > 0) {
|
||||
var cardQty = document.querySelector(".gueststotal");
|
||||
cardQty.innerHTML = guests;
|
||||
}
|
||||
|
||||
// Add the new value to geust input
|
||||
$("#eagle_booking_guests").val(guests);
|
||||
|
||||
}
|
||||
|
||||
guestsSum();
|
||||
|
||||
$(function () {
|
||||
$(".plus, .minus").on("click", function () {
|
||||
var button = $(this);
|
||||
var oldValue = button.parent().find("input").val();
|
||||
var min_value = button.parent().find("input").attr("min");
|
||||
|
||||
if (button.hasClass('plus')) {
|
||||
var newVal = parseFloat(oldValue) + 1;
|
||||
} else {
|
||||
|
||||
if (oldValue > min_value) {
|
||||
var newVal = parseFloat(oldValue) - 1;
|
||||
} else {
|
||||
newVal = min_value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
button.parent().find("input").val(newVal);
|
||||
|
||||
guestsSum();
|
||||
|
||||
if ($('form').hasClass('booking-search-form')) {
|
||||
eagle_booking_filters();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Bookings Filters
|
||||
/*----------------------------------------------------*/
|
||||
// bind change event to select
|
||||
$('.eb_bookings_filter').on('change', function () {
|
||||
var url = $(this).val(); // get selected value
|
||||
if (url) { // require a URL
|
||||
window.location = url; // redirect
|
||||
}
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Bookings Calendar AJAX
|
||||
/*----------------------------------------------------*/
|
||||
function eb_calendar_room_availability() {
|
||||
|
||||
// handler to the ajax request
|
||||
var eb_ajax_calendar_room_availability_xhr = null;
|
||||
|
||||
$('.eb-room-booked').on('mouseenter', function(event) {
|
||||
|
||||
// Remove any previous active
|
||||
$('.eb-room-booked').removeClass("open");
|
||||
|
||||
var popover = $('#eb-room-availability-popup');
|
||||
var eb_loader = '<div id="eb-loader"></div>';
|
||||
|
||||
popover.append(eb_loader);
|
||||
|
||||
$('#eb-calendar-title').hide();
|
||||
$('#eb-calendar-title-loading').show();
|
||||
|
||||
// Empty any previous results
|
||||
$("#eb-room-availability-popup #content").empty();
|
||||
$("#eb-calendar-date").empty();
|
||||
$("#eb-calendar-room-title").empty();
|
||||
|
||||
// Popover Position
|
||||
var pos = $(this).position();
|
||||
var date_width = $(this).outerWidth();
|
||||
var calendar_width = $('.eb-calendar-view').outerWidth();
|
||||
var popover_width = $('#eb-room-availability-popup').outerWidth();
|
||||
|
||||
// Display popover in the left side
|
||||
if ( (calendar_width - pos.left) < popover_width + 50 ) {
|
||||
|
||||
var popover_pos = pos.left - popover_width;
|
||||
popover.removeClass('right');
|
||||
popover.addClass('left');
|
||||
|
||||
// Display popover in the right side
|
||||
} else {
|
||||
|
||||
var popover_pos = pos.left + date_width;
|
||||
popover.removeClass('left');
|
||||
popover.addClass('right');
|
||||
|
||||
}
|
||||
|
||||
popover.css({
|
||||
position: "absolute",
|
||||
top: pos.top + "px",
|
||||
left: (popover_pos) + "px",
|
||||
|
||||
}).show();
|
||||
|
||||
|
||||
var eb_date = $(this).data("date");
|
||||
var eb_displayed_date = $(this).data("displayed-date");
|
||||
var eb_room_id = $(this).data("room-id");
|
||||
var eb_room_title = $(this).data("room-title");
|
||||
|
||||
// if there is a previous ajax request, then abort it
|
||||
if( eb_ajax_calendar_room_availability_xhr != null ) {
|
||||
eb_ajax_calendar_room_availability_xhr.abort();
|
||||
eb_ajax_calendar_room_availability_xhr = null;
|
||||
}
|
||||
|
||||
// Start the AJAX request
|
||||
eb_ajax_calendar_room_availability_xhr = $.ajax({
|
||||
|
||||
url: eb_admin_ajax.eb_admin_calendar_ajax,
|
||||
method: 'GET',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'eb_admin_calendar_action',
|
||||
eb_date: eb_date,
|
||||
eb_room_id: eb_room_id,
|
||||
eb_calendar_nonce: eb_admin_ajax.eb_admin_ajax_nonce,
|
||||
},
|
||||
|
||||
// Success
|
||||
success: function (eb_calendar_room_availability_data) {
|
||||
|
||||
// Appened new results
|
||||
$("#eb-room-availability-popup #content").append(eb_calendar_room_availability_data.output);
|
||||
|
||||
$("#eb-room-availability-popup #content #bookings").append(eb_calendar_room_availability_data.bookings);
|
||||
|
||||
$('#eb-calendar-title-loading').hide();
|
||||
$('#eb-calendar-title').show();
|
||||
$('#eb-calendar-date').text(eb_displayed_date);
|
||||
$('#eb-calendar-room-title').text(eb_room_title);
|
||||
|
||||
},
|
||||
|
||||
error: function (eb_ajax_calendar_room_availability_xhr, textStatus, errorThrown) {
|
||||
// Console mssg - debug purpose
|
||||
console.log(errorThrown);
|
||||
|
||||
},
|
||||
|
||||
complete: function () {
|
||||
|
||||
// Remove loader
|
||||
$('#eb-loader').remove();
|
||||
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Booking Calendar POPOVER
|
||||
/*----------------------------------------------------*/
|
||||
$('.eb-room-booked').on('click', function(event) {
|
||||
|
||||
$(this).addClass("open").siblings().removeClass("open");
|
||||
|
||||
});
|
||||
|
||||
$('.eb-room-booked').on('mouseleave', function(event) {
|
||||
|
||||
if ( !$(this).hasClass('open') ) {
|
||||
|
||||
$('#eb-room-availability-popup').hide();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$('body').on('click', function(event) {
|
||||
|
||||
if ( !$(event.target).closest('.eb-room-booked, #eb-room-availability-popup').length ) {
|
||||
|
||||
$('#eb-room-availability-popup').hide();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
eb_calendar_room_availability();
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Media Upload
|
||||
/*----------------------------------------------------*/
|
||||
function media_upload(button_class) {
|
||||
|
||||
$('body').on('click', button_class, function (e) {
|
||||
|
||||
var upload_file_box = $(this);
|
||||
|
||||
// If the media frame already exists, reopen it.
|
||||
if (frame) {
|
||||
frame.open();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a new media frame
|
||||
var frame = wp.media({
|
||||
library: {
|
||||
type: 'image'
|
||||
},
|
||||
multiple: false
|
||||
});
|
||||
|
||||
frame.on('select', function () {
|
||||
|
||||
// Get media attachment details from the frame state
|
||||
var attachment = frame.state().get('selection').first().toJSON();
|
||||
|
||||
upload_file_box.parent().find('.eb-upload-file-url').val(attachment.url);
|
||||
upload_file_box.find('.eb-upload-file-remove').css('display', 'block');
|
||||
upload_file_box.find('.eb-upload-file-text').css('display', 'none');
|
||||
upload_file_box.find('.eb-upload-file-preview').attr('src', attachment.url).css('display', 'block');
|
||||
|
||||
});
|
||||
|
||||
frame.open();
|
||||
return false;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
media_upload('.eb-upload-file');
|
||||
|
||||
// Remove File
|
||||
$('body').on('click', ".eb-upload-file-remove", function (e) {
|
||||
|
||||
var upload_file_remove = $(this);
|
||||
upload_file_remove.css('display', 'none');
|
||||
upload_file_remove.parent().find('.eb-upload-file-text').css('display', 'block');
|
||||
upload_file_remove.parent().find('.eb-upload-file-url').val("");
|
||||
upload_file_remove.parent().find('.eb-upload-file-preview').attr('src', "").css('display', 'none');
|
||||
|
||||
preventDefault(e);
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Clear the form after the submit
|
||||
$('#submit').click(function () {
|
||||
|
||||
|
||||
var upload_file_submit_button = $(this);
|
||||
|
||||
// Look for a div WordPress produces for an invalid form element
|
||||
if ( !$('#addtag .form-invalid').length ) {
|
||||
|
||||
upload_file_submit_button.parent().parent().find('.eb-upload-file-preview').attr('src', "").css('display', 'none');
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
})(jQuery);
|
||||
307
wp-content/plugins/eagle-booking/assets/js/admin/ical.js
Normal file
307
wp-content/plugins/eagle-booking/assets/js/admin/ical.js
Normal file
@@ -0,0 +1,307 @@
|
||||
|
||||
|
||||
/*================================================
|
||||
* Plugin Name: Eagle Booking / Admin iCal [Beta]
|
||||
* Version: 1.3.6
|
||||
* Author: Eagle Themes (Jomin Muskaj)
|
||||
* Author URI: eagle-booking.com
|
||||
=================================================*/
|
||||
|
||||
(function ($) {
|
||||
|
||||
"use strict";
|
||||
|
||||
/* Document is Raedy Lets Start */
|
||||
$(document).ready(function () {
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* New Entry Form
|
||||
/*----------------------------------------------------*/
|
||||
$(".eb-new-entry").on("click", function (event) {
|
||||
|
||||
$(this).closest('.eb-entry-line').find('.eb-no-entry').hide();
|
||||
|
||||
$(this).closest('.eb-entry-line').find(".eb_ical_new_url").parent().parent().show();
|
||||
|
||||
})
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Cancel Edit
|
||||
/*----------------------------------------------------*/
|
||||
$('body').on('click', '.eb-cancel-action', function(event) {
|
||||
|
||||
$(this).closest('.eb-entry-line').find(".eb_ical_new_url").parent().parent().hide();
|
||||
|
||||
// Only if there is no any other entry
|
||||
$(this).closest('.eb-entry-line').find('.eb-no-entry').show();
|
||||
|
||||
});
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Create Entry
|
||||
/*----------------------------------------------------*/
|
||||
$('.eb-create-entry').on('click', function(event) {
|
||||
|
||||
// Check before submit
|
||||
var eb_form_has_error = false;
|
||||
|
||||
// Get required fields
|
||||
var fields = {
|
||||
line: $(this).closest('.eb-entry-line').find('.eb_ical_new_line'),
|
||||
url: $(this).closest('.eb-entry-line').find('.eb_ical_new_url'),
|
||||
room_id: $(this).closest('.eb-entry-line').find('.eb_ical_new_url').data('room-id'),
|
||||
}
|
||||
|
||||
// // Check if any required field is empty
|
||||
fields.url.each( function() {
|
||||
|
||||
if( !this.value ) {
|
||||
eb_form_has_error = true;
|
||||
$(this).addClass("empty");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Let's send back to PHP
|
||||
if ( eb_form_has_error == false ) {
|
||||
|
||||
// Handler to the ajax request
|
||||
var eb_create_entry = null;
|
||||
|
||||
// If there is a previous ajax request, then abort it
|
||||
if( eb_create_entry != null ) {
|
||||
eb_create_entry.abort();
|
||||
eb_create_entry = null;
|
||||
}
|
||||
|
||||
// Set the data
|
||||
var data = {
|
||||
action: 'admin_create_url',
|
||||
nonce: ical.nonce,
|
||||
url: fields.url.val(),
|
||||
ical_room_id: fields.room_id,
|
||||
}
|
||||
|
||||
eb_create_entry = $.ajax({
|
||||
type: 'POST',
|
||||
dataType: "json",
|
||||
url: ical.ajaxurl,
|
||||
data: data
|
||||
|
||||
})
|
||||
|
||||
// Always
|
||||
.always( function (response) {} )
|
||||
|
||||
// Done
|
||||
.done( function (response) {
|
||||
|
||||
// Lets check the returned status
|
||||
if ( response.status === 'success' ) {
|
||||
|
||||
var response_class = 'success';
|
||||
|
||||
// Remove "Add New Line"
|
||||
fields.line.hide();
|
||||
|
||||
// Add the content of the new line
|
||||
var new_line = $('<tr class="eb-url-line">Testjoni</tr>');
|
||||
|
||||
// $(new_line).insertAfter('.eb_ical_new_url').fadeIn();
|
||||
|
||||
|
||||
$('<tr class="eb-url-line"><td class="eb-url-line" width="50%"><code class="eb-existing-entry"><a href="' + fields.url.val() + '" target="_blank">' + fields.url.val() + '</a></code></td><td class="eb-action-buttons"><span class="eb-delete-action" data-url-id="2"><i class="fas fa-times"></i></span></td></tr>').insertAfter(fields.line)
|
||||
|
||||
// alert(fields.url.val());
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
var response_class = 'failed';
|
||||
|
||||
}
|
||||
|
||||
// Show notification box & and remove it after 3s
|
||||
var eb_notice = $('<div class="eb-notice eb-'+ response_class +'">'+ response.mssg +'</div>');
|
||||
|
||||
$(eb_notice).hide().appendTo("body").fadeIn(300);
|
||||
|
||||
// Remove Notice
|
||||
setTimeout( function() {
|
||||
$('.eb-notice').fadeOut(300);
|
||||
}, 3000);
|
||||
|
||||
|
||||
} )
|
||||
|
||||
// Fail
|
||||
.fail( function (response) { console.log('Request Failed'); })
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Delete Entry
|
||||
/*----------------------------------------------------*/
|
||||
$('.eb-delete-action').on('click', function(event) {
|
||||
|
||||
// Get required fields
|
||||
var fields = {
|
||||
line: $(this).closest('.eb-entry-line'),
|
||||
url_id: $(this).closest('.eb-url-line').data('row-id'),
|
||||
}
|
||||
|
||||
|
||||
// Handler to the ajax request
|
||||
var eb_delete_entry = null;
|
||||
|
||||
// If there is a previous ajax request, then abort it
|
||||
if( eb_delete_entry != null ) {
|
||||
eb_delete_entry.abort();
|
||||
eb_delete_entry = null;
|
||||
}
|
||||
|
||||
// Set the data
|
||||
var data = {
|
||||
action: 'admin_delete_url',
|
||||
nonce: ical.nonce,
|
||||
url_id: fields.url_id
|
||||
}
|
||||
|
||||
eb_delete_entry = $.ajax({
|
||||
type: 'POST',
|
||||
dataType: "json",
|
||||
url: ical.ajaxurl,
|
||||
data: data
|
||||
|
||||
})
|
||||
|
||||
// Always
|
||||
.always( function (response) {} )
|
||||
|
||||
// Done
|
||||
.done( function (response) {
|
||||
|
||||
// Lets check the returned status
|
||||
if ( response.status === 'success' ) {
|
||||
|
||||
var response_class = 'success';
|
||||
|
||||
|
||||
$('.eb-url-line[data-row-id="'+ fields.url_id +'"]').fadeOut(300);
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
var response_class = 'failed';
|
||||
|
||||
}
|
||||
|
||||
// Show notification box & and remove it after 3s
|
||||
var eb_notice = $('<div class="eb-notice eb-'+ response_class +'">'+ response.mssg +'</div>');
|
||||
|
||||
$(eb_notice).hide().appendTo("body").fadeIn(300);
|
||||
|
||||
// Remove Notice
|
||||
setTimeout( function() {
|
||||
$('.eb-notice').fadeOut(300);
|
||||
}, 3000);
|
||||
|
||||
|
||||
} )
|
||||
|
||||
// Fail
|
||||
.fail( function (response) { console.log('Request Failed'); })
|
||||
|
||||
});
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Sync Room
|
||||
/*----------------------------------------------------*/
|
||||
$('.eb-sync-action').on('click', function(event) {
|
||||
|
||||
// rotate icon
|
||||
$(this).addClass('eb-rotate');
|
||||
|
||||
$(this).removeAttr('data-eb-tooltip');
|
||||
|
||||
// Get required fields
|
||||
var fields = {
|
||||
room_id: $(this).data('entry-id'),
|
||||
}
|
||||
|
||||
// Handler to the ajax request
|
||||
var eb_sync_entry = null;
|
||||
|
||||
// If there is a previous ajax request, then abort it
|
||||
if( eb_sync_entry != null ) {
|
||||
eb_sync_entry.abort();
|
||||
eb_sync_entry = null;
|
||||
}
|
||||
|
||||
// Set the data
|
||||
var data = {
|
||||
action: 'admin_sync_ical',
|
||||
nonce: ical.nonce,
|
||||
room_id: fields.room_id
|
||||
}
|
||||
|
||||
eb_sync_entry = $.ajax({
|
||||
type: 'POST',
|
||||
dataType: "json",
|
||||
url: ical.ajaxurl,
|
||||
data: data
|
||||
|
||||
})
|
||||
|
||||
// Always
|
||||
.always( function (response) {
|
||||
|
||||
console.log(response);
|
||||
|
||||
} )
|
||||
|
||||
// Done
|
||||
.done( function (response) {
|
||||
|
||||
|
||||
// remove rotate icon
|
||||
|
||||
$('.eb-edit-action').removeClass('eb-rotate');
|
||||
|
||||
|
||||
// Check if booking deleted successfully
|
||||
if ( response.status === 'success' ) {
|
||||
|
||||
var response_class = 'success';
|
||||
|
||||
} else {
|
||||
|
||||
var response_class = 'error';
|
||||
|
||||
}
|
||||
|
||||
// Show notification box & and remove it after 3s
|
||||
var eb_notice = $('<div class="eb-notice eb-'+ response_class +'">'+ response.mssg +'</div>');
|
||||
|
||||
$(eb_notice).hide().appendTo("body").fadeIn(300);
|
||||
|
||||
// Remove Notice
|
||||
setTimeout( function() { $('.eb-notice').fadeOut(300);}, 3000);
|
||||
|
||||
|
||||
} )
|
||||
|
||||
// Fail
|
||||
.fail( function (response) { console.log(response); })
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
485
wp-content/plugins/eagle-booking/assets/js/admin/taxesfees.js
Normal file
485
wp-content/plugins/eagle-booking/assets/js/admin/taxesfees.js
Normal file
@@ -0,0 +1,485 @@
|
||||
/*================================================
|
||||
* Plugin Name: Eagle Booking / Admin Taxes
|
||||
* Version: 1.2.9.4
|
||||
* Author: Eagle Themes (Jomin Muskaj)
|
||||
* Author URI: eagle-booking.com
|
||||
=================================================*/
|
||||
|
||||
(function ($) {
|
||||
|
||||
"use strict";
|
||||
|
||||
/* Document is Raedy Lets Start */
|
||||
$(document).ready(function () {
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* New Entry Form
|
||||
/*----------------------------------------------------*/
|
||||
$(".eb-new-entry").on("click", function (event) {
|
||||
|
||||
event.preventDefault();
|
||||
var cat = $(this).data('cat');
|
||||
|
||||
// Clear any previous value
|
||||
$(this).closest('form').find("input[type=text]").val("");
|
||||
|
||||
$('.eb-new-'+cat+'-line').toggle();
|
||||
$('.eb-'+cat+'-no-entry').hide();
|
||||
})
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Create Entry
|
||||
/*----------------------------------------------------*/
|
||||
$('.eb-create-entry').on('click', function(event) {
|
||||
|
||||
// Check before submit
|
||||
var eb_form_has_error = false;
|
||||
|
||||
var fields = {
|
||||
cat: $(this).closest('.eb-admin-taxes-fees').find('#eb_entry_cat'),
|
||||
title: $(this).closest('.eb-admin-taxes-fees').find('#eb_entry_title'),
|
||||
type: $(this).closest('.eb-admin-taxes-fees').find('#eb_entry_type'),
|
||||
amount: $(this).closest('.eb-admin-taxes-fees').find('#eb_entry_amount'),
|
||||
global: $(this).closest('.eb-admin-taxes-fees').find('#eb_entry_global'),
|
||||
services: $(this).closest('.eb-admin-taxes-fees').find('#eb_entry_services'),
|
||||
// fees: $(this).closest('.eb-admin-taxes-fees').find('#eb_entry_fees')
|
||||
}
|
||||
|
||||
if ( $(fields.global).is(":checked") ) {
|
||||
fields.global = 1;
|
||||
} else {
|
||||
fields.global = 0;
|
||||
}
|
||||
if ( $(fields.services).is(":checked") ) {
|
||||
fields.services = 1;
|
||||
} else {
|
||||
fields.services = 0;
|
||||
}
|
||||
// if ( $(fields.fees).is(":checked") ) {
|
||||
// fields.fees = 1;
|
||||
// } else {
|
||||
// fields.fees = 0;
|
||||
// }
|
||||
|
||||
// Check if any required field is empty
|
||||
fields.title.add(fields.type).add(fields.amount).each( function() {
|
||||
|
||||
if( !this.value ) {
|
||||
eb_form_has_error = true;
|
||||
$(this).addClass("empty");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if ( eb_form_has_error == false ) {
|
||||
|
||||
// Handler to the ajax request
|
||||
var eb_create_entry = null;
|
||||
|
||||
// If there is a previous ajax request, then abort it
|
||||
if( eb_create_entry != null ) {
|
||||
eb_create_entry.abort();
|
||||
eb_create_entry = null;
|
||||
}
|
||||
|
||||
// Set the data
|
||||
var data = {
|
||||
action: 'admin_create_entry',
|
||||
entry_nonce: taxes_fees.nonce,
|
||||
entry_cat: fields.cat.val(),
|
||||
entry_title: fields.title.val(),
|
||||
entry_type: fields.type.val(),
|
||||
entry_amount: fields.amount.val(),
|
||||
entry_global: fields.global,
|
||||
entry_services: fields.services,
|
||||
// entry_fees: fields.fees
|
||||
}
|
||||
|
||||
eb_create_entry = $.ajax({
|
||||
type: 'POST',
|
||||
url: taxes_fees.ajaxurl,
|
||||
data: data
|
||||
|
||||
})
|
||||
|
||||
// Always
|
||||
.always( function (response) {} )
|
||||
|
||||
// Done
|
||||
.done( function (response) {
|
||||
|
||||
// Lets check the returned status
|
||||
if ( response.status === 'success' ) {
|
||||
|
||||
// Hide New Line Form
|
||||
$('.eb-new-'+data.entry_cat+'-line').hide();
|
||||
|
||||
if ( fields.global == 1 ) {
|
||||
var global_checkbox_text = 'Yes';
|
||||
} else {
|
||||
var global_checkbox_text = 'No';
|
||||
}
|
||||
|
||||
if ( fields.services == 1 ) {
|
||||
var services_checkbox_text = 'Yes';
|
||||
} else {
|
||||
var services_checkbox_text = 'No';
|
||||
}
|
||||
|
||||
// if ( fields.fees == 1 ) {
|
||||
// var fees_checkbox_text = 'Yes';
|
||||
// } else {
|
||||
// var fees_checkbox_text = 'No';
|
||||
// }
|
||||
|
||||
// Appened the new tr after last tr
|
||||
if ( data.entry_cat === 'eb_taxes' ) {
|
||||
|
||||
var new_line = $(
|
||||
|
||||
'<tr class="eb-entry-line"><td>' + fields.title.val() + '</td>\
|
||||
<td>' + fields.amount.val() + '</td>\
|
||||
<td>' + global_checkbox_text + '</td>\
|
||||
<td>' + services_checkbox_text + '</td>\
|
||||
<td class="eb-action-buttons"><span class="eb-edit-action eb-edit-entry"><i class="far fa-edit"></i></span><span class="eb-delete-action eb-delete-entry"><i class="far fa-trash-alt"></i></span> </td>\
|
||||
</tr>');
|
||||
|
||||
} else {
|
||||
|
||||
var new_line = $(
|
||||
|
||||
'<tr class="eb-entry-line">\
|
||||
<td>' + fields.title.val() + '</td>\
|
||||
<td>' + fields.type.val().replace(/_/g, ' ') + '</td>\
|
||||
<td>' + fields.amount.val() + '</td>\
|
||||
<td>' + global_checkbox_text + '</td>\
|
||||
<td class="eb-action-buttons"><span class="eb-edit-action eb-edit-entry"><i class="far fa-edit"></i></span><span class="eb-delete-action eb-delete-entry"><i class="far fa-trash-alt"></i></span> </td>\
|
||||
</tr>');
|
||||
}
|
||||
|
||||
// Add the line after the specific table
|
||||
$('.eb-admin-taxes-fees[data-cat="'+ data.entry_cat +'"]').find('tr').last().after(new_line);
|
||||
|
||||
var response_class = 'success';
|
||||
|
||||
} else {
|
||||
|
||||
var response_class = 'failed';
|
||||
|
||||
}
|
||||
|
||||
// Show notification box & and remove it after 3s
|
||||
var eb_notice = $('<div class="eb-notice eb-'+ response_class +'">'+ response.mssg +'</div>');
|
||||
|
||||
$(eb_notice).hide().appendTo("body").fadeIn(300);
|
||||
|
||||
// Remove Notice
|
||||
setTimeout( function() {
|
||||
$('.eb-notice').fadeOut(300);
|
||||
}, 3000);
|
||||
|
||||
})
|
||||
|
||||
// Fail
|
||||
.fail( function (response) { console.log('Request Failed'); })
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Update Entry
|
||||
/*----------------------------------------------------*/
|
||||
$('body').on('click', '.eb-update-entry', function(event) {
|
||||
|
||||
// Check before submit
|
||||
var eb_form_has_error = false;
|
||||
|
||||
var fields = {
|
||||
cat: $(this).data('cat'),
|
||||
id: $(this).data('entry-id'),
|
||||
title: $('#eb_update_entry_title'),
|
||||
type: $('#eb_update_entry_type'),
|
||||
amount: $('#eb_update_entry_amount'),
|
||||
global: $('#eb_update_entry_global'),
|
||||
services: $('#eb_update_entry_services'),
|
||||
// fees: $('#eb_update_entry_fees'),
|
||||
}
|
||||
|
||||
if ( $(fields.global).is(":checked") ) {
|
||||
fields.global = 1;
|
||||
} else {
|
||||
fields.global = 0;
|
||||
}
|
||||
if ( $(fields.services).is(":checked") ) {
|
||||
fields.services = 1;
|
||||
} else {
|
||||
fields.services = 0;
|
||||
}
|
||||
// if ( $(fields.fees).is(":checked") ) {
|
||||
// fields.fees = 1;
|
||||
// } else {
|
||||
// fields.fees = 0;
|
||||
// }
|
||||
|
||||
// Check if any required field is empty
|
||||
fields.title.add(fields.type).add(fields.amount).each( function() {
|
||||
|
||||
if( !this.value ) {
|
||||
eb_form_has_error = true;
|
||||
$(this).addClass("empty");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if ( eb_form_has_error == false ) {
|
||||
|
||||
// Handler to the ajax request
|
||||
var eb_update_entry = null;
|
||||
|
||||
// If there is a previous ajax request, then abort it
|
||||
if( eb_update_entry != null ) {
|
||||
eb_update_entry.abort();
|
||||
eb_update_entry = null;
|
||||
}
|
||||
|
||||
// Set the returned data
|
||||
var data = {
|
||||
action: 'admin_update_entry',
|
||||
entry_nonce: taxes_fees.nonce,
|
||||
entry_cat: fields.cat,
|
||||
entry_id: fields.id,
|
||||
entry_title: fields.title.val(),
|
||||
entry_type: fields.type.val(),
|
||||
entry_amount: fields.amount.val(),
|
||||
entry_global: fields.global,
|
||||
entry_services: fields.services,
|
||||
// entry_fees: fields.fees
|
||||
}
|
||||
|
||||
if ( fields.global == 1 ) {
|
||||
var global_text = 'Yes';
|
||||
} else {
|
||||
var global_text = 'No';
|
||||
}
|
||||
if ( fields.services == 1 ) {
|
||||
var services_text = 'Yes';
|
||||
} else {
|
||||
var services_text = 'No';
|
||||
}
|
||||
// if ( fields.fees == 1 ) {
|
||||
// var fees_text = 'Yes';
|
||||
// } else {
|
||||
// var fees_text = 'No';
|
||||
// }
|
||||
|
||||
eb_update_entry = $.ajax({
|
||||
type: 'POST',
|
||||
url: taxes_fees.ajaxurl,
|
||||
data: data
|
||||
|
||||
})
|
||||
|
||||
// Always
|
||||
.always( function (response) {} )
|
||||
|
||||
// Done
|
||||
.done( function (response) {
|
||||
|
||||
// Lets check the returned status
|
||||
if ( response.status === 'success' ) {
|
||||
|
||||
var response_class = 'success';
|
||||
|
||||
// Hide the edit line
|
||||
$('.eb-entry-edit[data-entry-id="'+ fields.id +'"]').hide();
|
||||
|
||||
// Show again the line ( without new values )wp_posts
|
||||
$('.eb-entry-line[data-entry-id="'+ fields.id +'"]').show();
|
||||
|
||||
// Lets change the old values
|
||||
$('.eb-entry-line[data-entry-id="'+ fields.id +'"]').find('.eb-entry-title').text(fields.title.val());
|
||||
$('.eb-entry-line[data-entry-id="'+ fields.id +'"]').find('.eb-entry-amount').text(data.entry_amount);
|
||||
$('.eb-entry-line[data-entry-id="'+ fields.id +'"]').find('.eb-entry-global').text(global_text);
|
||||
if ( data.entry_cat === 'eb_fees' ) {
|
||||
$('.eb-entry-line[data-entry-id="'+ fields.id +'"]').find('.eb-entry-type').text(fields.type.val().replace(/_/g, ' '));
|
||||
} else {
|
||||
$('.eb-entry-line[data-entry-id="'+ fields.id +'"]').find('.eb-entry-services').text(services_text);
|
||||
}
|
||||
|
||||
// BUG: inputs still have the old values
|
||||
|
||||
} else {
|
||||
|
||||
var response_class = 'failed';
|
||||
|
||||
}
|
||||
|
||||
// Show notification box & and remove it after 3s
|
||||
var eb_notice = $('<div class="eb-notice eb-'+ response_class +'">'+ response.mssg +'</div>');
|
||||
|
||||
$(eb_notice).hide().appendTo("body").fadeIn(300);
|
||||
|
||||
// Remove Notice
|
||||
setTimeout( function() {
|
||||
$('.eb-notice').fadeOut(300);
|
||||
}, 3000);
|
||||
|
||||
})
|
||||
|
||||
// Fail
|
||||
.fail( function (response) { console.log('Request Failed'); })
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Delete Entry
|
||||
/*----------------------------------------------------*/
|
||||
$('.eb-delete-entry').on('click', function(event) {
|
||||
|
||||
var entry_id = $(this).data('entry-id');
|
||||
var entry_line = $(this).closest( "tr" );
|
||||
var entry_cat = $(this).data('cat');
|
||||
|
||||
// Handler to the ajax request
|
||||
var eb_delete = null;
|
||||
|
||||
// If there is a previous ajax request, then abort it
|
||||
if( eb_delete != null ) {
|
||||
eb_delete.abort();
|
||||
eb_delete = null;
|
||||
}
|
||||
|
||||
// Set the data
|
||||
var data = {
|
||||
action: 'admin_delete_entry',
|
||||
nonce: taxes_fees.nonce,
|
||||
id: entry_id,
|
||||
cat: entry_cat
|
||||
}
|
||||
|
||||
eb_delete = $.ajax({
|
||||
type: 'POST',
|
||||
url: taxes_fees.ajaxurl,
|
||||
data: data
|
||||
|
||||
})
|
||||
|
||||
// Always
|
||||
.always( function (response) {} )
|
||||
|
||||
// Done
|
||||
.done( function (response) {
|
||||
|
||||
// Lets check the returned status
|
||||
if ( response.status === 'success' ) {
|
||||
|
||||
var response_class = 'success';
|
||||
// Remove Deleted Line
|
||||
entry_line.fadeOut(300);
|
||||
|
||||
} else {
|
||||
|
||||
var response_class = 'failed';
|
||||
|
||||
}
|
||||
|
||||
// Show notification box & and remove it after 3s
|
||||
var eb_notice = $('<div class="eb-notice eb-'+ response_class +'">'+ response.mssg +'</div>');
|
||||
|
||||
$(eb_notice).hide().appendTo("body").fadeIn(300);
|
||||
|
||||
// Remove Notice
|
||||
setTimeout( function() {
|
||||
$('.eb-notice').fadeOut(300);
|
||||
}, 3000);
|
||||
|
||||
})
|
||||
|
||||
// Fail
|
||||
.fail( function (response) { console.log('Request Failed'); })
|
||||
|
||||
});
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Edit Entry
|
||||
/*----------------------------------------------------*/
|
||||
$('.eb-edit-entry').on('click', function(event) {
|
||||
|
||||
var entry_line = $(this).closest( "tr" );
|
||||
|
||||
var fields = {
|
||||
cat: $(this).data('cat'),
|
||||
id: $(this).data('entry-id'),
|
||||
title: entry_line.find('.eb-entry-title').text(),
|
||||
type: entry_line.find('.eb-entry-type').text(),
|
||||
amount: entry_line.find('.eb-entry-amount').text(),
|
||||
global: entry_line.find('.eb-entry-global').text(),
|
||||
services: entry_line.find('.eb-entry-services').text(),
|
||||
// fees: entry_line.find('.eb-entry-fees').text(),
|
||||
}
|
||||
|
||||
if ( fields.global === 'Yes' ) {
|
||||
var global_checkbox = 'checked';
|
||||
} else {
|
||||
var global_checkbox = '';
|
||||
}
|
||||
|
||||
if ( fields.services === 'Yes' ) {
|
||||
var services_checkbox = 'checked';
|
||||
} else {
|
||||
var services_checkbox = '';
|
||||
}
|
||||
|
||||
// if ( fields.fees === 'Yes' ) {
|
||||
// var fees_checkbox = 'checked';
|
||||
// } else {
|
||||
// var fees_checkbox = '';
|
||||
// }
|
||||
|
||||
// Appened the edit for instead of $this tr (taxes or fees)
|
||||
if ( fields.cat === 'eb_taxes' ) {
|
||||
|
||||
var new_line =
|
||||
|
||||
$('<tr class="eb-entry-edit" data-entry-id='+fields.id+'> \
|
||||
<td><input type="text" id="eb_update_entry_title" value="'+ fields.title +'"></td> \
|
||||
<td><input type="text" id="eb_update_entry_amount" value="'+ fields.amount +'"></td>\
|
||||
<td><label class="switch"><input type="checkbox" id="eb_update_entry_global" value="'+ fields.global +'" ' + global_checkbox + ' ><span class="slider round"></span></labe></td>\
|
||||
<td><label class="switch"><input type="checkbox" id="eb_update_entry_services" value="'+ fields.services +'" ' + services_checkbox + ' ><span class="slider round"></span></labe></td>\
|
||||
<td class="eb-action-buttons"><span class="eb-edit-action eb-update-entry" data-entry-id="'+ fields.id +'" data-cat="'+fields.cat+'"><i class="fas fa-check"></i></span><span class="eb-delete-action eb-cancel-entry" data-entry-id="'+ fields.id +'"><i class="fas fa-times"></i></span> </td>\
|
||||
</tr>');
|
||||
|
||||
} else {
|
||||
|
||||
var new_line =
|
||||
|
||||
$('<tr class="eb-entry-edit" data-entry-id='+fields.id+'>\
|
||||
<td><input type="text" id="eb_update_entry_title" value="'+ fields.title +'"></td>\
|
||||
<td><select id="eb_update_entry_type"><option value="per_booking">Per Booking</option><option value="per_booking_nights">Per Booking Nights</option><option value="per_guests">Per Guests</option><option value="per_booking_nights_guests">Per Booking Nights x Guests</option></select></td></select></td><td><input type="text" id="eb_update_entry_amount" value="'+ fields.amount +'"></td><td><label class="switch"><input type="checkbox" id="eb_update_entry_global" value="'+ fields.global +'" ' + global_checkbox + ' ><span class="slider round"></span></labe></td>\
|
||||
<td class="eb-action-buttons"><span class="eb-edit-action eb-update-entry" data-entry-id="'+ fields.id +'" data-cat="'+fields.cat+'"><i class="fas fa-check"></i></span><span class="eb-delete-action eb-cancel-entry" data-entry-id="'+ fields.id +'"><i class="fas fa-times"></i></span> </td>\
|
||||
</tr>');
|
||||
}
|
||||
|
||||
$(entry_line).hide();
|
||||
$(new_line).insertBefore(entry_line);
|
||||
|
||||
});
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/* Cancel Edit
|
||||
/*----------------------------------------------------*/
|
||||
$('body').on('click', '.eb-cancel-entry', function(event) {
|
||||
|
||||
var entry_id = $(this).data('entry-id');
|
||||
var original_line = ('.eb-entry-line[data-entry-id="'+ entry_id +'"]');
|
||||
$(original_line).show();
|
||||
$(this).closest( "tr" ).hide();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
Reference in New Issue
Block a user