PluginProbe
Booking Calendar / 10.10.2
Booking Calendar v10.10.2
11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 All 203 releases
booking / includes / _capacity / _src / create_booking.js

create_booking.js in Booking Calendar 10.10.2, at includes/_capacity/_src/create_booking.js

647 lines 27.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 setTimeout( function (){
241 wpbc_do_scroll( '#wpbc_scroll_point_' + response_data[ 'resource_id' ], 10 );
242 }, 500 );
243
244
245
246 }
247 ).fail(
248 // <editor-fold defaultstate="collapsed" desc=" = This section execute, when NONCE field was not passed or some error happened at server! = " >
249 function ( jqXHR, textStatus, errorThrown ) { if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); }
250
251 // -------------------------------------------------------------------------------------------------
252 // This section execute, when NONCE field was not passed or some error happened at server!
253 // -------------------------------------------------------------------------------------------------
254
255 // Get Content of Error Message
256 var error_message = '<strong>' + 'Error!' + '</strong> ' + errorThrown ;
257 if ( jqXHR.status ){
258 error_message += ' (<b>' + jqXHR.status + '</b>)';
259 if (403 == jqXHR.status ){
260 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>.';
261 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>'
262 }
263 }
264 if ( jqXHR.responseText ){
265 // Escape tags in Error message
266 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, "&amp;")
267 .replace(/</g, "&lt;")
268 .replace(/>/g, "&gt;")
269 .replace(/"/g, "&quot;")
270 .replace(/'/g, "&#39;")
271 +'</div>';
272 }
273 error_message = error_message.replace( /\n/g, "<br />" );
274
275 var calendar_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data );
276 var jq_node = '#booking_form' + calendar_id;
277
278 // Show Message
279 wpbc_front_end__show_message( error_message , { 'type' : 'error',
280 'show_here': {'jq_node': jq_node, 'where': 'after'},
281 'is_append': true,
282 'style' : 'text-align:left;',
283 'delay' : 0
284 } );
285 // Enable Submit | Hide spin loader
286 wpbc_booking_form__on_response__ui_elements_enable( calendar_id );
287 }
288 // </editor-fold>
289 )
290 // .done( function ( data, textStatus, jqXHR ) { if ( window.console && window.console.log ){ console.log( 'second success', data, textStatus, jqXHR ); } })
291 // .always( function ( data_jqXHR, textStatus, jqXHR_errorThrown ) { if ( window.console && window.console.log ){ console.log( 'always finished', data_jqXHR, textStatus, jqXHR_errorThrown ); } })
292 ; // End Ajax
293
294 return true;
295 }
296
297
298 // <editor-fold defaultstate="collapsed" desc=" == CAPTCHA == " >
299
300 /**
301 * Update image in captcha and show warning message
302 *
303 * @param params
304 *
305 * Example of 'params' : {
306 * 'resource_id': response_data[ 'resource_id' ],
307 * 'url' : response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'url' ],
308 * 'challenge' : response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'challenge' ],
309 * 'message' : response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" )
310 * }
311 */
312 function wpbc_captcha__simple__update( params ){
313
314 document.getElementById( 'captcha_input' + params[ 'resource_id' ] ).value = '';
315 document.getElementById( 'captcha_img' + params[ 'resource_id' ] ).src = params[ 'url' ];
316 document.getElementById( 'wpdev_captcha_challenge_' + params[ 'resource_id' ] ).value = params[ 'challenge' ];
317
318 // Show warning After CAPTCHA Img
319 var message_id = wpbc_front_end__show_message__warning( '#captcha_input' + params[ 'resource_id' ] + ' + img', params[ 'message' ] );
320
321 // Animate
322 jQuery( '#' + message_id + ', ' + '#captcha_input' + params[ 'resource_id' ] ).fadeOut( 350 ).fadeIn( 300 ).fadeOut( 350 ).fadeIn( 400 ).animate( {opacity: 1}, 4000 );
323 // Focus text field
324 jQuery( '#captcha_input' + params[ 'resource_id' ] ).trigger( 'focus' ); // FixIn: 8.7.11.12.
325
326
327 // Enable Submit | Hide spin loader
328 wpbc_booking_form__on_response__ui_elements_enable( params[ 'resource_id' ] );
329 }
330
331
332 /**
333 * If the captcha elements not exist in the booking form, then remove parameters relative captcha
334 * @param params
335 * @returns obj
336 */
337 function wpbc_captcha__simple__maybe_remove_in_ajx_params( params ){
338
339 if ( ! wpbc_captcha__simple__is_exist_in_form( params[ 'resource_id' ] ) ){
340 delete params[ 'captcha_chalange' ];
341 delete params[ 'captcha_user_input' ];
342 }
343 return params;
344 }
345
346
347 /**
348 * Check if CAPTCHA exist in the booking form
349 * @param resource_id
350 * @returns {boolean}
351 */
352 function wpbc_captcha__simple__is_exist_in_form( resource_id ){
353
354 return (
355 (0 !== jQuery( '#wpdev_captcha_challenge_' + resource_id ).length)
356 || (0 !== jQuery( '#captcha_input' + resource_id ).length)
357 );
358 }
359
360 // </editor-fold>
361
362
363 // <editor-fold defaultstate="collapsed" desc=" == Send Button | Form Spin Loader == " >
364
365 /**
366 * Disable Send button | Show Spin Loader
367 *
368 * @param resource_id
369 */
370 function wpbc_booking_form__on_submit__ui_elements_disable( resource_id ){
371
372 // Disable Submit
373 wpbc_booking_form__send_button__disable( resource_id );
374
375 // Show Spin loader in booking form
376 wpbc_booking_form__spin_loader__show( resource_id );
377 }
378
379 /**
380 * Enable Send button | Hide Spin Loader
381 *
382 * @param resource_id
383 */
384 function wpbc_booking_form__on_response__ui_elements_enable(resource_id){
385
386 // Enable Submit
387 wpbc_booking_form__send_button__enable( resource_id );
388
389 // Hide Spin loader in booking form
390 wpbc_booking_form__spin_loader__hide( resource_id );
391 }
392
393 /**
394 * Enable Submit button
395 * @param resource_id
396 */
397 function wpbc_booking_form__send_button__enable( resource_id ){
398
399 // Activate Send button
400 jQuery( '#booking_form_div' + resource_id + ' input[type=button]' ).prop( "disabled", false );
401 jQuery( '#booking_form_div' + resource_id + ' button' ).prop( "disabled", false );
402 }
403
404 /**
405 * Disable Submit button and show spin
406 *
407 * @param resource_id
408 */
409 function wpbc_booking_form__send_button__disable( resource_id ){
410
411 // Disable Send button
412 jQuery( '#booking_form_div' + resource_id + ' input[type=button]' ).prop( "disabled", true );
413 jQuery( '#booking_form_div' + resource_id + ' button' ).prop( "disabled", true );
414 }
415
416 /**
417 * Disable 'This' button
418 *
419 * @param _this
420 */
421 function wpbc_booking_form__this_button__disable( _this ){
422
423 // Disable Send button
424 jQuery( _this ).prop( "disabled", true );
425 }
426
427 /**
428 * Show booking form Spin Loader
429 * @param resource_id
430 */
431 function wpbc_booking_form__spin_loader__show( resource_id ){
432
433 // Show Spin Loader
434 jQuery( '#booking_form' + resource_id ).after(
435 '<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>'
436 );
437 }
438
439 /**
440 * Remove / Hide booking form Spin Loader
441 * @param resource_id
442 */
443 function wpbc_booking_form__spin_loader__hide( resource_id ){
444
445 // Remove Spin Loader
446 jQuery( '#wpbc_booking_form_spin_loader' + resource_id ).remove();
447 }
448
449
450 /**
451 * Hide booking form wth animation
452 *
453 * @param resource_id
454 */
455 function wpbc_booking_form__animated__hide( resource_id ){
456
457 // jQuery( '#booking_form' + resource_id ).slideUp( 1000
458 // , function (){
459 //
460 // // if ( document.getElementById( 'gateway_payment_forms' + response_data[ 'resource_id' ] ) != null ){
461 // // wpbc_do_scroll( '#submiting' + resource_id );
462 // // } else
463 // if ( jQuery( '#booking_form' + resource_id ).parent().find( '.submiting_content' ).length > 0 ){
464 // //wpbc_do_scroll( '#booking_form' + resource_id + ' + .submiting_content' );
465 //
466 // var hideTimeout = setTimeout(function () {
467 // wpbc_do_scroll( jQuery( '#booking_form' + resource_id ).parent().find( '.submiting_content' ).get( 0 ) );
468 // }, 100);
469 //
470 // }
471 // }
472 // );
473
474 jQuery( '#booking_form' + resource_id ).hide();
475
476 // var hideTimeout = setTimeout( function (){
477 //
478 // if ( jQuery( '#booking_form' + resource_id ).parent().find( '.submiting_content' ).length > 0 ){
479 // var random_id = Math.floor( (Math.random() * 10000) + 1 );
480 // jQuery( '#booking_form' + resource_id ).parent().before( '<div id="scroll_to' + random_id + '"></div>' );
481 // console.log( jQuery( '#scroll_to' + random_id ) );
482 //
483 // wpbc_do_scroll( '#scroll_to' + random_id );
484 // //wpbc_do_scroll( jQuery( '#booking_form' + resource_id ).parent().get( 0 ) );
485 // }
486 // }, 500 );
487 }
488 // </editor-fold>
489
490
491 // <editor-fold defaultstate="collapsed" desc=" == Mini Spin Loader == " >
492
493 /**
494 *
495 * @param parent_html_id
496 */
497
498 /**
499 * Show micro Spin Loader
500 *
501 * @param id ID of Loader, for later hide it by using wpbc__spin_loader__micro__hide( id ) OR wpbc__spin_loader__mini__hide( id )
502 * @param jq_node_where_insert such as '#estimate_booking_night_cost_hint10' OR '.estimate_booking_night_cost_hint10'
503 */
504 function wpbc__spin_loader__micro__show__inside( id , jq_node_where_insert ){
505
506 wpbc__spin_loader__mini__show( id, {
507 'color' : '#444',
508 'show_here': {
509 'where' : 'inside',
510 'jq_node': jq_node_where_insert
511 },
512 'style' : 'position: relative;display: inline-flex;flex-flow: column nowrap;justify-content: center;align-items: center;margin: 7px 12px;',
513 'class' : 'wpbc_one_spin_loader_micro'
514 } );
515 }
516
517 /**
518 * Remove spinner
519 * @param id
520 */
521 function wpbc__spin_loader__micro__hide( id ){
522 wpbc__spin_loader__mini__hide( id );
523 }
524
525
526 /**
527 * Show mini Spin Loader
528 * @param parent_html_id
529 */
530 function wpbc__spin_loader__mini__show( parent_html_id , params = {} ){
531
532 var params_default = {
533 'color' : '#0071ce',
534 'show_here': {
535 'jq_node': '', // any jQuery node definition
536 'where' : 'after' // 'inside' | 'before' | 'after' | 'right' | 'left'
537 },
538 'style' : 'position: relative;min-height: 2.8rem;',
539 'class' : 'wpbc_one_spin_loader_mini 0wpbc_spins_loader_mini'
540 };
541 for ( var p_key in params ){
542 params_default[ p_key ] = params[ p_key ];
543 }
544 params = params_default;
545
546 if ( ('undefined' !== typeof (params['color'])) && ('' != params['color']) ){
547 params['color'] = 'border-color:' + params['color'] + ';';
548 }
549
550 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>';
551
552 if ( '' == params[ 'show_here' ][ 'jq_node' ] ){
553 params[ 'show_here' ][ 'jq_node' ] = '#' + parent_html_id;
554 }
555
556 // Show Spin Loader
557 if ( 'after' == params[ 'show_here' ][ 'where' ] ){
558 jQuery( params[ 'show_here' ][ 'jq_node' ] ).after( spinner_html );
559 } else {
560 jQuery( params[ 'show_here' ][ 'jq_node' ] ).html( spinner_html );
561 }
562 }
563
564 /**
565 * Remove / Hide mini Spin Loader
566 * @param parent_html_id
567 */
568 function wpbc__spin_loader__mini__hide( parent_html_id ){
569
570 // Remove Spin Loader
571 jQuery( '#wpbc_mini_spin_loader' + parent_html_id ).remove();
572 }
573
574 // </editor-fold>
575
576 //TODO: what about showing only Thank you. message without payment forms.
577 /**
578 * Show 'Thank you'. message and payment forms
579 *
580 * @param response_data
581 */
582 function wpbc_show_thank_you_message_after_booking( response_data ){
583
584 if (
585 ('undefined' !== typeof (response_data[ 'ajx_confirmation' ][ 'ty_is_redirect' ]))
586 && ('undefined' !== typeof (response_data[ 'ajx_confirmation' ][ 'ty_url' ]))
587 && ('page' == response_data[ 'ajx_confirmation' ][ 'ty_is_redirect' ])
588 && ('' != response_data[ 'ajx_confirmation' ][ 'ty_url' ])
589 ){
590 jQuery( 'body' ).trigger( 'wpbc_booking_created', [ response_data[ 'resource_id' ] , response_data ] ); // FixIn: 10.0.0.30.
591 window.location.href = response_data[ 'ajx_confirmation' ][ 'ty_url' ];
592 return;
593 }
594
595 var resource_id = response_data[ 'resource_id' ]
596 var confirm_content ='';
597
598 if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'ty_message' ]) ){
599 response_data[ 'ajx_confirmation' ][ 'ty_message' ] = '';
600 }
601 if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'ty_payment_payment_description' ] ) ){
602 response_data[ 'ajx_confirmation' ][ 'ty_payment_payment_description' ] = '';
603 }
604 if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'payment_cost' ] ) ){
605 response_data[ 'ajx_confirmation' ][ 'payment_cost' ] = '';
606 }
607 if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'ty_payment_gateways' ] ) ){
608 response_data[ 'ajx_confirmation' ][ 'ty_payment_gateways' ] = '';
609 }
610 var ty_message_hide = ('' == response_data[ 'ajx_confirmation' ][ 'ty_message' ]) ? 'wpbc_ty_hide' : '';
611 var ty_payment_payment_description_hide = ('' == response_data[ 'ajx_confirmation' ][ 'ty_payment_payment_description' ].replace( /\\n/g, '' )) ? 'wpbc_ty_hide' : '';
612 var ty_booking_costs_hide = ('' == response_data[ 'ajx_confirmation' ][ 'payment_cost' ]) ? 'wpbc_ty_hide' : '';
613 var ty_payment_gateways_hide = ('' == response_data[ 'ajx_confirmation' ][ 'ty_payment_gateways' ].replace( /\\n/g, '' )) ? 'wpbc_ty_hide' : '';
614
615 if ( 'wpbc_ty_hide' != ty_payment_gateways_hide ){
616 jQuery( '.wpbc_ty__content_text.wpbc_ty__content_gateways' ).html( '' ); // Reset all other possible gateways before showing new one.
617 }
618
619 confirm_content += `<div id="wpbc_scroll_point_${resource_id}"></div>`;
620 confirm_content += ` <div class="wpbc_after_booking_thank_you_section">`;
621 confirm_content += ` <div class="wpbc_ty__message ${ty_message_hide}">${response_data[ 'ajx_confirmation' ][ 'ty_message' ]}</div>`;
622 confirm_content += ` <div class="wpbc_ty__container">`;
623 if ( '' !== response_data[ 'ajx_confirmation' ][ 'ty_message_booking_id' ] ){
624 confirm_content += ` <div class="wpbc_ty__header">${response_data[ 'ajx_confirmation' ][ 'ty_message_booking_id' ]}</div>`;
625 }
626 confirm_content += ` <div class="wpbc_ty__content">`;
627 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>`;
628 if ( '' !== response_data[ 'ajx_confirmation' ][ 'ty_customer_details' ] ){
629 confirm_content += ` <div class="wpbc_ty__content_text wpbc_cols_2">${response_data['ajx_confirmation']['ty_customer_details']}</div>`;
630 }
631 if ( '' !== response_data[ 'ajx_confirmation' ][ 'ty_booking_details' ] ){
632 confirm_content += ` <div class="wpbc_ty__content_text wpbc_cols_2">${response_data['ajx_confirmation']['ty_booking_details']}</div>`;
633 }
634 confirm_content += ` <div class="wpbc_ty__content_text wpbc_ty__content_costs ${ty_booking_costs_hide}">${response_data[ 'ajx_confirmation' ][ 'ty_booking_costs' ]}</div>`;
635 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>`;
636 confirm_content += ` </div>`;
637 confirm_content += ` </div>`;
638 confirm_content += `</div>`;
639
640 jQuery( '#booking_form' + resource_id ).after( confirm_content );
641
642
643 //FixIn: 10.0.0.30 // event name // Resource ID - '1'
644 jQuery( 'body' ).trigger( 'wpbc_booking_created', [ resource_id , response_data ] );
645 // To catch this event: jQuery( 'body' ).on('wpbc_booking_created', function( event, resource_id, params ) { console.log( event, resource_id, params ); } );
646 }
647