| 1 |
"use strict"; |
| 2 |
|
| 3 |
/** |
| 4 |
* Define HTML ui Hooks: on KeyUp | Change | -> Sort Order & Number Items / Page |
| 5 |
* * We are chnaged it once, because such elements always the same |
| 6 |
*/ |
| 7 |
function wpbc_ajx_booking_define_ui_hooks_once(){ |
| 8 |
|
| 9 |
//------------------------------------------------------------------------------------------------------------------ |
| 10 |
// Booked dates |
| 11 |
//------------------------------------------------------------------------------------------------------------------ |
| 12 |
jQuery( '#wh_booking_date' ).on( 'change', function( event ){ |
| 13 |
|
| 14 |
var changed_value = JSON.parse( jQuery( '#wh_booking_date' ).val() ); |
| 15 |
|
| 16 |
wpbc_ajx_booking_send_search_request_with_params( { |
| 17 |
'wh_booking_date': changed_value, |
| 18 |
'page_num' : 1, |
| 19 |
// Frontend selected elements (saving for future use, after F5) |
| 20 |
'ui_wh_booking_date_radio' : jQuery( 'input[name="ui_wh_booking_date_radio"]:checked' ).val(), |
| 21 |
'ui_wh_booking_date_next' : jQuery( '#ui_wh_booking_date_next' ).val(), |
| 22 |
'ui_wh_booking_date_prior' : jQuery( '#ui_wh_booking_date_prior' ).val(), |
| 23 |
'ui_wh_booking_date_checkin' : jQuery( '#ui_wh_booking_date_checkin' ).val(), |
| 24 |
'ui_wh_booking_date_checkout': jQuery( '#ui_wh_booking_date_checkout' ).val() |
| 25 |
} ); |
| 26 |
} ); |
| 27 |
|
| 28 |
//------------------------------------------------------------------------------------------------------------------ |
| 29 |
// Approved | Pending | All |
| 30 |
//------------------------------------------------------------------------------------------------------------------ |
| 31 |
jQuery( '#wh_approved' ).on( 'change', function( event ){ |
| 32 |
|
| 33 |
var changed_value = jQuery( '#wh_approved' ).val(); |
| 34 |
|
| 35 |
changed_value = JSON.parse( changed_value ); |
| 36 |
|
| 37 |
wpbc_ajx_booking_send_search_request_with_params( { |
| 38 |
'wh_approved': changed_value[ 0 ], |
| 39 |
'page_num' : 1 |
| 40 |
} ); |
| 41 |
} ); |
| 42 |
|
| 43 |
//------------------------------------------------------------------------------------------------------------------ |
| 44 |
// Keywords |
| 45 |
//------------------------------------------------------------------------------------------------------------------ |
| 46 |
jQuery( '#wpbc_search_field' ).on( "keyup", function ( event ){ |
| 47 |
if ( 13 !== event.which ){ |
| 48 |
wpbc_ajx_booking_searching_after_few_seconds( '#wpbc_search_field' ); // Searching after 1.5 seconds after Key Up |
| 49 |
} else { |
| 50 |
wpbc_ajx_booking_searching_after_few_seconds( '#wpbc_search_field', 0 ); // Immediate search |
| 51 |
} |
| 52 |
} ); |
| 53 |
|
| 54 |
//------------------------------------------------------------------------------------------------------------------ |
| 55 |
// Existing | Trash | Any |
| 56 |
//------------------------------------------------------------------------------------------------------------------ |
| 57 |
jQuery( '#wh_trash' ).on( 'change', function( event ){ |
| 58 |
|
| 59 |
var changed_value = JSON.parse( jQuery( '#wh_trash' ).val() ); |
| 60 |
|
| 61 |
wpbc_ajx_booking_send_search_request_with_params( { |
| 62 |
'wh_trash': changed_value[ 0 ], |
| 63 |
'page_num': 1 |
| 64 |
} ); |
| 65 |
} ); |
| 66 |
|
| 67 |
//------------------------------------------------------------------------------------------------------------------ |
| 68 |
// All bookings | New bookings |
| 69 |
//------------------------------------------------------------------------------------------------------------------ |
| 70 |
jQuery( '#wh_what_bookings' ).on( 'change', function( event ){ |
| 71 |
|
| 72 |
var changed_value = JSON.parse( jQuery( '#wh_what_bookings' ).val() ); |
| 73 |
|
| 74 |
wpbc_ajx_booking_send_search_request_with_params( { |
| 75 |
'wh_what_bookings': changed_value[ 0 ], |
| 76 |
'page_num': 1 |
| 77 |
} ); |
| 78 |
} ); |
| 79 |
|
| 80 |
//------------------------------------------------------------------------------------------------------------------ |
| 81 |
// "Creation Date" of bookings |
| 82 |
//------------------------------------------------------------------------------------------------------------------ |
| 83 |
jQuery( '#wh_modification_date' ).on( 'change', function( event ){ |
| 84 |
|
| 85 |
var changed_value = JSON.parse( jQuery( '#wh_modification_date' ).val() ); |
| 86 |
|
| 87 |
wpbc_ajx_booking_send_search_request_with_params( { |
| 88 |
'wh_modification_date': changed_value, |
| 89 |
'page_num' : 1, |
| 90 |
// Frontend selected elements (saving for future use, after F5) |
| 91 |
'ui_wh_modification_date_radio' : jQuery( 'input[name="ui_wh_modification_date_radio"]:checked' ).val(), |
| 92 |
'ui_wh_modification_date_prior' : jQuery( '#ui_wh_modification_date_prior' ).val(), |
| 93 |
'ui_wh_modification_date_checkin' : jQuery( '#ui_wh_modification_date_checkin' ).val(), |
| 94 |
'ui_wh_modification_date_checkout': jQuery( '#ui_wh_modification_date_checkout' ).val() |
| 95 |
} ); |
| 96 |
} ); |
| 97 |
|
| 98 |
//------------------------------------------------------------------------------------------------------------------ |
| 99 |
// Payment Status |
| 100 |
//------------------------------------------------------------------------------------------------------------------ |
| 101 |
jQuery( '#wh_pay_status' ).on( 'change', function( event ){ |
| 102 |
|
| 103 |
var changed_value = JSON.parse( jQuery( '#wh_pay_status' ).val() ); |
| 104 |
|
| 105 |
wpbc_ajx_booking_send_search_request_with_params( { |
| 106 |
'wh_pay_status': changed_value, |
| 107 |
'page_num' : 1, |
| 108 |
// Frontend selected elements (saving for future use, after F5) |
| 109 |
'ui_wh_pay_status_radio' : ( ( undefined === jQuery( 'input[name="ui_wh_pay_status_radio"]:checked' ).val() ) |
| 110 |
? '' |
| 111 |
: jQuery( 'input[name="ui_wh_pay_status_radio"]:checked' ).val() |
| 112 |
), |
| 113 |
'ui_wh_pay_status_custom': jQuery( '#ui_wh_pay_status_custom' ).val() |
| 114 |
} ); |
| 115 |
|
| 116 |
|
| 117 |
} ); |
| 118 |
|
| 119 |
//------------------------------------------------------------------------------------------------------------------ |
| 120 |
// Min Cost |
| 121 |
//------------------------------------------------------------------------------------------------------------------ |
| 122 |
jQuery( '#wh_cost' ).on( 'change', function( event ){ |
| 123 |
|
| 124 |
var changed_value = jQuery( '#wh_cost' ).val(); |
| 125 |
|
| 126 |
wpbc_ajx_booking_send_search_request_with_params( { |
| 127 |
'wh_cost' : changed_value, |
| 128 |
'page_num': 1 |
| 129 |
} ); |
| 130 |
} ); |
| 131 |
|
| 132 |
//------------------------------------------------------------------------------------------------------------------ |
| 133 |
// Max Cost |
| 134 |
//------------------------------------------------------------------------------------------------------------------ |
| 135 |
jQuery( '#wh_cost2' ).on( 'change', function( event ){ |
| 136 |
|
| 137 |
var changed_value = jQuery( '#wh_cost2' ).val(); |
| 138 |
|
| 139 |
wpbc_ajx_booking_send_search_request_with_params( { |
| 140 |
'wh_cost2' : changed_value, |
| 141 |
'page_num': 1 |
| 142 |
} ); |
| 143 |
} ); |
| 144 |
|
| 145 |
//------------------------------------------------------------------------------------------------------------------ |
| 146 |
// Booking resources |
| 147 |
//------------------------------------------------------------------------------------------------------------------ |
| 148 |
jQuery( '#wh_booking_type' ).on( 'change', function( event ){ |
| 149 |
|
| 150 |
var changed_value = jQuery( '#wh_booking_type' ).val(); // it's get as array |
| 151 |
if ( ( Array.isArray( changed_value ) ) && ( 0 === changed_value.length ) ){ |
| 152 |
changed_value = ['-1']; |
| 153 |
} |
| 154 |
wpbc_ajx_booking_send_search_request_with_params( { |
| 155 |
'wh_booking_type' : changed_value, |
| 156 |
'page_num': 1 |
| 157 |
} ); |
| 158 |
} ); |
| 159 |
|
| 160 |
|
| 161 |
//------------------------------------------------------------------------------------------------------------------ |
| 162 |
// Sorting |
| 163 |
//------------------------------------------------------------------------------------------------------------------ |
| 164 |
jQuery( '#wh_sort' ).on( 'change', function( event ){ |
| 165 |
|
| 166 |
var changed_value = jQuery( '#wh_sort' ).val(); |
| 167 |
|
| 168 |
changed_value = JSON.parse( changed_value ); |
| 169 |
|
| 170 |
wpbc_ajx_booking_send_search_request_with_params( { |
| 171 |
'wh_sort': changed_value[ 0 ] |
| 172 |
} ); |
| 173 |
} ); |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
jQuery(document).ready(function(){ |
| 178 |
wpbc_ajx_booking_define_ui_hooks_once(); |
| 179 |
}); |
| 180 |
|