| 1 |
"use strict"; |
| 2 |
|
| 3 |
/** |
| 4 |
* Request Object |
| 5 |
* Here we can define Search parameters and Update it later, when some parameter was changed |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
var wpbc_ajx_customize_plugin = (function ( obj, $) { |
| 10 |
|
| 11 |
// Secure parameters for Ajax ------------------------------------------------------------------------------------ |
| 12 |
var p_secure = obj.security_obj = obj.security_obj || { |
| 13 |
user_id: 0, |
| 14 |
nonce : '', |
| 15 |
locale : '' |
| 16 |
}; |
| 17 |
|
| 18 |
obj.set_secure_param = function ( param_key, param_val ) { |
| 19 |
p_secure[ param_key ] = param_val; |
| 20 |
}; |
| 21 |
|
| 22 |
obj.get_secure_param = function ( param_key ) { |
| 23 |
return p_secure[ param_key ]; |
| 24 |
}; |
| 25 |
|
| 26 |
|
| 27 |
// Listing Search parameters ------------------------------------------------------------------------------------ |
| 28 |
var p_listing = obj.search_request_obj = obj.search_request_obj || { |
| 29 |
// sort : "booking_id", |
| 30 |
// sort_type : "DESC", |
| 31 |
// page_num : 1, |
| 32 |
// page_items_count: 10, |
| 33 |
// create_date : "", |
| 34 |
// keyword : "", |
| 35 |
// source : "" |
| 36 |
}; |
| 37 |
|
| 38 |
obj.search_set_all_params = function ( request_param_obj ) { |
| 39 |
p_listing = request_param_obj; |
| 40 |
}; |
| 41 |
|
| 42 |
obj.search_get_all_params = function () { |
| 43 |
return p_listing; |
| 44 |
}; |
| 45 |
|
| 46 |
obj.search_get_param = function ( param_key ) { |
| 47 |
return p_listing[ param_key ]; |
| 48 |
}; |
| 49 |
|
| 50 |
obj.search_set_param = function ( param_key, param_val ) { |
| 51 |
// if ( Array.isArray( param_val ) ){ |
| 52 |
// param_val = JSON.stringify( param_val ); |
| 53 |
// } |
| 54 |
p_listing[ param_key ] = param_val; |
| 55 |
}; |
| 56 |
|
| 57 |
obj.search_set_params_arr = function( params_arr ){ |
| 58 |
_.each( params_arr, function ( p_val, p_key, p_data ){ // Define different Search parameters for request |
| 59 |
this.search_set_param( p_key, p_val ); |
| 60 |
} ); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
// Other parameters ------------------------------------------------------------------------------------ |
| 65 |
var p_other = obj.other_obj = obj.other_obj || { }; |
| 66 |
|
| 67 |
obj.set_other_param = function ( param_key, param_val ) { |
| 68 |
p_other[ param_key ] = param_val; |
| 69 |
}; |
| 70 |
|
| 71 |
obj.get_other_param = function ( param_key ) { |
| 72 |
return p_other[ param_key ]; |
| 73 |
}; |
| 74 |
|
| 75 |
|
| 76 |
return obj; |
| 77 |
}( wpbc_ajx_customize_plugin || {}, jQuery )); |
| 78 |
|
| 79 |
var wpbc_ajx_bookings = []; |
| 80 |
|
| 81 |
/** |
| 82 |
* Show Content ---------------------------------------------------------------------------------------------- */ |
| 83 |
|
| 84 |
/** |
| 85 |
* Show Content - Calendar and UI elements |
| 86 |
* |
| 87 |
* @param ajx_data |
| 88 |
* @param ajx_search_params |
| 89 |
* @param ajx_cleaned_params |
| 90 |
*/ |
| 91 |
function wpbc_ajx_customize_plugin__page_content__show( ajx_data, ajx_search_params , ajx_cleaned_params ){ |
| 92 |
|
| 93 |
// Content --------------------------------------------------------------------------------------------------------- |
| 94 |
var template__customize_plugin_main_page_content = wp.template( 'wpbc_ajx_customize_plugin_main_page_content' ); |
| 95 |
jQuery( wpbc_ajx_customize_plugin.get_other_param( 'listing_container' ) ).html( template__customize_plugin_main_page_content( { |
| 96 |
'ajx_data' : ajx_data, |
| 97 |
'ajx_search_params' : ajx_search_params, // $_REQUEST[ 'search_params' ] |
| 98 |
'ajx_cleaned_params' : ajx_cleaned_params |
| 99 |
} ) ); |
| 100 |
|
| 101 |
var template__inline_calendar; |
| 102 |
var data_arr = { |
| 103 |
'ajx_data' : ajx_data, |
| 104 |
'ajx_search_params' : ajx_search_params, |
| 105 |
'ajx_cleaned_params' : ajx_cleaned_params |
| 106 |
}; |
| 107 |
|
| 108 |
switch ( ajx_data['customize_steps']['current'] ){ |
| 109 |
|
| 110 |
case 'calendar_skin': |
| 111 |
|
| 112 |
// Calendar -------------------------------------------------------------------------------------------- |
| 113 |
template__inline_calendar = wp.template( 'wpbc_ajx_customize_plugin__inline_calendar' ); |
| 114 |
jQuery('.wpbc_ajx_cstm__section_left').html( template__inline_calendar( data_arr ) ); |
| 115 |
|
| 116 |
// Calendar Skin |
| 117 |
var template__wiget_calendar_skin = wp.template( 'wpbc_ajx_widget_change_calendar_skin' ); |
| 118 |
jQuery('.wpbc_ajx_cstm__section_right .wpbc_widgets').append( template__wiget_calendar_skin( data_arr ) ); |
| 119 |
|
| 120 |
// Shortcode |
| 121 |
// var template__widget_plugin_shortcode = wp.template( 'wpbc_ajx_widget_plugin_shortcode' ); |
| 122 |
// jQuery('.wpbc_ajx_cstm__section_right .wpbc_widgets').append( template__widget_plugin_shortcode( data_arr ) ); |
| 123 |
|
| 124 |
// Size |
| 125 |
// var template__wiget_calendar_size = wp.template( 'wpbc_ajx_widget_calendar_size' ); |
| 126 |
// jQuery('.wpbc_ajx_cstm__section_right .wpbc_widgets').append( template__wiget_calendar_size( data_arr ) ); |
| 127 |
|
| 128 |
break; |
| 129 |
|
| 130 |
case 'calendar_size': |
| 131 |
|
| 132 |
// Calendar -------------------------------------------------------------------------------------------- |
| 133 |
template__inline_calendar = wp.template( 'wpbc_ajx_customize_plugin__inline_calendar' ); |
| 134 |
jQuery('.wpbc_ajx_cstm__section_left').html( template__inline_calendar( data_arr ) ); |
| 135 |
|
| 136 |
// Calendar Skin |
| 137 |
var template__wiget_calendar_size = wp.template( 'wpbc_ajx_widget_calendar_size' ); |
| 138 |
jQuery('.wpbc_ajx_cstm__section_right .wpbc_widgets').append( template__wiget_calendar_size( data_arr ) ); |
| 139 |
|
| 140 |
// Shortcode |
| 141 |
// var template__widget_plugin_shortcode = wp.template( 'wpbc_ajx_widget_plugin_shortcode' ); |
| 142 |
// jQuery('.wpbc_ajx_cstm__section_right .wpbc_widgets').append( template__widget_plugin_shortcode( data_arr ) ); |
| 143 |
|
| 144 |
break; |
| 145 |
|
| 146 |
case 'calendar_dates_selection': |
| 147 |
|
| 148 |
// Calendar -------------------------------------------------------------------------------------------- |
| 149 |
template__inline_calendar = wp.template( 'wpbc_ajx_customize_plugin__inline_calendar' ); |
| 150 |
jQuery('.wpbc_ajx_cstm__section_left').html( template__inline_calendar( data_arr ) ); |
| 151 |
|
| 152 |
jQuery('.wpbc_ajx_cstm__section_left').append('<div class="clear" style="width:100%;margin:50px 0 0;"></div>'); |
| 153 |
|
| 154 |
var message_html_id = wpbc_ajx_customize_plugin__show_message( |
| 155 |
'<strong>' + 'You can test days selection in calendar' + '</strong>' |
| 156 |
, { |
| 157 |
'container': '.wpbc_ajx_cstm__section_left', // '#ajax_working', |
| 158 |
'style' : 'margin: 6px auto; padding: 6px 20px;z-index: 999999;', |
| 159 |
'type' : 'info', |
| 160 |
'delay' : 5000 |
| 161 |
} |
| 162 |
); |
| 163 |
wpbc_blink_element( '#' + message_html_id, 3, 320 ); |
| 164 |
|
| 165 |
// Widget - Dates selection |
| 166 |
var template__widget_plugin_calendar_dates_selection = wp.template( 'wpbc_ajx_widget_calendar_dates_selection' ); |
| 167 |
jQuery('.wpbc_ajx_cstm__section_right .wpbc_widgets').append( template__widget_plugin_calendar_dates_selection( data_arr ) ); |
| 168 |
|
| 169 |
break; |
| 170 |
|
| 171 |
case 'calendar_weekdays_availability': |
| 172 |
|
| 173 |
// Scroll to current month |
| 174 |
var s_year = wpbc_ajx_customize_plugin.search_set_param( 'calendar__start_year', 0 ); |
| 175 |
var s_month = wpbc_ajx_customize_plugin.search_set_param( 'calendar__start_month', 0 ); |
| 176 |
|
| 177 |
// Calendar -------------------------------------------------------------------------------------------- |
| 178 |
template__inline_calendar = wp.template( 'wpbc_ajx_customize_plugin__inline_calendar' ); |
| 179 |
jQuery('.wpbc_ajx_cstm__section_left').html( template__inline_calendar( data_arr ) ); |
| 180 |
|
| 181 |
// Widget - Weekdays Availability |
| 182 |
var template__widget_plugin_calendar_weekdays_availability = wp.template( 'wpbc_ajx_widget_calendar_weekdays_availability' ); |
| 183 |
jQuery('.wpbc_ajx_cstm__section_right .wpbc_widgets').append( template__widget_plugin_calendar_weekdays_availability( data_arr ) ); |
| 184 |
|
| 185 |
break; |
| 186 |
|
| 187 |
case 'calendar_additional': |
| 188 |
|
| 189 |
// Calendar -------------------------------------------------------------------------------------------- |
| 190 |
template__inline_calendar = wp.template( 'wpbc_ajx_customize_plugin__inline_calendar' ); |
| 191 |
jQuery('.wpbc_ajx_cstm__section_left').html( template__inline_calendar( data_arr ) ); |
| 192 |
|
| 193 |
// Calendar Skin |
| 194 |
var template__wiget_calendar_additional = wp.template( 'wpbc_ajx_widget_calendar_additional' ); |
| 195 |
jQuery('.wpbc_ajx_cstm__section_right .wpbc_widgets').append( template__wiget_calendar_additional( data_arr ) ); |
| 196 |
|
| 197 |
// Shortcode |
| 198 |
// var template__widget_plugin_shortcode = wp.template( 'wpbc_ajx_widget_plugin_shortcode' ); |
| 199 |
// jQuery('.wpbc_ajx_cstm__section_right .wpbc_widgets').append( template__widget_plugin_shortcode( data_arr ) ); |
| 200 |
|
| 201 |
break; |
| 202 |
|
| 203 |
default: |
| 204 |
//console.log( `Sorry, we are out of ${expr}.` ); |
| 205 |
} |
| 206 |
|
| 207 |
// Toolbar --------------------------------------------------------------------------------------------------------- |
| 208 |
var template__customize_plugin_toolbar_page_content = wp.template( 'wpbc_ajx_customize_plugin_toolbar_page_content' ); |
| 209 |
jQuery( wpbc_ajx_customize_plugin.get_other_param( 'toolbar_container' ) ).html( template__customize_plugin_toolbar_page_content( { |
| 210 |
'ajx_data' : ajx_data, |
| 211 |
'ajx_search_params' : ajx_search_params, // $_REQUEST[ 'search_params' ] |
| 212 |
'ajx_cleaned_params' : ajx_cleaned_params |
| 213 |
} ) ); |
| 214 |
|
| 215 |
|
| 216 |
// Booking resources ------------------------------------------------------------------------------------------ |
| 217 |
var wpbc_ajx_select_booking_resource = wp.template( 'wpbc_ajx_select_booking_resource' ); |
| 218 |
jQuery( '#wpbc_hidden_template__select_booking_resource').html( wpbc_ajx_select_booking_resource( { |
| 219 |
'ajx_data' : ajx_data, |
| 220 |
'ajx_search_params' : ajx_search_params, |
| 221 |
'ajx_cleaned_params' : ajx_cleaned_params |
| 222 |
} ) ); |
| 223 |
/* |
| 224 |
* By default hided at ../wp-content/plugins/booking/includes/page-customize/_src/customize_plugin_page.css #wpbc_hidden_template__select_booking_resource { display: none; } |
| 225 |
* |
| 226 |
* We can hide ///- Hide resources! |
| 227 |
* //setTimeout( function (){ jQuery( '#wpbc_hidden_template__select_booking_resource' ).html( '' ); }, 1000 ); |
| 228 |
*/ |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
// Other --------------------------------------------------------------------------------------------------------- |
| 234 |
jQuery( '.wpbc_processing.wpbc_spin').parent().parent().parent().parent( '[id^="wpbc_notice_"]' ).hide(); |
| 235 |
|
| 236 |
|
| 237 |
// Load calendar --------------------------------------------------------------------------------------------------------- |
| 238 |
wpbc_ajx_customize_plugin__calendar__show( { |
| 239 |
'resource_id' : ajx_cleaned_params.resource_id, |
| 240 |
'ajx_nonce_calendar': ajx_data.ajx_nonce_calendar, |
| 241 |
'ajx_data_arr' : ajx_data, |
| 242 |
'ajx_cleaned_params' : ajx_cleaned_params |
| 243 |
} ); |
| 244 |
|
| 245 |
//------------------------------------------------------------------------------------------------------------------ |
| 246 |
/** |
| 247 |
* Change calendar skin view |
| 248 |
*/ |
| 249 |
jQuery( '.wpbc_radio__set_days_customize_plugin' ).on('change', function ( event, resource_id, inst ){ |
| 250 |
wpbc__calendar__change_skin( jQuery( this ).val() ); |
| 251 |
}); |
| 252 |
|
| 253 |
|
| 254 |
// Re-load Tooltips |
| 255 |
jQuery( document ).ready( function (){ |
| 256 |
wpbc_define_tippy_tooltips( wpbc_ajx_customize_plugin.get_other_param( 'listing_container' ) + ' ' ); |
| 257 |
wpbc_define_tippy_tooltips( wpbc_ajx_customize_plugin.get_other_param( 'toolbar_container' ) + ' ' ); |
| 258 |
}); |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
/** |
| 263 |
* Show inline month view calendar with all predefined CSS (sizes and check in/out, times containers) |
| 264 |
* @param {obj} calendar_params_arr |
| 265 |
{ |
| 266 |
'resource_id' : ajx_cleaned_params.resource_id, |
| 267 |
'ajx_nonce_calendar' : ajx_data_arr.ajx_nonce_calendar, |
| 268 |
'ajx_data_arr' : ajx_data_arr = { ajx_booking_resources:[], resource_unavailable_dates:[], season_customize_plugin:{},.... } |
| 269 |
'ajx_cleaned_params' : { |
| 270 |
calendar__days_selection_mode: "dynamic" |
| 271 |
calendar__timeslot_day_bg_as_available: "" |
| 272 |
calendar__view__cell_height: "" |
| 273 |
calendar__view__months_in_row: 4 |
| 274 |
calendar__view__visible_months: 12 |
| 275 |
calendar__view__width: "100%" |
| 276 |
|
| 277 |
dates_customize_plugin: "unavailable" |
| 278 |
dates_selection: "2023-03-14 ~ 2023-03-16" |
| 279 |
do_action: "set_customize_plugin" |
| 280 |
resource_id: 1 |
| 281 |
ui_clicked_element_id: "wpbc_customize_plugin_apply_btn" |
| 282 |
ui_usr__customize_plugin_selected_toolbar: "info" |
| 283 |
} |
| 284 |
} |
| 285 |
*/ |
| 286 |
function wpbc_ajx_customize_plugin__calendar__show( calendar_params_arr ){ |
| 287 |
|
| 288 |
// Update nonce |
| 289 |
jQuery( '#ajx_nonce_calendar_section' ).html( calendar_params_arr.ajx_nonce_calendar ); |
| 290 |
|
| 291 |
|
| 292 |
//------------------------------------------------------------------------------------------------------------------ |
| 293 |
// Update bookings |
| 294 |
//------------------------------------------------------------------------------------------------------------------ |
| 295 |
if ( 'undefined' == typeof (wpbc_ajx_bookings[ calendar_params_arr.resource_id ]) ){ wpbc_ajx_bookings[ calendar_params_arr.resource_id ] = []; } |
| 296 |
wpbc_ajx_bookings[ calendar_params_arr.resource_id ] = calendar_params_arr[ 'ajx_data_arr' ][ 'calendar_settings' ][ 'booked_dates' ]; |
| 297 |
|
| 298 |
|
| 299 |
//------------------------------------------------------------------------------------------------------------------ |
| 300 |
// Get scrolling month or year in calendar and save it to the init parameters |
| 301 |
//------------------------------------------------------------------------------------------------------------------ |
| 302 |
jQuery( 'body' ).off( 'wpbc__inline_booking_calendar__changed_year_month' ); |
| 303 |
jQuery( 'body' ).on( 'wpbc__inline_booking_calendar__changed_year_month', function ( event, year, month, calendar_params_arr, datepick_this ){ |
| 304 |
|
| 305 |
wpbc_ajx_customize_plugin.search_set_param( 'calendar__start_year', year ); |
| 306 |
wpbc_ajx_customize_plugin.search_set_param( 'calendar__start_month', month ); |
| 307 |
} ); |
| 308 |
|
| 309 |
//------------------------------------------------------------------------------------------------------------------ |
| 310 |
// Define showing mouse over tooltip on unavailable dates |
| 311 |
//------------------------------------------------------------------------------------------------------------------ |
| 312 |
jQuery( 'body' ).on( 'wpbc_datepick_inline_calendar_refresh', function ( event, resource_id, inst ){ |
| 313 |
|
| 314 |
/** |
| 315 |
* It's defined, when calendar REFRESHED (change months or days selection) loaded in jquery.datepick.wpbc.9.0.js : |
| 316 |
* $( 'body' ).trigger( 'wpbc_datepick_inline_calendar_refresh', ... //FixIn: 9.4.4.13 |
| 317 |
*/ |
| 318 |
|
| 319 |
// inst.dpDiv it's: <div class="datepick-inline datepick-multi" style="width: 17712px;">....</div> |
| 320 |
|
| 321 |
inst.dpDiv.find( '.season_unavailable,.before_after_unavailable,.weekdays_unavailable' ).on( 'mouseover', function ( this_event ){ |
| 322 |
// also available these vars: resource_id, jCalContainer, inst |
| 323 |
var jCell = jQuery( this_event.currentTarget ); |
| 324 |
wpbc_cstm__show_tooltip__for_element( jCell, calendar_params_arr[ 'ajx_data_arr' ]['popover_hints'] ); |
| 325 |
}); |
| 326 |
|
| 327 |
}); |
| 328 |
|
| 329 |
|
| 330 |
//------------------------------------------------------------------------------------------------------------------ |
| 331 |
// Define height of the calendar cells, and mouse over tooltips at some unavailable dates |
| 332 |
//------------------------------------------------------------------------------------------------------------------ |
| 333 |
jQuery( 'body' ).on( 'wpbc_datepick_inline_calendar_loaded', function ( event, resource_id, jCalContainer, inst ){ |
| 334 |
|
| 335 |
/** |
| 336 |
* It's defined, when calendar loaded in jquery.datepick.wpbc.9.0.js : |
| 337 |
* $( 'body' ).trigger( 'wpbc_datepick_inline_calendar_loaded', ... //FixIn: 9.4.4.12 |
| 338 |
*/ |
| 339 |
|
| 340 |
// Remove highlight day for today date |
| 341 |
jQuery( '.datepick-days-cell.datepick-today.datepick-days-cell-over' ).removeClass( 'datepick-days-cell-over' ); |
| 342 |
|
| 343 |
// Set height of calendar cells if defined this option |
| 344 |
var stylesheet = document.getElementById( 'wpbc-calendar-cell-height' ); |
| 345 |
if ( null !== stylesheet ){ |
| 346 |
stylesheet.parentNode.removeChild( stylesheet ); |
| 347 |
} |
| 348 |
if ( '' !== calendar_params_arr.ajx_cleaned_params.calendar__view__cell_height ){ |
| 349 |
jQuery( 'head' ).append( '<style type="text/css" id="wpbc-calendar-cell-height">' |
| 350 |
+ '.hasDatepick .datepick-inline .datepick-title-row th, ' |
| 351 |
+ '.hasDatepick .datepick-inline .datepick-days-cell {' |
| 352 |
+ 'height: ' + calendar_params_arr.ajx_cleaned_params.calendar__view__cell_height + ' !important;' |
| 353 |
+ '}' |
| 354 |
+'</style>' ); |
| 355 |
} |
| 356 |
|
| 357 |
// Define showing mouse over tooltip on unavailable dates |
| 358 |
jCalContainer.find( '.season_unavailable,.before_after_unavailable,.weekdays_unavailable' ).on( 'mouseover', function ( this_event ){ |
| 359 |
// also available these vars: resource_id, jCalContainer, inst |
| 360 |
var jCell = jQuery( this_event.currentTarget ); |
| 361 |
wpbc_cstm__show_tooltip__for_element( jCell, calendar_params_arr[ 'ajx_data_arr' ]['popover_hints'] ); |
| 362 |
}); |
| 363 |
} ); |
| 364 |
|
| 365 |
|
| 366 |
//------------------------------------------------------------------------------------------------------------------ |
| 367 |
// Define months_in_row |
| 368 |
//------------------------------------------------------------------------------------------------------------------ |
| 369 |
if ( ( undefined == calendar_params_arr.ajx_cleaned_params.calendar__view__months_in_row ) |
| 370 |
|| ( '' == calendar_params_arr.ajx_cleaned_params.calendar__view__months_in_row ) |
| 371 |
){ |
| 372 |
calendar_params_arr.ajx_cleaned_params.calendar__view__months_in_row = calendar_params_arr.ajx_cleaned_params.calendar__view__visible_months; |
| 373 |
} |
| 374 |
|
| 375 |
//------------------------------------------------------------------------------------------------------------------ |
| 376 |
// Define width of entire calendar |
| 377 |
//------------------------------------------------------------------------------------------------------------------ |
| 378 |
var width = ''; // var width = 'width:100%;max-width:100%;'; |
| 379 |
// Width /* FixIn: 9.7.3.4 */ |
| 380 |
if ( ( undefined != calendar_params_arr.ajx_cleaned_params.calendar__view__width ) |
| 381 |
&& ( '' !== calendar_params_arr.ajx_cleaned_params.calendar__view__width ) |
| 382 |
){ |
| 383 |
width += 'max-width:' + calendar_params_arr.ajx_cleaned_params.calendar__view__width + ';'; |
| 384 |
width += 'width:100%;'; |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
//------------------------------------------------------------------------------------------------------------------ |
| 389 |
// Add calendar container: "Calendar is loading..." and textarea |
| 390 |
//------------------------------------------------------------------------------------------------------------------ |
| 391 |
jQuery( '.wpbc_ajx_cstm__calendar' ).html( |
| 392 |
|
| 393 |
'<div class="' + ' bk_calendar_frame' |
| 394 |
+ ' months_num_in_row_' + calendar_params_arr.ajx_cleaned_params.calendar__view__months_in_row |
| 395 |
+ ' cal_month_num_' + calendar_params_arr.ajx_cleaned_params.calendar__view__visible_months |
| 396 |
+ ' ' + calendar_params_arr.ajx_cleaned_params.calendar__timeslot_day_bg_as_available // 'wpbc_timeslot_day_bg_as_available' || '' |
| 397 |
+ '" ' |
| 398 |
+ 'style="' + width + '">' |
| 399 |
|
| 400 |
+ '<div id="calendar_booking' + calendar_params_arr.resource_id + '">' + 'Calendar is loading...' + '</div>' |
| 401 |
|
| 402 |
+ '</div>' |
| 403 |
|
| 404 |
+ '<textarea id="date_booking' + calendar_params_arr.resource_id + '"' |
| 405 |
+ ' name="date_booking' + calendar_params_arr.resource_id + '"' |
| 406 |
+ ' autocomplete="off"' |
| 407 |
+ ' style="display:none;width:100%;height:10em;margin:2em 0 0;"></textarea>' |
| 408 |
); |
| 409 |
|
| 410 |
|
| 411 |
//------------------------------------------------------------------------------------------------------------------ |
| 412 |
// Define variables for calendar |
| 413 |
//------------------------------------------------------------------------------------------------------------------ |
| 414 |
var cal_param_arr = calendar_params_arr.ajx_data_arr.calendar_settings; |
| 415 |
cal_param_arr[ 'html_id' ] = 'calendar_booking' + calendar_params_arr.ajx_cleaned_params.resource_id; |
| 416 |
cal_param_arr[ 'text_id' ] = 'date_booking' + calendar_params_arr.ajx_cleaned_params.resource_id; |
| 417 |
cal_param_arr[ 'resource_id' ] = calendar_params_arr.ajx_cleaned_params.resource_id; |
| 418 |
cal_param_arr[ 'ajx_nonce_calendar' ] = calendar_params_arr.ajx_data_arr.ajx_nonce_calendar; |
| 419 |
cal_param_arr[ 'season_customize_plugin' ] = calendar_params_arr.ajx_data_arr.season_customize_plugin; |
| 420 |
cal_param_arr[ 'resource_unavailable_dates' ] = calendar_params_arr.ajx_data_arr.resource_unavailable_dates; |
| 421 |
cal_param_arr[ 'popover_hints' ] = calendar_params_arr.ajx_data_arr.popover_hints; // {'season_unavailable':'...','weekdays_unavailable':'...','before_after_unavailable':'...',} |
| 422 |
|
| 423 |
|
| 424 |
//------------------------------------------------------------------------------------------------------------------ |
| 425 |
// Show Calendar |
| 426 |
//------------------------------------------------------------------------------------------------------------------ |
| 427 |
wpbc_show_inline_booking_calendar( cal_param_arr ); |
| 428 |
|
| 429 |
|
| 430 |
//------------------------------------------------------------------------------------------------------------------ |
| 431 |
// Scroll to specific Year and Month, if defined in init parameters |
| 432 |
//------------------------------------------------------------------------------------------------------------------ |
| 433 |
var s_year = wpbc_ajx_customize_plugin.search_get_param( 'calendar__start_year' ); |
| 434 |
var s_month = wpbc_ajx_customize_plugin.search_get_param( 'calendar__start_month' ); |
| 435 |
if ( ( 0 !== s_year ) && ( 0 !== s_month ) ){ |
| 436 |
wpbc__inline_booking_calendar__change_year_month( cal_param_arr[ 'resource_id' ], s_year, s_month ) |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
/** |
| 442 |
* Tooltips ---------------------------------------------------------------------------------------------- */ |
| 443 |
|
| 444 |
/** |
| 445 |
* Define showing tooltip, when mouse over on SELECTABLE (available, pending, approved, resource unavailable), days |
| 446 |
* Can be called directly from datepick init function. |
| 447 |
* |
| 448 |
* @param value |
| 449 |
* @param date |
| 450 |
* @param calendar_params_arr |
| 451 |
* @param datepick_this |
| 452 |
* @returns {boolean} |
| 453 |
*/ |
| 454 |
function wpbc_cstm__prepare_tooltip__in_calendar( value, date, calendar_params_arr, datepick_this ){ |
| 455 |
|
| 456 |
if ( null == date ){ return false; } |
| 457 |
|
| 458 |
var td_class = ( date.getMonth() + 1 ) + '-' + date.getDate() + '-' + date.getFullYear(); |
| 459 |
|
| 460 |
var jCell = jQuery( '#calendar_booking' + calendar_params_arr.resource_id + ' td.cal4date-' + td_class ); |
| 461 |
|
| 462 |
wpbc_cstm__show_tooltip__for_element( jCell, calendar_params_arr[ 'popover_hints' ] ); |
| 463 |
return true; |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
/** |
| 468 |
* Define tooltip for showing on UNAVAILABLE days (season, weekday, today_depends unavailable) |
| 469 |
* |
| 470 |
* @param jCell jQuery of specific day cell |
| 471 |
* @param popover_hints Array with tooltip hint texts : {'season_unavailable':'...','weekdays_unavailable':'...','before_after_unavailable':'...',} |
| 472 |
*/ |
| 473 |
function wpbc_cstm__show_tooltip__for_element( jCell, popover_hints ){ |
| 474 |
|
| 475 |
var tooltip_time = ''; |
| 476 |
|
| 477 |
if ( jCell.hasClass( 'season_unavailable' ) ){ |
| 478 |
tooltip_time = popover_hints[ 'season_unavailable' ]; |
| 479 |
} else if ( jCell.hasClass( 'weekdays_unavailable' ) ){ |
| 480 |
tooltip_time = popover_hints[ 'weekdays_unavailable' ]; |
| 481 |
} else if ( jCell.hasClass( 'before_after_unavailable' ) ){ |
| 482 |
tooltip_time = popover_hints[ 'before_after_unavailable' ]; |
| 483 |
} else if ( jCell.hasClass( 'date2approve' ) ){ |
| 484 |
|
| 485 |
} else if ( jCell.hasClass( 'date_approved' ) ){ |
| 486 |
|
| 487 |
} else { |
| 488 |
|
| 489 |
} |
| 490 |
|
| 491 |
jCell.attr( 'data-content', tooltip_time ); |
| 492 |
|
| 493 |
var td_el = jCell.get(0); //jQuery( '#calendar_booking' + calendar_params_arr.resource_id + ' td.cal4date-' + td_class ).get(0); |
| 494 |
|
| 495 |
if ( ( undefined == td_el._tippy ) && ( '' != tooltip_time ) ){ |
| 496 |
|
| 497 |
wpbc_tippy( td_el , { |
| 498 |
content( reference ){ |
| 499 |
|
| 500 |
var popover_content = reference.getAttribute( 'data-content' ); |
| 501 |
|
| 502 |
return '<div class="popover popover_tippy">' |
| 503 |
+ '<div class="popover-content">' |
| 504 |
+ popover_content |
| 505 |
+ '</div>' |
| 506 |
+ '</div>'; |
| 507 |
}, |
| 508 |
allowHTML : true, |
| 509 |
trigger : 'mouseenter focus', |
| 510 |
interactive : ! true, |
| 511 |
hideOnClick : true, |
| 512 |
interactiveBorder: 10, |
| 513 |
maxWidth : 550, |
| 514 |
theme : 'wpbc-tippy-times', |
| 515 |
placement : 'top', |
| 516 |
delay : [400, 0], //FixIn: 9.4.2.2 |
| 517 |
ignoreAttributes : true, |
| 518 |
touch : true, //['hold', 500], // 500ms delay //FixIn: 9.2.1.5 |
| 519 |
appendTo: () => document.body, |
| 520 |
}); |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
/** |
| 529 |
* Ajax ------------------------------------------------------------------------------------------------------ */ |
| 530 |
|
| 531 |
/** |
| 532 |
* Send Ajax show request |
| 533 |
*/ |
| 534 |
function wpbc_ajx_customize_plugin__ajax_request(){ |
| 535 |
|
| 536 |
console.groupCollapsed( 'WPBC_AJX_CUSTOMIZE_PLUGIN' ); console.log( ' == Before Ajax Send - search_get_all_params() == ' , wpbc_ajx_customize_plugin.search_get_all_params() ); |
| 537 |
|
| 538 |
wpbc_customize_plugin_reload_button__spin_start(); |
| 539 |
|
| 540 |
// Start Ajax |
| 541 |
jQuery.post( wpbc_url_ajax, |
| 542 |
{ |
| 543 |
action : 'WPBC_AJX_CUSTOMIZE_PLUGIN', |
| 544 |
wpbc_ajx_user_id: wpbc_ajx_customize_plugin.get_secure_param( 'user_id' ), |
| 545 |
nonce : wpbc_ajx_customize_plugin.get_secure_param( 'nonce' ), |
| 546 |
wpbc_ajx_locale : wpbc_ajx_customize_plugin.get_secure_param( 'locale' ), |
| 547 |
|
| 548 |
search_params : wpbc_ajx_customize_plugin.search_get_all_params() |
| 549 |
}, |
| 550 |
/** |
| 551 |
* S u c c e s s |
| 552 |
* |
| 553 |
* @param response_data - its object returned from Ajax - class-live-searcg.php |
| 554 |
* @param textStatus - 'success' |
| 555 |
* @param jqXHR - Object |
| 556 |
*/ |
| 557 |
function ( response_data, textStatus, jqXHR ) { |
| 558 |
|
| 559 |
console.log( ' == Response WPBC_AJX_CUSTOMIZE_PLUGIN == ', response_data ); console.groupEnd(); |
| 560 |
|
| 561 |
// Probably Error |
| 562 |
if ( (typeof response_data !== 'object') || (response_data === null) ){ |
| 563 |
|
| 564 |
wpbc_ajx_customize_plugin__actual_content__hide(); |
| 565 |
wpbc_ajx_customize_plugin__show_message( response_data ); |
| 566 |
|
| 567 |
return; |
| 568 |
} |
| 569 |
|
| 570 |
// Reload page, after filter toolbar has been reset |
| 571 |
if ( ( undefined != response_data[ 'ajx_cleaned_params' ]) |
| 572 |
&& ( 'reset_done' === response_data[ 'ajx_cleaned_params' ][ 'do_action' ]) |
| 573 |
){ |
| 574 |
location.reload(); |
| 575 |
return; |
| 576 |
} |
| 577 |
|
| 578 |
// Show listing |
| 579 |
wpbc_ajx_customize_plugin__page_content__show( response_data[ 'ajx_data' ], response_data[ 'ajx_search_params' ] , response_data[ 'ajx_cleaned_params' ] ); |
| 580 |
|
| 581 |
//wpbc_ajx_customize_plugin__define_ui_hooks(); // Redefine Hooks, because we show new DOM elements |
| 582 |
if ( '' != response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ) ){ |
| 583 |
wpbc_admin_show_message( |
| 584 |
response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ) |
| 585 |
, ( '1' == response_data[ 'ajx_data' ][ 'ajx_after_action_result' ] ) ? 'success' : 'error' |
| 586 |
, 10000 |
| 587 |
); |
| 588 |
} |
| 589 |
|
| 590 |
wpbc_customize_plugin_reload_button__spin_pause(); |
| 591 |
// Remove spin icon from button and Enable this button. |
| 592 |
wpbc_button__remove_spin( response_data[ 'ajx_cleaned_params' ][ 'ui_clicked_element_id' ] ) |
| 593 |
|
| 594 |
jQuery( '#ajax_respond' ).html( response_data ); // For ability to show response, add such DIV element to page |
| 595 |
} |
| 596 |
).fail( function ( jqXHR, textStatus, errorThrown ) { if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); } |
| 597 |
|
| 598 |
var error_message = '<strong>' + 'Error!' + '</strong> ' + errorThrown ; |
| 599 |
if ( jqXHR.status ){ |
| 600 |
error_message += ' (<b>' + jqXHR.status + '</b>)'; |
| 601 |
if (403 == jqXHR.status ){ |
| 602 |
error_message += ' Probably nonce for this page has been expired. Please <a href="javascript:void(0)" onclick="javascript:location.reload();">reload the page</a>.'; |
| 603 |
} |
| 604 |
} |
| 605 |
if ( jqXHR.responseText ){ |
| 606 |
error_message += ' ' + jqXHR.responseText; |
| 607 |
} |
| 608 |
error_message = error_message.replace( /\n/g, "<br />" ); |
| 609 |
|
| 610 |
wpbc_ajx_customize_plugin__actual_content__hide(); |
| 611 |
wpbc_ajx_customize_plugin__show_message( error_message ); |
| 612 |
}) |
| 613 |
// .done( function ( data, textStatus, jqXHR ) { if ( window.console && window.console.log ){ console.log( 'second success', data, textStatus, jqXHR ); } }) |
| 614 |
// .always( function ( data_jqXHR, textStatus, jqXHR_errorThrown ) { if ( window.console && window.console.log ){ console.log( 'always finished', data_jqXHR, textStatus, jqXHR_errorThrown ); } }) |
| 615 |
; // End Ajax |
| 616 |
|
| 617 |
} |
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
/** |
| 622 |
* H o o k s - its Action/Times when need to re-Render Views ----------------------------------------------- */ |
| 623 |
|
| 624 |
/** |
| 625 |
* Send Ajax Search Request after Updating search request parameters |
| 626 |
* |
| 627 |
* @param params_arr |
| 628 |
*/ |
| 629 |
function wpbc_ajx_customize_plugin__send_request_with_params ( params_arr ){ |
| 630 |
|
| 631 |
// Define different Search parameters for request |
| 632 |
_.each( params_arr, function ( p_val, p_key, p_data ) { |
| 633 |
//console.log( 'Request for: ', p_key, p_val ); |
| 634 |
wpbc_ajx_customize_plugin.search_set_param( p_key, p_val ); |
| 635 |
}); |
| 636 |
|
| 637 |
// Send Ajax Request |
| 638 |
wpbc_ajx_customize_plugin__ajax_request(); |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
/** |
| 643 |
* Search request for "Page Number" |
| 644 |
* @param page_number int |
| 645 |
*/ |
| 646 |
function wpbc_ajx_customize_plugin__pagination_click( page_number ){ |
| 647 |
|
| 648 |
wpbc_ajx_customize_plugin__send_request_with_params( { |
| 649 |
'page_num': page_number |
| 650 |
} ); |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
/** |
| 656 |
* Show / Hide Content --------------------------------------------------------------------------------------- */ |
| 657 |
|
| 658 |
/** |
| 659 |
* Show Listing Content - Sending Ajax Request - with parameters that we early defined |
| 660 |
*/ |
| 661 |
function wpbc_ajx_customize_plugin__actual_content__show(){ |
| 662 |
|
| 663 |
wpbc_ajx_customize_plugin__ajax_request(); // Send Ajax Request - with parameters that we early defined in "wpbc_ajx_booking_listing" Obj. |
| 664 |
} |
| 665 |
|
| 666 |
/** |
| 667 |
* Hide Listing Content |
| 668 |
*/ |
| 669 |
function wpbc_ajx_customize_plugin__actual_content__hide(){ |
| 670 |
|
| 671 |
jQuery( wpbc_ajx_customize_plugin.get_other_param( 'listing_container' ) ).html( '' ); |
| 672 |
} |
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
/** |
| 677 |
* M e s s a g e --------------------------------------------------------------------------------------------- */ |
| 678 |
|
| 679 |
/** |
| 680 |
* |
| 681 |
*/ |
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
/** |
| 686 |
* Show message in content |
| 687 |
* |
| 688 |
* @param message Message HTML |
| 689 |
* @param params = { |
| 690 |
* ['type'] 'warning' | 'info' | 'error' | 'success' default: 'warning' |
| 691 |
* ['container'] '.wpbc_ajx_cstm__section_left' default: wpbc_ajx_customize_plugin.get_other_param( 'listing_container' ) |
| 692 |
* ['is_append'] true | false default: true |
| 693 |
* } |
| 694 |
* Example: |
| 695 |
* var html_id = wpbc_ajx_customize_plugin__show_message( 'You can test days selection in calendar', 'info', '.wpbc_ajx_cstm__section_left', true ); |
| 696 |
* |
| 697 |
* |
| 698 |
* @returns string - HTML ID |
| 699 |
*/ |
| 700 |
function wpbc_ajx_customize_plugin__show_message( message, params = {} ){ |
| 701 |
|
| 702 |
var params_default = { |
| 703 |
'type' : 'warning', |
| 704 |
'container': wpbc_ajx_customize_plugin.get_other_param( 'listing_container' ), |
| 705 |
'is_append': true, |
| 706 |
'style' : 'text-align:left;', |
| 707 |
'delay' : 0 |
| 708 |
}; |
| 709 |
_.each( params, function ( p_val, p_key, p_data ){ |
| 710 |
params_default[ p_key ] = p_val; |
| 711 |
} ); |
| 712 |
params = params_default; |
| 713 |
|
| 714 |
var unique_div_id = new Date(); |
| 715 |
unique_div_id = 'wpbc_notice_' + unique_div_id.getTime(); |
| 716 |
|
| 717 |
var alert_class = 'notice '; |
| 718 |
if ( params['type'] == 'error' ){ |
| 719 |
alert_class += 'notice-error '; |
| 720 |
message = '<i style="margin-right: 0.5em;color: #d63638;" class="menu_icon icon-1x wpbc_icn_report_gmailerrorred"></i>' + message; |
| 721 |
} |
| 722 |
if ( params['type'] == 'warning' ){ |
| 723 |
alert_class += 'notice-warning '; |
| 724 |
message = '<i style="margin-right: 0.5em;color: #e9aa04;" class="menu_icon icon-1x wpbc_icn_warning"></i>' + message; |
| 725 |
} |
| 726 |
if ( params['type'] == 'info' ){ |
| 727 |
alert_class += 'notice-info '; |
| 728 |
} |
| 729 |
if ( params['type'] == 'success' ){ |
| 730 |
alert_class += 'notice-info alert-success updated '; |
| 731 |
message = '<i style="margin-right: 0.5em;color: #64aa45;" class="menu_icon icon-1x wpbc_icn_done_outline"></i>' + message; |
| 732 |
} |
| 733 |
|
| 734 |
message = '<div id="' + unique_div_id + '" class="wpbc-settings-notice ' + alert_class + '" style="' + params[ 'style' ] + '">' + message + '</div>'; |
| 735 |
|
| 736 |
if ( params['is_append'] ){ |
| 737 |
jQuery( params['container'] ).append( message ); |
| 738 |
} else { |
| 739 |
jQuery( params['container'] ).html( message ); |
| 740 |
} |
| 741 |
|
| 742 |
params['delay'] = parseInt( params['delay'] ); |
| 743 |
if ( params['delay'] > 0 ){ |
| 744 |
|
| 745 |
var closed_timer = setTimeout( function (){ |
| 746 |
jQuery( '#' + unique_div_id ).fadeOut( 1500 ); |
| 747 |
} |
| 748 |
, params[ 'delay' ] |
| 749 |
); |
| 750 |
} |
| 751 |
|
| 752 |
return unique_div_id; |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
/** |
| 758 |
* Support Functions - Spin Icon in Buttons ------------------------------------------------------------------ */ |
| 759 |
|
| 760 |
/** |
| 761 |
* Spin button in Filter toolbar - Start |
| 762 |
*/ |
| 763 |
function wpbc_customize_plugin_reload_button__spin_start(){ |
| 764 |
jQuery( '#wpbc_customize_plugin_reload_button .menu_icon.wpbc_spin').removeClass( 'wpbc_animation_pause' ); |
| 765 |
} |
| 766 |
|
| 767 |
/** |
| 768 |
* Spin button in Filter toolbar - Pause |
| 769 |
*/ |
| 770 |
function wpbc_customize_plugin_reload_button__spin_pause(){ |
| 771 |
jQuery( '#wpbc_customize_plugin_reload_button .menu_icon.wpbc_spin' ).addClass( 'wpbc_animation_pause' ); |
| 772 |
} |
| 773 |
|
| 774 |
/** |
| 775 |
* Spin button in Filter toolbar - is Spinning ? |
| 776 |
* |
| 777 |
* @returns {boolean} |
| 778 |
*/ |
| 779 |
function wpbc_customize_plugin_reload_button__is_spin(){ |
| 780 |
if ( jQuery( '#wpbc_customize_plugin_reload_button .menu_icon.wpbc_spin' ).hasClass( 'wpbc_animation_pause' ) ){ |
| 781 |
return true; |
| 782 |
} else { |
| 783 |
return false; |
| 784 |
} |
| 785 |
} |
| 786 |
|