PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 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 All 205 releases
booking / includes / _capacity / _src / create_booking.js

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

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