| 1 |
"use strict"; |
| 2 |
|
| 3 |
// --------------------------------------------------------------------------------------------------------------------- |
| 4 |
// == A j a x A d d N e w B o o k i n g == |
| 5 |
// --------------------------------------------------------------------------------------------------------------------- |
| 6 |
|
| 7 |
|
| 8 |
/** |
| 9 |
* Submit new booking |
| 10 |
* |
| 11 |
* @param params = { |
| 12 |
'resource_id' : resource_id, |
| 13 |
'dates_ddmmyy_csv' : document.getElementById( 'date_booking' + resource_id ).value, |
| 14 |
'formdata' : formdata, |
| 15 |
'booking_hash' : my_booking_hash, |
| 16 |
'custom_form' : my_booking_form, |
| 17 |
|
| 18 |
'captcha_chalange' : captcha_chalange, |
| 19 |
'captcha_user_input' : user_captcha, |
| 20 |
|
| 21 |
'is_emails_send' : is_send_emeils, |
| 22 |
'active_locale' : wpdev_active_locale |
| 23 |
} |
| 24 |
* |
| 25 |
*/ |
| 26 |
function wpbc_ajx_booking__create( params ){ |
| 27 |
|
| 28 |
console.groupCollapsed( 'WPBC_AJX_BOOKING__CREATE' ); |
| 29 |
console.groupCollapsed( '== Before Ajax Send ==' ); |
| 30 |
console.log( params ); |
| 31 |
console.groupEnd(); |
| 32 |
|
| 33 |
params = wpbc_captcha__simple__maybe_remove_in_ajx_params( params ); |
| 34 |
|
| 35 |
// Trigger hook before sending request to create the booking. |
| 36 |
jQuery( 'body' ).trigger( 'wpbc_before_booking_create', [ params['resource_id'], params ] ); |
| 37 |
|
| 38 |
// Start Ajax. |
| 39 |
jQuery.post( wpbc_url_ajax, |
| 40 |
{ |
| 41 |
action : 'WPBC_AJX_BOOKING__CREATE', |
| 42 |
wpbc_ajx_user_id : _wpbc.get_secure_param( 'user_id' ), |
| 43 |
nonce : _wpbc.get_secure_param( 'nonce' ), |
| 44 |
wpbc_ajx_locale : _wpbc.get_secure_param( 'locale' ), |
| 45 |
calendar_request_params: params, |
| 46 |
/** |
| 47 |
* Usually params = { 'resource_id' : resource_id, |
| 48 |
* 'dates_ddmmyy_csv' : document.getElementById( 'date_booking' + resource_id ).value, |
| 49 |
* 'formdata' : formdata, |
| 50 |
* 'booking_hash' : my_booking_hash, |
| 51 |
* 'custom_form' : my_booking_form, |
| 52 |
* |
| 53 |
* 'captcha_chalange' : captcha_chalange, |
| 54 |
* 'user_captcha' : user_captcha, |
| 55 |
* |
| 56 |
* 'is_emails_send' : is_send_emeils, |
| 57 |
* 'active_locale' : wpdev_active_locale |
| 58 |
* } |
| 59 |
*/ |
| 60 |
}, |
| 61 |
|
| 62 |
/** |
| 63 |
* S u c c e s s |
| 64 |
* |
| 65 |
* @param response_data - its object returned from Ajax - class-live-searcg.php |
| 66 |
* @param textStatus - 'success' |
| 67 |
* @param jqXHR - Object |
| 68 |
*/ |
| 69 |
function ( response_data, textStatus, jqXHR ) { |
| 70 |
console.log( ' == Response WPBC_AJX_BOOKING__CREATE == ' ); |
| 71 |
for ( var obj_key in response_data ){ |
| 72 |
console.groupCollapsed( '==' + obj_key + '==' ); |
| 73 |
console.log( ' : ' + obj_key + ' : ', response_data[ obj_key ] ); |
| 74 |
console.groupEnd(); |
| 75 |
} |
| 76 |
console.groupEnd(); |
| 77 |
|
| 78 |
|
| 79 |
// <editor-fold defaultstate="collapsed" desc=" = Error Message! Server response with String. -> E_X_I_T " > |
| 80 |
// ------------------------------------------------------------------------------------------------- |
| 81 |
// This section execute, when server response with String instead of Object -- Usually it's because of mistake in code ! |
| 82 |
// ------------------------------------------------------------------------------------------------- |
| 83 |
if ( (typeof response_data !== 'object') || (response_data === null) ){ |
| 84 |
|
| 85 |
var calendar_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data ); |
| 86 |
var jq_node = '#booking_form' + calendar_id; |
| 87 |
|
| 88 |
if ( '' == response_data ){ |
| 89 |
response_data = '<strong>' + 'Error! Server respond with empty string!' + '</strong> ' ; |
| 90 |
} |
| 91 |
// Show Message |
| 92 |
wpbc_front_end__show_message( response_data , { 'type' : 'error', |
| 93 |
'show_here': {'jq_node': jq_node, 'where': 'after'}, |
| 94 |
'is_append': true, |
| 95 |
'style' : 'text-align:left;', |
| 96 |
'delay' : 0 |
| 97 |
} ); |
| 98 |
// Enable Submit | Hide spin loader |
| 99 |
wpbc_booking_form__on_response__ui_elements_enable( calendar_id ); |
| 100 |
return; |
| 101 |
} |
| 102 |
// </editor-fold> |
| 103 |
|
| 104 |
|
| 105 |
// <editor-fold defaultstate="collapsed" desc=" == This section execute, when we have KNOWN errors from Booking Calendar. -> E_X_I_T " > |
| 106 |
// ------------------------------------------------------------------------------------------------- |
| 107 |
// This section execute, when we have KNOWN errors from Booking Calendar |
| 108 |
// ------------------------------------------------------------------------------------------------- |
| 109 |
|
| 110 |
if ( 'ok' != response_data[ 'ajx_data' ][ 'status' ] ) { |
| 111 |
|
| 112 |
switch ( response_data[ 'ajx_data' ][ 'status_error' ] ){ |
| 113 |
|
| 114 |
case 'captcha_simple_wrong': |
| 115 |
wpbc_captcha__simple__update( { |
| 116 |
'resource_id': response_data[ 'resource_id' ], |
| 117 |
'url' : response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'url' ], |
| 118 |
'challenge' : response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'challenge' ], |
| 119 |
'message' : response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ) |
| 120 |
} |
| 121 |
); |
| 122 |
break; |
| 123 |
|
| 124 |
case 'resource_id_incorrect': // Show Error Message - incorrect booking resource ID during submit of booking. |
| 125 |
var message_id = wpbc_front_end__show_message( response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ), |
| 126 |
{ |
| 127 |
'type' : ('undefined' !== typeof (response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ])) |
| 128 |
? response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ] : 'warning', |
| 129 |
'delay' : 0, |
| 130 |
'show_here': { 'where': 'after', 'jq_node': '#booking_form' + params[ 'resource_id' ] } |
| 131 |
} ); |
| 132 |
break; |
| 133 |
|
| 134 |
case 'booking_can_not_save': // We can not save booking, because dates are booked or can not save in same booking resource all the dates |
| 135 |
var message_id = wpbc_front_end__show_message( response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ), |
| 136 |
{ |
| 137 |
'type' : ('undefined' !== typeof (response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ])) |
| 138 |
? response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ] : 'warning', |
| 139 |
'delay' : 0, |
| 140 |
'show_here': { 'where': 'after', 'jq_node': '#booking_form' + params[ 'resource_id' ] } |
| 141 |
} ); |
| 142 |
|
| 143 |
// Enable Submit | Hide spin loader |
| 144 |
wpbc_booking_form__on_response__ui_elements_enable( response_data[ 'resource_id' ] ); |
| 145 |
|
| 146 |
break; |
| 147 |
|
| 148 |
|
| 149 |
default: |
| 150 |
|
| 151 |
// <editor-fold defaultstate="collapsed" desc=" = For debug only ? -- Show Message under the form = " > |
| 152 |
// -------------------------------------------------------------------------------------------------------------------------------- |
| 153 |
if ( |
| 154 |
( 'undefined' !== typeof (response_data[ 'ajx_data' ][ 'ajx_after_action_message' ]) ) |
| 155 |
&& ( '' != response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ) ) |
| 156 |
){ |
| 157 |
|
| 158 |
var calendar_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data ); |
| 159 |
var jq_node = '#booking_form' + calendar_id; |
| 160 |
|
| 161 |
var ajx_after_booking_message = response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ); |
| 162 |
|
| 163 |
console.log( ajx_after_booking_message ); |
| 164 |
|
| 165 |
/** |
| 166 |
* // Show Message |
| 167 |
var ajx_after_action_message_id = wpbc_front_end__show_message( ajx_after_booking_message, |
| 168 |
{ |
| 169 |
'type' : ('undefined' !== typeof (response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ])) |
| 170 |
? response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ] : 'info', |
| 171 |
'delay' : 10000, |
| 172 |
'show_here': { |
| 173 |
'jq_node': jq_node, |
| 174 |
'where' : 'after' |
| 175 |
} |
| 176 |
} ); |
| 177 |
*/ |
| 178 |
} |
| 179 |
// </editor-fold> |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
// ------------------------------------------------------------------------------------------------- |
| 184 |
// Reactivate calendar again ? |
| 185 |
// ------------------------------------------------------------------------------------------------- |
| 186 |
// Enable Submit | Hide spin loader |
| 187 |
wpbc_booking_form__on_response__ui_elements_enable( response_data[ 'resource_id' ] ); |
| 188 |
|
| 189 |
// Unselect dates |
| 190 |
wpbc_calendar__unselect_all_dates( response_data[ 'resource_id' ] ); |
| 191 |
|
| 192 |
// 'resource_id' => $params['resource_id'], |
| 193 |
// 'booking_hash' => $booking_hash, |
| 194 |
// 'request_uri' => $_SERVER['REQUEST_URI'], // Is it the same as window.location.href or |
| 195 |
// 'custom_form' => $params['custom_form'], // Optional. |
| 196 |
// 'aggregate_resource_id_str' => implode( ',', $params['aggregate_resource_id_arr'] ) // Optional. Resource ID from aggregate parameter in shortcode. |
| 197 |
|
| 198 |
// Load new data in calendar. |
| 199 |
wpbc_calendar__load_data__ajx( { |
| 200 |
'resource_id' : response_data[ 'resource_id' ] // It's from response ...AJX_BOOKING__CREATE of initial sent resource_id |
| 201 |
, 'booking_hash': response_data[ 'ajx_cleaned_params' ]['booking_hash'] // ?? we can not use it, because HASH chnaged in any case! |
| 202 |
, 'request_uri' : response_data[ 'ajx_cleaned_params' ]['request_uri'] |
| 203 |
, 'custom_form' : response_data[ 'ajx_cleaned_params' ]['custom_form'] |
| 204 |
// Aggregate booking resources, if any ? |
| 205 |
, 'aggregate_resource_id_str' : _wpbc.booking__get_param_value( response_data[ 'resource_id' ], 'aggregate_resource_id_arr' ).join(',') |
| 206 |
|
| 207 |
} ); |
| 208 |
// Exit |
| 209 |
return; |
| 210 |
} |
| 211 |
|
| 212 |
// </editor-fold> |
| 213 |
|
| 214 |
|
| 215 |
/* |
| 216 |
// Show Calendar |
| 217 |
wpbc_calendar__loading__stop( response_data[ 'resource_id' ] ); |
| 218 |
|
| 219 |
// ------------------------------------------------------------------------------------------------- |
| 220 |
// Bookings - Dates |
| 221 |
_wpbc.bookings_in_calendar__set_dates( response_data[ 'resource_id' ], response_data[ 'ajx_data' ]['dates'] ); |
| 222 |
|
| 223 |
// Bookings - Child or only single booking resource in dates |
| 224 |
_wpbc.booking__set_param_value( response_data[ 'resource_id' ], 'resources_id_arr__in_dates', response_data[ 'ajx_data' ][ 'resources_id_arr__in_dates' ] ); |
| 225 |
// ------------------------------------------------------------------------------------------------- |
| 226 |
|
| 227 |
// Update calendar |
| 228 |
wpbc_calendar__update_look( response_data[ 'resource_id' ] ); |
| 229 |
*/ |
| 230 |
|
| 231 |
// Hide spin loader |
| 232 |
wpbc_booking_form__spin_loader__hide( response_data[ 'resource_id' ] ); |
| 233 |
|
| 234 |
// Hide booking form |
| 235 |
wpbc_booking_form__animated__hide( response_data[ 'resource_id' ] ); |
| 236 |
|
| 237 |
// Show Confirmation | Payment section |
| 238 |
wpbc_show_thank_you_message_after_booking( response_data ); |
| 239 |
|
| 240 |
// Trigger hook after a booking was created or updated successfully. |
| 241 |
jQuery( 'body' ).trigger( 'wpbc_booking_form_submit_success', [ response_data[ 'resource_id' ], response_data, params ] ); |
| 242 |
|
| 243 |
setTimeout( function (){ |
| 244 |
wpbc_do_scroll( '#wpbc_scroll_point_' + response_data[ 'resource_id' ], 10 ); |
| 245 |
}, 500 ); |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
} |
| 250 |
).fail( |
| 251 |
// <editor-fold defaultstate="collapsed" desc=" = This section execute, when NONCE field was not passed or some error happened at server! = " > |
| 252 |
function ( jqXHR, textStatus, errorThrown ) { if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); } |
| 253 |
|
| 254 |
// ------------------------------------------------------------------------------------------------- |
| 255 |
// This section execute, when NONCE field was not passed or some error happened at server! |
| 256 |
// ------------------------------------------------------------------------------------------------- |
| 257 |
|
| 258 |
// Get Content of Error Message |
| 259 |
var error_message = '<strong>' + 'Error!' + '</strong> ' + errorThrown ; |
| 260 |
if ( jqXHR.status ){ |
| 261 |
error_message += ' (<b>' + jqXHR.status + '</b>)'; |
| 262 |
if (403 == jqXHR.status ){ |
| 263 |
error_message += '<br> Probably nonce for this page has been expired. Please <a href="javascript:void(0)" onclick="javascript:location.reload();">reload the page</a>.'; |
| 264 |
error_message += '<br> Otherwise, please check this <a style="font-weight: 600;" href="https://wpbookingcalendar.com/faq/request-do-not-pass-security-check/?after_update=10.1.1">troubleshooting instruction</a>.<br>' |
| 265 |
} |
| 266 |
} |
| 267 |
if ( jqXHR.responseText ){ |
| 268 |
// Escape tags in Error message |
| 269 |
error_message += '<br><strong>Response</strong><div style="padding: 0 10px;margin: 0 0 10px;border-radius:3px; box-shadow:0px 0px 1px #a3a3a3;">' + jqXHR.responseText.replace(/&/g, "&") |
| 270 |
.replace(/</g, "<") |
| 271 |
.replace(/>/g, ">") |
| 272 |
.replace(/"/g, """) |
| 273 |
.replace(/'/g, "'") |
| 274 |
+'</div>'; |
| 275 |
} |
| 276 |
error_message = error_message.replace( /\n/g, "<br />" ); |
| 277 |
|
| 278 |
var calendar_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data ); |
| 279 |
var jq_node = '#booking_form' + calendar_id; |
| 280 |
|
| 281 |
// Show Message |
| 282 |
wpbc_front_end__show_message( error_message , { 'type' : 'error', |
| 283 |
'show_here': {'jq_node': jq_node, 'where': 'after'}, |
| 284 |
'is_append': true, |
| 285 |
'style' : 'text-align:left;', |
| 286 |
'delay' : 0 |
| 287 |
} ); |
| 288 |
// Enable Submit | Hide spin loader |
| 289 |
wpbc_booking_form__on_response__ui_elements_enable( calendar_id ); |
| 290 |
} |
| 291 |
// </editor-fold> |
| 292 |
) |
| 293 |
// .done( function ( data, textStatus, jqXHR ) { if ( window.console && window.console.log ){ console.log( 'second success', data, textStatus, jqXHR ); } }) |
| 294 |
// .always( function ( data_jqXHR, textStatus, jqXHR_errorThrown ) { if ( window.console && window.console.log ){ console.log( 'always finished', data_jqXHR, textStatus, jqXHR_errorThrown ); } }) |
| 295 |
; // End Ajax |
| 296 |
|
| 297 |
return true; |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
// <editor-fold defaultstate="collapsed" desc=" == CAPTCHA == " > |
| 302 |
|
| 303 |
/** |
| 304 |
* Update image in captcha and show warning message |
| 305 |
* |
| 306 |
* @param params |
| 307 |
* |
| 308 |
* Example of 'params' : { |
| 309 |
* 'resource_id': response_data[ 'resource_id' ], |
| 310 |
* 'url' : response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'url' ], |
| 311 |
* 'challenge' : response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'challenge' ], |
| 312 |
* 'message' : response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ) |
| 313 |
* } |
| 314 |
*/ |
| 315 |
function wpbc_captcha__simple__update( params ){ |
| 316 |
|
| 317 |
document.getElementById( 'captcha_input' + params[ 'resource_id' ] ).value = ''; |
| 318 |
document.getElementById( 'captcha_img' + params[ 'resource_id' ] ).src = params[ 'url' ]; |
| 319 |
document.getElementById( 'wpdev_captcha_challenge_' + params[ 'resource_id' ] ).value = params[ 'challenge' ]; |
| 320 |
|
| 321 |
// Show warning After CAPTCHA Img |
| 322 |
var message_id = wpbc_front_end__show_message__warning( '#captcha_input' + params[ 'resource_id' ] + ' + img', params[ 'message' ] ); |
| 323 |
|
| 324 |
// Animate |
| 325 |
jQuery( '#' + message_id + ', ' + '#captcha_input' + params[ 'resource_id' ] ).fadeOut( 350 ).fadeIn( 300 ).fadeOut( 350 ).fadeIn( 400 ).animate( {opacity: 1}, 4000 ); |
| 326 |
// Focus text field |
| 327 |
jQuery( '#captcha_input' + params[ 'resource_id' ] ).trigger( 'focus' ); // FixIn: 8.7.11.12. |
| 328 |
|
| 329 |
|
| 330 |
// Enable Submit | Hide spin loader |
| 331 |
wpbc_booking_form__on_response__ui_elements_enable( params[ 'resource_id' ] ); |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
/** |
| 336 |
* If the captcha elements not exist in the booking form, then remove parameters relative captcha |
| 337 |
* @param params |
| 338 |
* @returns obj |
| 339 |
*/ |
| 340 |
function wpbc_captcha__simple__maybe_remove_in_ajx_params( params ){ |
| 341 |
|
| 342 |
if ( ! wpbc_captcha__simple__is_exist_in_form( params[ 'resource_id' ] ) ){ |
| 343 |
delete params[ 'captcha_chalange' ]; |
| 344 |
delete params[ 'captcha_user_input' ]; |
| 345 |
} |
| 346 |
return params; |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
/** |
| 351 |
* Check if CAPTCHA exist in the booking form |
| 352 |
* @param resource_id |
| 353 |
* @returns {boolean} |
| 354 |
*/ |
| 355 |
function wpbc_captcha__simple__is_exist_in_form( resource_id ){ |
| 356 |
|
| 357 |
return ( |
| 358 |
(0 !== jQuery( '#wpdev_captcha_challenge_' + resource_id ).length) |
| 359 |
|| (0 !== jQuery( '#captcha_input' + resource_id ).length) |
| 360 |
); |
| 361 |
} |
| 362 |
|
| 363 |
// </editor-fold> |
| 364 |
|
| 365 |
|
| 366 |
// <editor-fold defaultstate="collapsed" desc=" == Send Button | Form Spin Loader == " > |
| 367 |
|
| 368 |
/** |
| 369 |
* Disable Send button | Show Spin Loader |
| 370 |
* |
| 371 |
* @param resource_id |
| 372 |
*/ |
| 373 |
function wpbc_booking_form__on_submit__ui_elements_disable( resource_id ){ |
| 374 |
|
| 375 |
// Disable Submit |
| 376 |
wpbc_booking_form__send_button__disable( resource_id ); |
| 377 |
|
| 378 |
// Show Spin loader in booking form |
| 379 |
wpbc_booking_form__spin_loader__show( resource_id ); |
| 380 |
} |
| 381 |
|
| 382 |
/** |
| 383 |
* Enable Send button | Hide Spin Loader |
| 384 |
* |
| 385 |
* @param resource_id |
| 386 |
*/ |
| 387 |
function wpbc_booking_form__on_response__ui_elements_enable(resource_id){ |
| 388 |
|
| 389 |
// Enable Submit |
| 390 |
wpbc_booking_form__send_button__enable( resource_id ); |
| 391 |
|
| 392 |
// Hide Spin loader in booking form |
| 393 |
wpbc_booking_form__spin_loader__hide( resource_id ); |
| 394 |
} |
| 395 |
|
| 396 |
/** |
| 397 |
* Enable Submit button |
| 398 |
* @param resource_id |
| 399 |
*/ |
| 400 |
function wpbc_booking_form__send_button__enable( resource_id ){ |
| 401 |
|
| 402 |
// Activate Send button |
| 403 |
jQuery( '#booking_form_div' + resource_id + ' input[type=button]' ).prop( "disabled", false ); |
| 404 |
jQuery( '#booking_form_div' + resource_id + ' button' ).prop( "disabled", false ); |
| 405 |
} |
| 406 |
|
| 407 |
/** |
| 408 |
* Disable Submit button and show spin |
| 409 |
* |
| 410 |
* @param resource_id |
| 411 |
*/ |
| 412 |
function wpbc_booking_form__send_button__disable( resource_id ){ |
| 413 |
|
| 414 |
// Disable Send button |
| 415 |
jQuery( '#booking_form_div' + resource_id + ' input[type=button]' ).prop( "disabled", true ); |
| 416 |
jQuery( '#booking_form_div' + resource_id + ' button' ).prop( "disabled", true ); |
| 417 |
} |
| 418 |
|
| 419 |
/** |
| 420 |
* Disable 'This' button |
| 421 |
* |
| 422 |
* @param _this |
| 423 |
*/ |
| 424 |
function wpbc_booking_form__this_button__disable( _this ){ |
| 425 |
|
| 426 |
// Disable Send button |
| 427 |
jQuery( _this ).prop( "disabled", true ); |
| 428 |
} |
| 429 |
|
| 430 |
/** |
| 431 |
* Show booking form Spin Loader |
| 432 |
* @param resource_id |
| 433 |
*/ |
| 434 |
function wpbc_booking_form__spin_loader__show( resource_id ){ |
| 435 |
|
| 436 |
var $form_container = jQuery( '#booking_form_div' + resource_id ); |
| 437 |
var loader_text = 'Saving'; |
| 438 |
if ( 'undefined' !== typeof _wpbc && _wpbc.get_message ) { |
| 439 |
loader_text = _wpbc.get_message( 'message_saving' ) || loader_text; |
| 440 |
} |
| 441 |
var loader_html = '<div id="wpbc_booking_form_spin_loader' + resource_id + '" class="wpbc_booking_form_spin_loader wpbc_booking_form_submit_overlay" aria-live="polite" aria-hidden="false">' |
| 442 |
+ '<div class="wpbc_spins_loading_container">' |
| 443 |
+ '<div class="wpbc_booking_form_spin_loader"><div class="wpbc_spins_loader_wrapper"><div class="wpbc_spin_loader_one_new"></div></div></div>' |
| 444 |
+ '<span>' + loader_text + '...</span>' |
| 445 |
+ '</div>' |
| 446 |
+ '</div>'; |
| 447 |
|
| 448 |
// Remove any previous inline loader before adding the submit overlay. |
| 449 |
jQuery( '#wpbc_booking_form_spin_loader' + resource_id ).remove(); |
| 450 |
|
| 451 |
if ( $form_container.length && $form_container.is( ':visible' ) ) { |
| 452 |
$form_container.addClass( 'wpbc_booking_form_is_submitting' ); |
| 453 |
$form_container.prepend( loader_html ); |
| 454 |
return; |
| 455 |
} |
| 456 |
|
| 457 |
// Fallback for any unexpected legacy markup without #booking_form_div{resource_id}. |
| 458 |
jQuery( '#booking_form' + resource_id ).after( |
| 459 |
'<div id="wpbc_booking_form_spin_loader' + resource_id + '" class="wpbc_booking_form_spin_loader" style="position: relative;"><div class="wpbc_spins_loader_wrapper"><div class="wpbc_spin_loader_one_new"></div></div></div>' |
| 460 |
); |
| 461 |
} |
| 462 |
|
| 463 |
/** |
| 464 |
* Remove / Hide booking form Spin Loader |
| 465 |
* @param resource_id |
| 466 |
*/ |
| 467 |
function wpbc_booking_form__spin_loader__hide( resource_id ){ |
| 468 |
|
| 469 |
// Remove Spin Loader |
| 470 |
jQuery( '#wpbc_booking_form_spin_loader' + resource_id ).remove(); |
| 471 |
jQuery( '#booking_form_div' + resource_id ).removeClass( 'wpbc_booking_form_is_submitting' ); |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
/** |
| 476 |
* Hide booking form wth animation |
| 477 |
* |
| 478 |
* @param resource_id |
| 479 |
*/ |
| 480 |
function wpbc_booking_form__animated__hide( resource_id ){ |
| 481 |
|
| 482 |
jQuery( '#booking_form' + resource_id ).hide(); |
| 483 |
} |
| 484 |
// </editor-fold> |
| 485 |
|
| 486 |
|
| 487 |
// <editor-fold defaultstate="collapsed" desc=" == Mini Spin Loader == " > |
| 488 |
|
| 489 |
/** |
| 490 |
* |
| 491 |
* @param parent_html_id |
| 492 |
*/ |
| 493 |
|
| 494 |
/** |
| 495 |
* Show micro Spin Loader |
| 496 |
* |
| 497 |
* @param id ID of Loader, for later hide it by using wpbc__spin_loader__micro__hide( id ) OR wpbc__spin_loader__mini__hide( id ) |
| 498 |
* @param jq_node_where_insert such as '#estimate_booking_night_cost_hint10' OR '.estimate_booking_night_cost_hint10' |
| 499 |
*/ |
| 500 |
function wpbc__spin_loader__micro__show__inside( id , jq_node_where_insert ){ |
| 501 |
|
| 502 |
wpbc__spin_loader__mini__show( id, { |
| 503 |
'color' : '#444', |
| 504 |
'show_here': { |
| 505 |
'where' : 'inside', |
| 506 |
'jq_node': jq_node_where_insert |
| 507 |
}, |
| 508 |
'style' : 'position: relative;display: inline-flex;flex-flow: column nowrap;justify-content: center;align-items: center;margin: 7px 12px;', |
| 509 |
'class' : 'wpbc_one_spin_loader_micro' |
| 510 |
} ); |
| 511 |
} |
| 512 |
|
| 513 |
/** |
| 514 |
* Remove spinner |
| 515 |
* @param id |
| 516 |
*/ |
| 517 |
function wpbc__spin_loader__micro__hide( id ){ |
| 518 |
wpbc__spin_loader__mini__hide( id ); |
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
/** |
| 523 |
* Show mini Spin Loader |
| 524 |
* @param parent_html_id |
| 525 |
*/ |
| 526 |
function wpbc__spin_loader__mini__show( parent_html_id , params = {} ){ |
| 527 |
|
| 528 |
var params_default = { |
| 529 |
'color' : '#0071ce', |
| 530 |
'show_here': { |
| 531 |
'jq_node': '', // any jQuery node definition |
| 532 |
'where' : 'after' // 'inside' | 'before' | 'after' | 'right' | 'left' |
| 533 |
}, |
| 534 |
'style' : 'position: relative;min-height: 2.8rem;', |
| 535 |
'class' : 'wpbc_one_spin_loader_mini 0wpbc_spin_loader_one_new' |
| 536 |
}; |
| 537 |
for ( var p_key in params ){ |
| 538 |
params_default[ p_key ] = params[ p_key ]; |
| 539 |
} |
| 540 |
params = params_default; |
| 541 |
|
| 542 |
if ( ('undefined' !== typeof (params['color'])) && ('' != params['color']) ){ |
| 543 |
params['color'] = 'border-color:' + params['color'] + ';'; |
| 544 |
} |
| 545 |
|
| 546 |
var spinner_html = '<div id="wpbc_mini_spin_loader' + parent_html_id + '" class="wpbc_booking_form_spin_loader" style="' + params[ 'style' ] + '"><div class="wpbc_spins_loader_wrapper"><div class="' + params[ 'class' ] + '" style="' + params[ 'color' ] + '"></div></div></div>'; |
| 547 |
|
| 548 |
if ( '' == params[ 'show_here' ][ 'jq_node' ] ){ |
| 549 |
params[ 'show_here' ][ 'jq_node' ] = '#' + parent_html_id; |
| 550 |
} |
| 551 |
|
| 552 |
// Show Spin Loader |
| 553 |
if ( 'after' == params[ 'show_here' ][ 'where' ] ){ |
| 554 |
jQuery( params[ 'show_here' ][ 'jq_node' ] ).after( spinner_html ); |
| 555 |
} else { |
| 556 |
jQuery( params[ 'show_here' ][ 'jq_node' ] ).html( spinner_html ); |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
/** |
| 561 |
* Remove / Hide mini Spin Loader |
| 562 |
* @param parent_html_id |
| 563 |
*/ |
| 564 |
function wpbc__spin_loader__mini__hide( parent_html_id ){ |
| 565 |
|
| 566 |
// Remove Spin Loader |
| 567 |
jQuery( '#wpbc_mini_spin_loader' + parent_html_id ).remove(); |
| 568 |
} |
| 569 |
|
| 570 |
// </editor-fold> |
| 571 |
|
| 572 |
//TODO: what about showing only Thank you. message without payment forms. |
| 573 |
/** |
| 574 |
* Show 'Thank you'. message and payment forms |
| 575 |
* |
| 576 |
* @param response_data |
| 577 |
*/ |
| 578 |
function wpbc_show_thank_you_message_after_booking( response_data ){ |
| 579 |
|
| 580 |
if ( |
| 581 |
('undefined' !== typeof (response_data[ 'ajx_confirmation' ][ 'ty_is_redirect' ])) |
| 582 |
&& ('undefined' !== typeof (response_data[ 'ajx_confirmation' ][ 'ty_url' ])) |
| 583 |
&& ('page' == response_data[ 'ajx_confirmation' ][ 'ty_is_redirect' ]) |
| 584 |
&& ('' != response_data[ 'ajx_confirmation' ][ 'ty_url' ]) |
| 585 |
){ |
| 586 |
jQuery( 'body' ).trigger( 'wpbc_booking_created', [ response_data[ 'resource_id' ] , response_data ] ); // FixIn: 10.0.0.30. |
| 587 |
window.location.href = response_data[ 'ajx_confirmation' ][ 'ty_url' ]; |
| 588 |
return; |
| 589 |
} |
| 590 |
|
| 591 |
var resource_id = response_data[ 'resource_id' ] |
| 592 |
var confirm_content =''; |
| 593 |
|
| 594 |
if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'ty_message' ]) ){ |
| 595 |
response_data[ 'ajx_confirmation' ][ 'ty_message' ] = ''; |
| 596 |
} |
| 597 |
if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'ty_payment_payment_description' ] ) ){ |
| 598 |
response_data[ 'ajx_confirmation' ][ 'ty_payment_payment_description' ] = ''; |
| 599 |
} |
| 600 |
if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'payment_cost' ] ) ){ |
| 601 |
response_data[ 'ajx_confirmation' ][ 'payment_cost' ] = ''; |
| 602 |
} |
| 603 |
if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'ty_payment_gateways' ] ) ){ |
| 604 |
response_data[ 'ajx_confirmation' ][ 'ty_payment_gateways' ] = ''; |
| 605 |
} |
| 606 |
var ty_message_hide = ('' == response_data[ 'ajx_confirmation' ][ 'ty_message' ]) ? 'wpbc_ty_hide' : ''; |
| 607 |
var ty_payment_payment_description_hide = ('' == response_data[ 'ajx_confirmation' ][ 'ty_payment_payment_description' ].replace( /\\n/g, '' )) ? 'wpbc_ty_hide' : ''; |
| 608 |
var ty_booking_costs_hide = ('' == response_data[ 'ajx_confirmation' ][ 'payment_cost' ]) ? 'wpbc_ty_hide' : ''; |
| 609 |
var ty_payment_gateways_hide = ('' == response_data[ 'ajx_confirmation' ][ 'ty_payment_gateways' ].replace( /\\n/g, '' )) ? 'wpbc_ty_hide' : ''; |
| 610 |
|
| 611 |
if ( 'wpbc_ty_hide' != ty_payment_gateways_hide ){ |
| 612 |
jQuery( '.wpbc_ty__content_text.wpbc_ty__content_gateways' ).html( '' ); // Reset all other possible gateways before showing new one. |
| 613 |
} |
| 614 |
|
| 615 |
confirm_content += `<div id="wpbc_scroll_point_${resource_id}"></div>`; |
| 616 |
confirm_content += ` <div class="wpbc_after_booking_thank_you_section">`; |
| 617 |
confirm_content += ` <div class="wpbc_ty__message ${ty_message_hide}">${response_data[ 'ajx_confirmation' ][ 'ty_message' ]}</div>`; |
| 618 |
confirm_content += ` <div class="wpbc_ty__container">`; |
| 619 |
if ( '' !== response_data[ 'ajx_confirmation' ][ 'ty_message_booking_id' ] ){ |
| 620 |
confirm_content += ` <div class="wpbc_ty__header">${response_data[ 'ajx_confirmation' ][ 'ty_message_booking_id' ]}</div>`; |
| 621 |
} |
| 622 |
confirm_content += ` <div class="wpbc_ty__content">`; |
| 623 |
confirm_content += ` <div class="wpbc_ty__content_text wpbc_ty__payment_description ${ty_payment_payment_description_hide}">${response_data[ 'ajx_confirmation' ][ 'ty_payment_payment_description' ].replace( /\\n/g, '' )}</div>`; |
| 624 |
if ( '' !== response_data[ 'ajx_confirmation' ][ 'ty_customer_details' ] ){ |
| 625 |
confirm_content += ` <div class="wpbc_ty__content_text wpbc_cols_2">${response_data['ajx_confirmation']['ty_customer_details']}</div>`; |
| 626 |
} |
| 627 |
if ( '' !== response_data[ 'ajx_confirmation' ][ 'ty_booking_details' ] ){ |
| 628 |
confirm_content += ` <div class="wpbc_ty__content_text wpbc_cols_2">${response_data['ajx_confirmation']['ty_booking_details']}</div>`; |
| 629 |
} |
| 630 |
confirm_content += ` <div class="wpbc_ty__content_text wpbc_ty__content_costs ${ty_booking_costs_hide}">${response_data[ 'ajx_confirmation' ][ 'ty_booking_costs' ]}</div>`; |
| 631 |
confirm_content += ` <div class="wpbc_ty__content_text wpbc_ty__content_gateways ${ty_payment_gateways_hide}">${response_data[ 'ajx_confirmation' ][ 'ty_payment_gateways' ].replace( /\\n/g, '' ).replace( /ajax_script/gi, 'script' )}</div>`; |
| 632 |
confirm_content += ` </div>`; |
| 633 |
confirm_content += ` </div>`; |
| 634 |
confirm_content += `</div>`; |
| 635 |
|
| 636 |
jQuery( '#booking_form' + resource_id ).after( confirm_content ); |
| 637 |
|
| 638 |
|
| 639 |
//FixIn: 10.0.0.30 // event name // Resource ID - '1' |
| 640 |
jQuery( 'body' ).trigger( 'wpbc_booking_created', [ resource_id , response_data ] ); |
| 641 |
// To catch this event: jQuery( 'body' ).on('wpbc_booking_created', function( event, resource_id, params ) { console.log( event, resource_id, params ); } ); |
| 642 |
} |
| 643 |
|