PluginProbe
Booking Calendar / 10.15.6
Booking Calendar v10.15.6
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.15.6, at includes/_capacity/_src/create_booking.js

618 lines 26.2 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_spin_loader_one_new"></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 ).hide();
458 }
459 // </editor-fold>
460
461
462 // <editor-fold defaultstate="collapsed" desc=" == Mini Spin Loader == " >
463
464 /**
465 *
466 * @param parent_html_id
467 */
468
469 /**
470 * Show micro Spin Loader
471 *
472 * @param id ID of Loader, for later hide it by using wpbc__spin_loader__micro__hide( id ) OR wpbc__spin_loader__mini__hide( id )
473 * @param jq_node_where_insert such as '#estimate_booking_night_cost_hint10' OR '.estimate_booking_night_cost_hint10'
474 */
475 function wpbc__spin_loader__micro__show__inside( id , jq_node_where_insert ){
476
477 wpbc__spin_loader__mini__show( id, {
478 'color' : '#444',
479 'show_here': {
480 'where' : 'inside',
481 'jq_node': jq_node_where_insert
482 },
483 'style' : 'position: relative;display: inline-flex;flex-flow: column nowrap;justify-content: center;align-items: center;margin: 7px 12px;',
484 'class' : 'wpbc_one_spin_loader_micro'
485 } );
486 }
487
488 /**
489 * Remove spinner
490 * @param id
491 */
492 function wpbc__spin_loader__micro__hide( id ){
493 wpbc__spin_loader__mini__hide( id );
494 }
495
496
497 /**
498 * Show mini Spin Loader
499 * @param parent_html_id
500 */
501 function wpbc__spin_loader__mini__show( parent_html_id , params = {} ){
502
503 var params_default = {
504 'color' : '#0071ce',
505 'show_here': {
506 'jq_node': '', // any jQuery node definition
507 'where' : 'after' // 'inside' | 'before' | 'after' | 'right' | 'left'
508 },
509 'style' : 'position: relative;min-height: 2.8rem;',
510 'class' : 'wpbc_one_spin_loader_mini 0wpbc_spin_loader_one_new'
511 };
512 for ( var p_key in params ){
513 params_default[ p_key ] = params[ p_key ];
514 }
515 params = params_default;
516
517 if ( ('undefined' !== typeof (params['color'])) && ('' != params['color']) ){
518 params['color'] = 'border-color:' + params['color'] + ';';
519 }
520
521 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>';
522
523 if ( '' == params[ 'show_here' ][ 'jq_node' ] ){
524 params[ 'show_here' ][ 'jq_node' ] = '#' + parent_html_id;
525 }
526
527 // Show Spin Loader
528 if ( 'after' == params[ 'show_here' ][ 'where' ] ){
529 jQuery( params[ 'show_here' ][ 'jq_node' ] ).after( spinner_html );
530 } else {
531 jQuery( params[ 'show_here' ][ 'jq_node' ] ).html( spinner_html );
532 }
533 }
534
535 /**
536 * Remove / Hide mini Spin Loader
537 * @param parent_html_id
538 */
539 function wpbc__spin_loader__mini__hide( parent_html_id ){
540
541 // Remove Spin Loader
542 jQuery( '#wpbc_mini_spin_loader' + parent_html_id ).remove();
543 }
544
545 // </editor-fold>
546
547 //TODO: what about showing only Thank you. message without payment forms.
548 /**
549 * Show 'Thank you'. message and payment forms
550 *
551 * @param response_data
552 */
553 function wpbc_show_thank_you_message_after_booking( response_data ){
554
555 if (
556 ('undefined' !== typeof (response_data[ 'ajx_confirmation' ][ 'ty_is_redirect' ]))
557 && ('undefined' !== typeof (response_data[ 'ajx_confirmation' ][ 'ty_url' ]))
558 && ('page' == response_data[ 'ajx_confirmation' ][ 'ty_is_redirect' ])
559 && ('' != response_data[ 'ajx_confirmation' ][ 'ty_url' ])
560 ){
561 jQuery( 'body' ).trigger( 'wpbc_booking_created', [ response_data[ 'resource_id' ] , response_data ] ); // FixIn: 10.0.0.30.
562 window.location.href = response_data[ 'ajx_confirmation' ][ 'ty_url' ];
563 return;
564 }
565
566 var resource_id = response_data[ 'resource_id' ]
567 var confirm_content ='';
568
569 if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'ty_message' ]) ){
570 response_data[ 'ajx_confirmation' ][ 'ty_message' ] = '';
571 }
572 if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'ty_payment_payment_description' ] ) ){
573 response_data[ 'ajx_confirmation' ][ 'ty_payment_payment_description' ] = '';
574 }
575 if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'payment_cost' ] ) ){
576 response_data[ 'ajx_confirmation' ][ 'payment_cost' ] = '';
577 }
578 if ( 'undefined' === typeof (response_data[ 'ajx_confirmation' ][ 'ty_payment_gateways' ] ) ){
579 response_data[ 'ajx_confirmation' ][ 'ty_payment_gateways' ] = '';
580 }
581 var ty_message_hide = ('' == response_data[ 'ajx_confirmation' ][ 'ty_message' ]) ? 'wpbc_ty_hide' : '';
582 var ty_payment_payment_description_hide = ('' == response_data[ 'ajx_confirmation' ][ 'ty_payment_payment_description' ].replace( /\\n/g, '' )) ? 'wpbc_ty_hide' : '';
583 var ty_booking_costs_hide = ('' == response_data[ 'ajx_confirmation' ][ 'payment_cost' ]) ? 'wpbc_ty_hide' : '';
584 var ty_payment_gateways_hide = ('' == response_data[ 'ajx_confirmation' ][ 'ty_payment_gateways' ].replace( /\\n/g, '' )) ? 'wpbc_ty_hide' : '';
585
586 if ( 'wpbc_ty_hide' != ty_payment_gateways_hide ){
587 jQuery( '.wpbc_ty__content_text.wpbc_ty__content_gateways' ).html( '' ); // Reset all other possible gateways before showing new one.
588 }
589
590 confirm_content += `<div id="wpbc_scroll_point_${resource_id}"></div>`;
591 confirm_content += ` <div class="wpbc_after_booking_thank_you_section">`;
592 confirm_content += ` <div class="wpbc_ty__message ${ty_message_hide}">${response_data[ 'ajx_confirmation' ][ 'ty_message' ]}</div>`;
593 confirm_content += ` <div class="wpbc_ty__container">`;
594 if ( '' !== response_data[ 'ajx_confirmation' ][ 'ty_message_booking_id' ] ){
595 confirm_content += ` <div class="wpbc_ty__header">${response_data[ 'ajx_confirmation' ][ 'ty_message_booking_id' ]}</div>`;
596 }
597 confirm_content += ` <div class="wpbc_ty__content">`;
598 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>`;
599 if ( '' !== response_data[ 'ajx_confirmation' ][ 'ty_customer_details' ] ){
600 confirm_content += ` <div class="wpbc_ty__content_text wpbc_cols_2">${response_data['ajx_confirmation']['ty_customer_details']}</div>`;
601 }
602 if ( '' !== response_data[ 'ajx_confirmation' ][ 'ty_booking_details' ] ){
603 confirm_content += ` <div class="wpbc_ty__content_text wpbc_cols_2">${response_data['ajx_confirmation']['ty_booking_details']}</div>`;
604 }
605 confirm_content += ` <div class="wpbc_ty__content_text wpbc_ty__content_costs ${ty_booking_costs_hide}">${response_data[ 'ajx_confirmation' ][ 'ty_booking_costs' ]}</div>`;
606 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>`;
607 confirm_content += ` </div>`;
608 confirm_content += ` </div>`;
609 confirm_content += `</div>`;
610
611 jQuery( '#booking_form' + resource_id ).after( confirm_content );
612
613
614 //FixIn: 10.0.0.30 // event name // Resource ID - '1'
615 jQuery( 'body' ).trigger( 'wpbc_booking_created', [ resource_id , response_data ] );
616 // To catch this event: jQuery( 'body' ).on('wpbc_booking_created', function( event, resource_id, params ) { console.log( event, resource_id, params ); } );
617 }
618