| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | "use strict"; |
| 2 | 2 | |
| 3 | 3 | // --------------------------------------------------------------------------------------------------------------------- |
| 4 | 4 | // == A j a x A d d N e w B o o k i n g == |
| @@ -65,11 +65,39 @@ | ||
| 65 | 65 | * @param response_data - its object returned from Ajax - class-live-searcg.php |
| 66 | 66 | * @param textStatus - 'success' |
| 67 | 67 | * @param jqXHR - Object |
| 68 | 68 | */ |
| 69 | - function ( response_data, textStatus, jqXHR ) { | |
| 70 | -console.log( ' == Response WPBC_AJX_BOOKING__CREATE == ' ); | |
| 71 | -for ( var obj_key in response_data ){ | |
| 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 ){ | |
| 72 | 100 | console.groupCollapsed( '==' + obj_key + '==' ); |
| 73 | 101 | console.log( ' : ' + obj_key + ' : ', response_data[ obj_key ] ); |
| 74 | 102 | console.groupEnd(); |
| 75 | 103 | } |
| @@ -75,34 +103,8 @@ | ||
| 75 | 103 | } |
| 76 | 104 | console.groupEnd(); |
| 77 | 105 | |
| 78 | 106 | |
| 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 | 107 | // <editor-fold defaultstate="collapsed" desc=" == This section execute, when we have KNOWN errors from Booking Calendar. -> E_X_I_T " > |
| 106 | 108 | // ------------------------------------------------------------------------------------------------- |
| 107 | 109 | // This section execute, when we have KNOWN errors from Booking Calendar |
| 108 | 110 | // ------------------------------------------------------------------------------------------------- |
| @@ -115,9 +117,9 @@ | ||
| 115 | 117 | wpbc_captcha__simple__update( { |
| 116 | 118 | 'resource_id': response_data[ 'resource_id' ], |
| 117 | 119 | 'url' : response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'url' ], |
| 118 | 120 | 'challenge' : response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'challenge' ], |
| 119 | - 'message' : response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ) | |
| 121 | + 'message' : response_data[ 'ajx_data' ][ 'ajx_after_action_message' ] | |
| 120 | 122 | } |
| 121 | 123 | ); |
| 122 | 124 | break; |
| 123 | 125 | |
| @@ -157,25 +159,21 @@ | ||
| 157 | 159 | |
| 158 | 160 | var calendar_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data ); |
| 159 | 161 | var jq_node = '#booking_form' + calendar_id; |
| 160 | 162 | |
| 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 | - */ | |
| 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 | + } ); | |
| 178 | 176 | } |
| 179 | 177 | // </editor-fold> |
| 180 | 178 | } |
| 181 | 179 | |
| @@ -248,44 +246,31 @@ | ||
| 248 | 246 | |
| 249 | 247 | } |
| 250 | 248 | ).fail( |
| 251 | 249 | // <editor-fold defaultstate="collapsed" desc=" = This section execute, when NONCE field was not passed or some error happened at server! = " > |
| 252 | - function ( jqXHR, textStatus, errorThrown ) { if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); } | |
| 250 | + function ( jqXHR, textStatus, errorThrown ) { | |
| 251 | + wpbc_front_end__log_unexpected_ajax_response( 'WPBC_AJX_BOOKING__CREATE', jqXHR.responseText || '', jqXHR, textStatus, errorThrown ); | |
| 253 | 252 | |
| 254 | 253 | // ------------------------------------------------------------------------------------------------- |
| 255 | 254 | // This section execute, when NONCE field was not passed or some error happened at server! |
| 256 | 255 | // ------------------------------------------------------------------------------------------------- |
| 257 | 256 | |
| 258 | - // Get Content of Error Message | |
| 259 | - var error_message = '<strong>' + 'Error!' + '</strong> ' + errorThrown ; | |
| 260 | - if ( jqXHR.status ){ | |
| 261 | - error_message += ' (<b>' + jqXHR.status + '</b>)'; | |
| 262 | - if (403 == jqXHR.status ){ | |
| 263 | - 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>.'; | |
| 264 | - 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>' | |
| 265 | - } | |
| 266 | - } | |
| 267 | - if ( jqXHR.responseText ){ | |
| 268 | - // Escape tags in Error message | |
| 269 | - 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, "&") | |
| 270 | - .replace(/</g, "<") | |
| 271 | - .replace(/>/g, ">") | |
| 272 | - .replace(/"/g, """) | |
| 273 | - .replace(/'/g, "'") | |
| 274 | - +'</div>'; | |
| 275 | - } | |
| 276 | - error_message = error_message.replace( /\n/g, "<br />" ); | |
| 257 | + var error_message = _wpbc.get_message( 'message_unexpected_server_response' ) || 'The server returned an unexpected response. Please reload the page and try again.'; | |
| 258 | + if ( jqXHR.status ){ | |
| 259 | + error_message += ' (' + parseInt( jqXHR.status, 10 ) + ')'; | |
| 260 | + } | |
| 277 | 261 | |
| 278 | 262 | var calendar_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data ); |
| 279 | 263 | var jq_node = '#booking_form' + calendar_id; |
| 280 | 264 | |
| 281 | 265 | // Show Message |
| 282 | - wpbc_front_end__show_message( error_message , { 'type' : 'error', | |
| 283 | - 'show_here': {'jq_node': jq_node, 'where': 'after'}, | |
| 284 | - 'is_append': true, | |
| 285 | - 'style' : 'text-align:left;', | |
| 286 | - 'delay' : 0 | |
| 287 | - } ); | |
| 266 | + wpbc_front_end__show_message( error_message , { 'type' : 'error', | |
| 267 | + 'show_here' : {'jq_node': jq_node, 'where': 'after'}, | |
| 268 | + 'is_append' : true, | |
| 269 | + 'style' : 'text-align:left;', | |
| 270 | + 'content_mode': 'text', | |
| 271 | + 'delay' : 0 | |
| 272 | + } ); | |
| 288 | 273 | // Enable Submit | Hide spin loader |
| 289 | 274 | wpbc_booking_form__on_response__ui_elements_enable( calendar_id ); |
| 290 | 275 | } |
| 291 | 276 | // </editor-fold> |
| @@ -318,9 +303,9 @@ | ||
| 318 | 303 | document.getElementById( 'captcha_img' + params[ 'resource_id' ] ).src = params[ 'url' ]; |
| 319 | 304 | document.getElementById( 'wpdev_captcha_challenge_' + params[ 'resource_id' ] ).value = params[ 'challenge' ]; |
| 320 | 305 | |
| 321 | 306 | // Show warning After CAPTCHA Img |
| 322 | - var message_id = wpbc_front_end__show_message__warning( '#captcha_input' + params[ 'resource_id' ] + ' + img', params[ 'message' ] ); | |
| 307 | + var message_id = wpbc_front_end__show_message__warning( '#captcha_input' + params[ 'resource_id' ] + ' + img', params[ 'message' ], 'text' ); | |
| 323 | 308 | |
| 324 | 309 | // Animate |
| 325 | 310 | jQuery( '#' + message_id + ', ' + '#captcha_input' + params[ 'resource_id' ] ).fadeOut( 350 ).fadeIn( 300 ).fadeOut( 350 ).fadeIn( 400 ).animate( {opacity: 1}, 4000 ); |
| 326 | 311 | // Focus text field |
| @@ -435,9 +420,9 @@ | ||
| 435 | 420 | |
| 436 | 421 | var $form_container = jQuery( '#booking_form_div' + resource_id ); |
| 437 | 422 | var loader_text = 'Saving'; |
| 438 | 423 | if ( 'undefined' !== typeof _wpbc && _wpbc.get_message ) { |
| 439 | - loader_text = _wpbc.get_message( 'message_saving' ) || loader_text; | |
| 424 | + loader_text = _wpbc.get_message( 'message_booking_saving' ) || loader_text; | |
| 440 | 425 | } |
| 441 | 426 | var loader_html = '<div id="wpbc_booking_form_spin_loader' + resource_id + '" class="wpbc_booking_form_spin_loader wpbc_booking_form_submit_overlay" aria-live="polite" aria-hidden="false">' |
| 442 | 427 | + '<div class="wpbc_spins_loading_container">' |
| 443 | 428 | + '<div class="wpbc_booking_form_spin_loader"><div class="wpbc_spins_loader_wrapper"><div class="wpbc_spin_loader_one_new"></div></div></div>' |