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