PluginProbe
Booking Calendar / 11.5
Booking Calendar v11.5
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 10.11 All 204 releases
booking / includes / _capacity / _src / create_booking.js

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

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