| 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 |
// Start Ajax |
| 36 |
jQuery.post( wpbc_url_ajax, |
| 37 |
{ |
| 38 |
action : 'WPBC_AJX_BOOKING__CREATE', |
| 39 |
wpbc_ajx_user_id: _wpbc.get_secure_param( 'user_id' ), |
| 40 |
nonce : _wpbc.get_secure_param( 'nonce' ), |
| 41 |
wpbc_ajx_locale : _wpbc.get_secure_param( 'locale' ), |
| 42 |
|
| 43 |
calendar_request_params : params |
| 44 |
|
| 45 |
/** |
| 46 |
* Usually params = { 'resource_id' : resource_id, |
| 47 |
* 'dates_ddmmyy_csv' : document.getElementById( 'date_booking' + resource_id ).value, |
| 48 |
* 'formdata' : formdata, |
| 49 |
* 'booking_hash' : my_booking_hash, |
| 50 |
* 'custom_form' : my_booking_form, |
| 51 |
* |
| 52 |
* 'captcha_chalange' : captcha_chalange, |
| 53 |
* 'user_captcha' : user_captcha, |
| 54 |
* |
| 55 |
* 'is_emails_send' : is_send_emeils, |
| 56 |
* 'active_locale' : wpdev_active_locale |
| 57 |
* } |
| 58 |
*/ |
| 59 |
}, |
| 60 |
|
| 61 |
/** |
| 62 |
* S u c c e s s |
| 63 |
* |
| 64 |
* @param response_data - its object returned from Ajax - class-live-searcg.php |
| 65 |
* @param textStatus - 'success' |
| 66 |
* @param jqXHR - Object |
| 67 |
*/ |
| 68 |
function ( response_data, textStatus, jqXHR ) { |
| 69 |
console.log( ' == Response WPBC_AJX_BOOKING__CREATE == ' ); |
| 70 |
for ( var obj_key in response_data ){ |
| 71 |
console.groupCollapsed( '==' + obj_key + '==' ); |
| 72 |
console.log( ' : ' + obj_key + ' : ', response_data[ obj_key ] ); |
| 73 |
console.groupEnd(); |
| 74 |
} |
| 75 |
console.groupEnd(); |
| 76 |
|
| 77 |
|
| 78 |
// <editor-fold defaultstate="collapsed" desc=" = Error Message! Server response with String. -> E_X_I_T " > |
| 79 |
// ------------------------------------------------------------------------------------------------- |
| 80 |
// This section execute, when server response with String instead of Object -- Usually it's because of mistake in code ! |
| 81 |
// ------------------------------------------------------------------------------------------------- |
| 82 |
if ( (typeof response_data !== 'object') || (response_data === null) ){ |
| 83 |
|
| 84 |
var calendar_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data ); |
| 85 |
var jq_node = '#booking_form' + calendar_id; |
| 86 |
|
| 87 |
if ( '' == response_data ){ |
| 88 |
response_data = '<strong>' + 'Error! Server respond with empty string!' + '</strong> ' ; |
| 89 |
} |
| 90 |
// Show Message |
| 91 |
wpbc_front_end__show_message( response_data , { 'type' : 'error', |
| 92 |
'show_here': {'jq_node': jq_node, 'where': 'after'}, |
| 93 |
'is_append': true, |
| 94 |
'style' : 'text-align:left;', |
| 95 |
'delay' : 0 |
| 96 |
} ); |
| 97 |
// Enable Submit | Hide spin loader |
| 98 |
wpbc_booking_form__on_response__ui_elements_enable( calendar_id ); |
| 99 |
return; |
| 100 |
} |
| 101 |
// </editor-fold> |
| 102 |
|
| 103 |
|
| 104 |
// <editor-fold defaultstate="collapsed" desc=" == This section execute, when we have KNOWN errors from Booking Calendar. -> E_X_I_T " > |
| 105 |
// ------------------------------------------------------------------------------------------------- |
| 106 |
// This section execute, when we have KNOWN errors from Booking Calendar |
| 107 |
// ------------------------------------------------------------------------------------------------- |
| 108 |
|
| 109 |
if ( 'ok' != response_data[ 'ajx_data' ][ 'status' ] ) { |
| 110 |
|
| 111 |
switch ( response_data[ 'ajx_data' ][ 'status_error' ] ){ |
| 112 |
|
| 113 |
case 'captcha_simple_wrong': |
| 114 |
wpbc_captcha__simple__update( { |
| 115 |
'resource_id': response_data[ 'resource_id' ], |
| 116 |
'url' : response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'url' ], |
| 117 |
'challenge' : response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'challenge' ], |
| 118 |
'message' : response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ) |
| 119 |
} |
| 120 |
); |
| 121 |
break; |
| 122 |
|
| 123 |
case 'resource_id_incorrect': // Show Error Message - incorrect booking resource ID during submit of booking. |
| 124 |
var message_id = wpbc_front_end__show_message( response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ), |
| 125 |
{ |
| 126 |
'type' : ('undefined' !== typeof (response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ])) |
| 127 |
? response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ] : 'warning', |
| 128 |
'delay' : 0, |
| 129 |
'show_here': { 'where': 'after', 'jq_node': '#booking_form' + params[ 'resource_id' ] } |
| 130 |
} ); |
| 131 |
break; |
| 132 |
|
| 133 |
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 |
| 134 |
var message_id = wpbc_front_end__show_message( response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ), |
| 135 |
{ |
| 136 |
'type' : ('undefined' !== typeof (response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ])) |
| 137 |
? response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ] : 'warning', |
| 138 |
'delay' : 0, |
| 139 |
'show_here': { 'where': 'after', 'jq_node': '#booking_form' + params[ 'resource_id' ] } |
| 140 |
} ); |
| 141 |
|
| 142 |
// Enable Submit | Hide spin loader |
| 143 |
wpbc_booking_form__on_response__ui_elements_enable( response_data[ 'resource_id' ] ); |
| 144 |
|
| 145 |
break; |
| 146 |
|
| 147 |
|
| 148 |
default: |
| 149 |
|
| 150 |
// <editor-fold defaultstate="collapsed" desc=" = For debug only ? -- Show Message under the form = " > |
| 151 |
// -------------------------------------------------------------------------------------------------------------------------------- |
| 152 |
if ( |
| 153 |
( 'undefined' !== typeof (response_data[ 'ajx_data' ][ 'ajx_after_action_message' ]) ) |
| 154 |
&& ( '' != response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ) ) |
| 155 |
){ |
| 156 |
|
| 157 |
var calendar_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data ); |
| 158 |
var jq_node = '#booking_form' + calendar_id; |
| 159 |
|
| 160 |
var ajx_after_booking_message = response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ); |
| 161 |
|
| 162 |
console.log( ajx_after_booking_message ); |
| 163 |
|
| 164 |
/** |
| 165 |
* // Show Message |
| 166 |
var ajx_after_action_message_id = wpbc_front_end__show_message( ajx_after_booking_message, |
| 167 |
{ |
| 168 |
'type' : ('undefined' !== typeof (response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ])) |
| 169 |
? response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ] : 'info', |
| 170 |
'delay' : 10000, |
| 171 |
'show_here': { |
| 172 |
'jq_node': jq_node, |
| 173 |
'where' : 'after' |
| 174 |
} |
| 175 |
} ); |
| 176 |
*/ |
| 177 |
} |
| 178 |
// </editor-fold> |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
// ------------------------------------------------------------------------------------------------- |
| 183 |
// Reactivate calendar again ? |
| 184 |
// ------------------------------------------------------------------------------------------------- |
| 185 |
// Enable Submit | Hide spin loader |
| 186 |
wpbc_booking_form__on_response__ui_elements_enable( response_data[ 'resource_id' ] ); |
| 187 |
|
| 188 |
// Unselect dates |
| 189 |
wpbc_calendar__unselect_all_dates( response_data[ 'resource_id' ] ); |
| 190 |
|
| 191 |
// 'resource_id' => $params['resource_id'], |
| 192 |
// 'booking_hash' => $booking_hash, |
| 193 |
// 'request_uri' => $_SERVER['REQUEST_URI'], // Is it the same as window.location.href or |
| 194 |
// 'custom_form' => $params['custom_form'], // Optional. |
| 195 |
// 'aggregate_resource_id_str' => implode( ',', $params['aggregate_resource_id_arr'] ) // Optional. Resource ID from aggregate parameter in shortcode. |
| 196 |
|
| 197 |
// Load new data in calendar. |
| 198 |
wpbc_calendar__load_data__ajx( { |
| 199 |
'resource_id' : response_data[ 'resource_id' ] // It's from response ...AJX_BOOKING__CREATE of initial sent resource_id |
| 200 |
, 'booking_hash': response_data[ 'ajx_cleaned_params' ]['booking_hash'] // ?? we can not use it, because HASH chnaged in any case! |
| 201 |
, 'request_uri' : response_data[ 'ajx_cleaned_params' ]['request_uri'] |
| 202 |
, 'custom_form' : response_data[ 'ajx_cleaned_params' ]['custom_form'] |
| 203 |
// Aggregate booking resources, if any ? |
| 204 |
, 'aggregate_resource_id_str' : _wpbc.booking__get_param_value( response_data[ 'resource_id' ], 'aggregate_resource_id_arr' ).join(',') |
| 205 |
|
| 206 |
} ); |
| 207 |
// Exit |
| 208 |
return; |
| 209 |
} |
| 210 |
|
| 211 |
// </editor-fold> |
| 212 |
|
| 213 |
|
| 214 |
/* |
| 215 |
// Show Calendar |
| 216 |
wpbc_calendar__loading__stop( response_data[ 'resource_id' ] ); |
| 217 |
|
| 218 |
// ------------------------------------------------------------------------------------------------- |
| 219 |
// Bookings - Dates |
| 220 |
_wpbc.bookings_in_calendar__set_dates( response_data[ 'resource_id' ], response_data[ 'ajx_data' ]['dates'] ); |
| 221 |
|
| 222 |
// Bookings - Child or only single booking resource in dates |
| 223 |
_wpbc.booking__set_param_value( response_data[ 'resource_id' ], 'resources_id_arr__in_dates', response_data[ 'ajx_data' ][ 'resources_id_arr__in_dates' ] ); |
| 224 |
// ------------------------------------------------------------------------------------------------- |
| 225 |
|
| 226 |
// Update calendar |
| 227 |
wpbc_calendar__update_look( response_data[ 'resource_id' ] ); |
| 228 |
*/ |
| 229 |
|
| 230 |
// Hide spin loader |
| 231 |
wpbc_booking_form__spin_loader__hide( response_data[ 'resource_id' ] ); |
| 232 |
|
| 233 |
// Hide booking form |
| 234 |
wpbc_booking_form__animated__hide( response_data[ 'resource_id' ] ); |
| 235 |
|
| 236 |
// Show Confirmation | Payment section |
| 237 |
wpbc_show_thank_you_message_after_booking( response_data ); |
| 238 |
|
| 239 |
setTimeout( function (){ |
| 240 |
wpbc_do_scroll( '#wpbc_scroll_point_' + response_data[ 'resource_id' ], 10 ); |
| 241 |
}, 500 ); |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
} |
| 246 |
).fail( |
| 247 |
// <editor-fold defaultstate="collapsed" desc=" = This section execute, when NONCE field was not passed or some error happened at server! = " > |
| 248 |
function ( jqXHR, textStatus, errorThrown ) { if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); } |
| 249 |
|
| 250 |
// ------------------------------------------------------------------------------------------------- |
| 251 |
// This section execute, when NONCE field was not passed or some error happened at server! |
| 252 |
// ------------------------------------------------------------------------------------------------- |
| 253 |
|
| 254 |
// Get Content of Error Message |
| 255 |
var error_message = '<strong>' + 'Error!' + '</strong> ' + errorThrown ; |
| 256 |
if ( jqXHR.status ){ |
| 257 |
error_message += ' (<b>' + jqXHR.status + '</b>)'; |
| 258 |
if (403 == jqXHR.status ){ |
| 259 |
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>.'; |
| 260 |
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>' |
| 261 |
} |
| 262 |
} |
| 263 |
if ( jqXHR.responseText ){ |
| 264 |
// Escape tags in Error message |
| 265 |
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, "&") |
| 266 |
.replace(/</g, "<") |
| 267 |
.replace(/>/g, ">") |
| 268 |
.replace(/"/g, """) |
| 269 |
.replace(/'/g, "'") |
| 270 |
+'</div>'; |
| 271 |
} |
| 272 |
error_message = error_message.replace( /\n/g, "<br />" ); |
| 273 |
|
| 274 |
var calendar_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data ); |
| 275 |
var jq_node = '#booking_form' + calendar_id; |
| 276 |
|
| 277 |
// Show Message |
| 278 |
wpbc_front_end__show_message( error_message , { 'type' : 'error', |
| 279 |
'show_here': {'jq_node': jq_node, 'where': 'after'}, |
| 280 |
'is_append': true, |
| 281 |
'style' : 'text-align:left;', |
| 282 |
'delay' : 0 |
| 283 |
} ); |
| 284 |
// Enable Submit | Hide spin loader |
| 285 |
wpbc_booking_form__on_response__ui_elements_enable( calendar_id ); |
| 286 |
} |
| 287 |
// </editor-fold> |
| 288 |
) |
| 289 |
// .done( function ( data, textStatus, jqXHR ) { if ( window.console && window.console.log ){ console.log( 'second success', data, textStatus, jqXHR ); } }) |
| 290 |
// .always( function ( data_jqXHR, textStatus, jqXHR_errorThrown ) { if ( window.console && window.console.log ){ console.log( 'always finished', data_jqXHR, textStatus, jqXHR_errorThrown ); } }) |
| 291 |
; // End Ajax |
| 292 |
|
| 293 |
return true; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
// <editor-fold defaultstate="collapsed" desc=" == CAPTCHA == " > |
| 298 |
|
| 299 |
/** |
| 300 |
* Update image in captcha and show warning message |
| 301 |
* |
| 302 |
* @param params |
| 303 |
* |
| 304 |
* Example of 'params' : { |
| 305 |
* 'resource_id': response_data[ 'resource_id' ], |
| 306 |
* 'url' : response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'url' ], |
| 307 |
* 'challenge' : response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'challenge' ], |
| 308 |
* 'message' : response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ) |
| 309 |
* } |
| 310 |
*/ |
| 311 |
function wpbc_captcha__simple__update( params ){ |
| 312 |
|
| 313 |
document.getElementById( 'captcha_input' + params[ 'resource_id' ] ).value = ''; |
| 314 |
document.getElementById( 'captcha_img' + params[ 'resource_id' ] ).src = params[ 'url' ]; |
| 315 |
document.getElementById( 'wpdev_captcha_challenge_' + params[ 'resource_id' ] ).value = params[ 'challenge' ]; |
| 316 |
|
| 317 |
// Show warning After CAPTCHA Img |
| 318 |
var message_id = wpbc_front_end__show_message__warning( '#captcha_input' + params[ 'resource_id' ] + ' + img', params[ 'message' ] ); |
| 319 |
|
| 320 |
// Animate |
| 321 |
jQuery( '#' + message_id + ', ' + '#captcha_input' + params[ 'resource_id' ] ).fadeOut( 350 ).fadeIn( 300 ).fadeOut( 350 ).fadeIn( 400 ).animate( {opacity: 1}, 4000 ); |
| 322 |
// Focus text field |
| 323 |
jQuery( '#captcha_input' + params[ 'resource_id' ] ).trigger( 'focus' ); //FixIn: 8.7.11.12 |
| 324 |
|
| 325 |
|
| 326 |
// Enable Submit | Hide spin loader |
| 327 |
wpbc_booking_form__on_response__ui_elements_enable( params[ 'resource_id' ] ); |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
/** |
| 332 |
* If the captcha elements not exist in the booking form, then remove parameters relative captcha |
| 333 |
* @param params |
| 334 |
* @returns obj |
| 335 |
*/ |
| 336 |
function wpbc_captcha__simple__maybe_remove_in_ajx_params( params ){ |
| 337 |
|
| 338 |
if ( ! wpbc_captcha__simple__is_exist_in_form( params[ 'resource_id' ] ) ){ |
| 339 |
delete params[ 'captcha_chalange' ]; |
| 340 |
delete params[ 'captcha_user_input' ]; |
| 341 |
} |
| 342 |
return params; |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
/** |
| 347 |
* Check if CAPTCHA exist in the booking form |
| 348 |
* @param resource_id |
| 349 |
* @returns {boolean} |
| 350 |
*/ |
| 351 |
function wpbc_captcha__simple__is_exist_in_form( resource_id ){ |
| 352 |
|
| 353 |
return ( |
| 354 |
(0 !== jQuery( '#wpdev_captcha_challenge_' + resource_id ).length) |
| 355 |
|| (0 !== jQuery( '#captcha_input' + resource_id ).length) |
| 356 |
); |
| 357 |
} |
| 358 |
|
| 359 |
// </editor-fold> |
| 360 |
|
| 361 |
|
| 362 |
// <editor-fold defaultstate="collapsed" desc=" == Send Button | Form Spin Loader == " > |
| 363 |
|
| 364 |
/** |
| 365 |
* Disable Send button | Show Spin Loader |
| 366 |
* |
| 367 |
* @param resource_id |
| 368 |
*/ |
| 369 |
function wpbc_booking_form__on_submit__ui_elements_disable( resource_id ){ |
| 370 |
|
| 371 |
// Disable Submit |
| 372 |
wpbc_booking_form__send_button__disable( resource_id ); |
| 373 |
|
| 374 |
// Show Spin loader in booking form |
| 375 |
wpbc_booking_form__spin_loader__show( resource_id ); |
| 376 |
} |
| 377 |
|
| 378 |
/** |
| 379 |
* Enable Send button | Hide Spin Loader |
| 380 |
* |
| 381 |
* @param resource_id |
| 382 |
*/ |
| 383 |
function wpbc_booking_form__on_response__ui_elements_enable(resource_id){ |
| 384 |
|
| 385 |
// Enable Submit |
| 386 |
wpbc_booking_form__send_button__enable( resource_id ); |
| 387 |
|
| 388 |
// Hide Spin loader in booking form |
| 389 |
wpbc_booking_form__spin_loader__hide( resource_id ); |
| 390 |
} |
| 391 |
|
| 392 |
/** |
| 393 |
* Enable Submit button |
| 394 |
* @param resource_id |
| 395 |
*/ |
| 396 |
function wpbc_booking_form__send_button__enable( resource_id ){ |
| 397 |
|
| 398 |
// Activate Send button |
| 399 |
jQuery( '#booking_form_div' + resource_id + ' input[type=button]' ).prop( "disabled", false ); |
| 400 |
jQuery( '#booking_form_div' + resource_id + ' button' ).prop( "disabled", false ); |
| 401 |
} |
| 402 |
|
| 403 |
/** |
| 404 |
* Disable Submit button and show spin |
| 405 |
* |
| 406 |
* @param resource_id |
| 407 |
*/ |
| 408 |
function wpbc_booking_form__send_button__disable( resource_id ){ |
| 409 |
|
| 410 |
// Disable Send button |
| 411 |
jQuery( '#booking_form_div' + resource_id + ' input[type=button]' ).prop( "disabled", true ); |
| 412 |
jQuery( '#booking_form_div' + resource_id + ' button' ).prop( "disabled", true ); |
| 413 |
} |
| 414 |
|
| 415 |
/** |
| 416 |
* Show booking form Spin Loader |
| 417 |
* @param resource_id |
| 418 |
*/ |
| 419 |
function wpbc_booking_form__spin_loader__show( resource_id ){ |
| 420 |
|
| 421 |
// Show Spin Loader |
| 422 |
jQuery( '#booking_form' + resource_id ).after( |
| 423 |
'<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_spins_loader_mini"></div></div></div>' |
| 424 |
); |
| 425 |
} |
| 426 |
|
| 427 |
/** |
| 428 |
* Remove / Hide booking form Spin Loader |
| 429 |
* @param resource_id |
| 430 |
*/ |
| 431 |
function wpbc_booking_form__spin_loader__hide( resource_id ){ |
| 432 |
|
| 433 |
// Remove Spin Loader |
| 434 |
jQuery( '#wpbc_booking_form_spin_loader' + resource_id ).remove(); |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
/** |
| 439 |
* Hide booking form wth animation |
| 440 |
* |
| 441 |
* @param resource_id |
| 442 |
*/ |
| 443 |
function wpbc_booking_form__animated__hide( resource_id ){ |
| 444 |
|
| 445 |
// jQuery( '#booking_form' + resource_id ).slideUp( 1000 |
| 446 |
// , function (){ |
| 447 |
// |
| 448 |
// // if ( document.getElementById( 'gateway_payment_forms' + response_data[ 'resource_id' ] ) != null ){ |
| 449 |
// // wpbc_do_scroll( '#submiting' + resource_id ); |
| 450 |
// // } else |
| 451 |
// if ( jQuery( '#booking_form' + resource_id ).parent().find( '.submiting_content' ).length > 0 ){ |
| 452 |
// //wpbc_do_scroll( '#booking_form' + resource_id + ' + .submiting_content' ); |
| 453 |
// |
| 454 |
// var hideTimeout = setTimeout(function () { |
| 455 |
// wpbc_do_scroll( jQuery( '#booking_form' + resource_id ).parent().find( '.submiting_content' ).get( 0 ) ); |
| 456 |
// }, 100); |
| 457 |
// |
| 458 |
// } |
| 459 |
// } |
| 460 |
// ); |
| 461 |
|
| 462 |
jQuery( '#booking_form' + resource_id ).hide(); |
| 463 |
|
| 464 |
// var hideTimeout = setTimeout( function (){ |
| 465 |
// |
| 466 |
// if ( jQuery( '#booking_form' + resource_id ).parent().find( '.submiting_content' ).length > 0 ){ |
| 467 |
// var random_id = Math.floor( (Math.random() * 10000) + 1 ); |
| 468 |
// jQuery( '#booking_form' + resource_id ).parent().before( '<div id="scroll_to' + random_id + '"></div>' ); |
| 469 |
// console.log( jQuery( '#scroll_to' + random_id ) ); |
| 470 |
// |
| 471 |
// wpbc_do_scroll( '#scroll_to' + random_id ); |
| 472 |
// //wpbc_do_scroll( jQuery( '#booking_form' + resource_id ).parent().get( 0 ) ); |
| 473 |
// } |
| 474 |
// }, 500 ); |
| 475 |
} |
| 476 |
// </editor-fold> |
| 477 |
|
| 478 |
|
| 479 |
// <editor-fold defaultstate="collapsed" desc=" == Mini Spin Loader == " > |
| 480 |
|
| 481 |
/** |
| 482 |
* Show mini Spin Loader |
| 483 |
* @param parent_html_id |
| 484 |
*/ |
| 485 |
function wpbc__spin_loader__mini__show( parent_html_id , color = '#0071ce' ){ |
| 486 |
|
| 487 |
if ( ('undefined' !== typeof (color)) && ('' != color) ){ |
| 488 |
color = 'border-color:' + color + ';'; |
| 489 |
} |
| 490 |
// Show Spin Loader |
| 491 |
jQuery( '#' + parent_html_id ).after( |
| 492 |
'<div id="wpbc_mini_spin_loader' + parent_html_id + '" class="wpbc_booking_form_spin_loader" style="position: relative;min-height: 2.8rem;"><div class="wpbc_spins_loader_wrapper"><div class="wpbc_one_spin_loader_mini 0wpbc_spins_loader_mini" style="'+color+'"></div></div></div>' |
| 493 |
); |
| 494 |
} |
| 495 |
|
| 496 |
/** |
| 497 |
* Remove / Hide mini Spin Loader |
| 498 |
* @param parent_html_id |
| 499 |
*/ |
| 500 |
function wpbc__spin_loader__mini__hide( parent_html_id ){ |
| 501 |
|
| 502 |
// Remove Spin Loader |
| 503 |
jQuery( '#wpbc_mini_spin_loader' + parent_html_id ).remove(); |
| 504 |
} |
| 505 |
|
| 506 |
// </editor-fold> |
| 507 |
|
| 508 |
//TODO: what about showing only Thank you. message without payment forms. |
| 509 |
/** |
| 510 |
* Show 'Thank you'. message and payment forms |
| 511 |
* |
| 512 |
* @param response_data |
| 513 |
*/ |
| 514 |
function wpbc_show_thank_you_message_after_booking( response_data ){ |
| 515 |
|
| 516 |
if ( |
| 517 |
('undefined' !== typeof (response_data[ 'ajx_confirmation' ][ 'ty_is_redirect' ])) |
| 518 |
&& ('undefined' !== typeof (response_data[ 'ajx_confirmation' ][ 'ty_url' ])) |
| 519 |
&& ('page' == response_data[ 'ajx_confirmation' ][ 'ty_is_redirect' ]) |
| 520 |
&& ('' != response_data[ 'ajx_confirmation' ][ 'ty_url' ]) |
| 521 |
){ |
| 522 |
jQuery( 'body' ).trigger( 'wpbc_booking_created', [ response_data[ 'resource_id' ] , response_data ] ); //FixIn: 10.0.0.30 |
| 523 |
window.location.href = response_data[ 'ajx_confirmation' ][ 'ty_url' ]; |
| 524 |
return; |
| 525 |
} |
| 526 |
|
| 527 |
var resource_id = response_data[ 'resource_id' ] |
| 528 |
var confirm_content =''; |
| 529 |
|
| 530 |
if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'ty_message' ]) ){ |
| 531 |
response_data[ 'ajx_confirmation' ][ 'ty_message' ] = ''; |
| 532 |
} |
| 533 |
if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'ty_payment_payment_description' ] ) ){ |
| 534 |
response_data[ 'ajx_confirmation' ][ 'ty_payment_payment_description' ] = ''; |
| 535 |
} |
| 536 |
if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'payment_cost' ] ) ){ |
| 537 |
response_data[ 'ajx_confirmation' ][ 'payment_cost' ] = ''; |
| 538 |
} |
| 539 |
if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'ty_payment_gateways' ] ) ){ |
| 540 |
response_data[ 'ajx_confirmation' ][ 'ty_payment_gateways' ] = ''; |
| 541 |
} |
| 542 |
var ty_message_hide = ('' == response_data[ 'ajx_confirmation' ][ 'ty_message' ]) ? 'wpbc_ty_hide' : ''; |
| 543 |
var ty_payment_payment_description_hide = ('' == response_data[ 'ajx_confirmation' ][ 'ty_payment_payment_description' ].replace( /\\n/g, '' )) ? 'wpbc_ty_hide' : ''; |
| 544 |
var ty_booking_costs_hide = ('' == response_data[ 'ajx_confirmation' ][ 'payment_cost' ]) ? 'wpbc_ty_hide' : ''; |
| 545 |
var ty_payment_gateways_hide = ('' == response_data[ 'ajx_confirmation' ][ 'ty_payment_gateways' ].replace( /\\n/g, '' )) ? 'wpbc_ty_hide' : ''; |
| 546 |
|
| 547 |
if ( 'wpbc_ty_hide' != ty_payment_gateways_hide ){ |
| 548 |
jQuery( '.wpbc_ty__content_text.wpbc_ty__content_gateways' ).html( '' ); // Reset all other possible gateways before showing new one. |
| 549 |
} |
| 550 |
|
| 551 |
confirm_content += `<div id="wpbc_scroll_point_${resource_id}"></div>`; |
| 552 |
confirm_content += ` <div class="wpbc_after_booking_thank_you_section">`; |
| 553 |
confirm_content += ` <div class="wpbc_ty__message ${ty_message_hide}">${response_data[ 'ajx_confirmation' ][ 'ty_message' ]}</div>`; |
| 554 |
confirm_content += ` <div class="wpbc_ty__container">`; |
| 555 |
confirm_content += ` <div class="wpbc_ty__header">${response_data['ajx_confirmation']['ty_message_booking_id']}</div>`; |
| 556 |
confirm_content += ` <div class="wpbc_ty__content">`; |
| 557 |
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>`; |
| 558 |
confirm_content += ` <div class="wpbc_ty__content_text wpbc_cols_2">${response_data['ajx_confirmation']['ty_customer_details']}</div>`; |
| 559 |
confirm_content += ` <div class="wpbc_ty__content_text wpbc_cols_2">${response_data['ajx_confirmation']['ty_booking_details']}</div>`; |
| 560 |
confirm_content += ` <div class="wpbc_ty__content_text wpbc_ty__content_costs ${ty_booking_costs_hide}">${response_data[ 'ajx_confirmation' ][ 'ty_booking_costs' ]}</div>`; |
| 561 |
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>`; |
| 562 |
confirm_content += ` </div>`; |
| 563 |
confirm_content += ` </div>`; |
| 564 |
confirm_content += `</div>`; |
| 565 |
|
| 566 |
jQuery( '#booking_form' + resource_id ).after( confirm_content ); |
| 567 |
|
| 568 |
|
| 569 |
//FixIn: 10.0.0.30 // event name // Resource ID - '1' |
| 570 |
jQuery( 'body' ).trigger( 'wpbc_booking_created', [ resource_id , response_data ] ); |
| 571 |
// To catch this event: jQuery( 'body' ).on('wpbc_booking_created', function( event, resource_id, params ) { console.log( event, resource_id, params ); } ); |
| 572 |
} |
| 573 |
|