"use strict";
function wpbc_ajx_booking__create(params){
console.groupCollapsed('WPBC_AJX_BOOKING__CREATE');
console.groupCollapsed('==Before Ajax Send==');
console.log(params);
console.groupEnd();
params=wpbc_captcha__simple__maybe_remove_in_ajx_params(params);
jQuery('body').trigger('wpbc_before_booking_create', [params['resource_id'], params]);
jQuery.post(wpbc_url_ajax, {
action: 'WPBC_AJX_BOOKING__CREATE',
wpbc_ajx_user_id: _wpbc.get_secure_param('user_id'),
nonce: _wpbc.get_secure_param('nonce'),
wpbc_ajx_locale: _wpbc.get_secure_param('locale'),
calendar_request_params: params
},
function (response_data, textStatus, jqXHR){
console.log('==Response WPBC_AJX_BOOKING__CREATE==');
for (var obj_key in response_data){
console.groupCollapsed('==' + obj_key + '==');
console.log(':' + obj_key + ':', response_data[obj_key]);
console.groupEnd();
}
console.groupEnd();
if(typeof response_data!=='object'||response_data===null){
var calendar_id=wpbc_get_resource_id__from_ajx_post_data_url(this.data);
var jq_node='#booking_form' + calendar_id;
if(''==response_data){
response_data='<strong>' + 'Error! Server respond with empty string!' + '</strong> ';
}
wpbc_front_end__show_message(response_data, {
'type': 'error',
'show_here': {
'jq_node': jq_node,
'where': 'after'
},
'is_append': true,
'style': 'text-align:left;',
'delay': 0
});
wpbc_booking_form__on_response__ui_elements_enable(calendar_id);
return;
}
if('ok'!=response_data['ajx_data']['status']){
switch (response_data['ajx_data']['status_error']){
case 'captcha_simple_wrong':
wpbc_captcha__simple__update({
'resource_id': response_data['resource_id'],
'url': response_data['ajx_data']['captcha__simple']['url'],
'challenge': response_data['ajx_data']['captcha__simple']['challenge'],
'message': response_data['ajx_data']['ajx_after_action_message']
});
break;
case 'resource_id_incorrect':
var message_id=wpbc_front_end__show_message(response_data['ajx_data']['ajx_after_action_message'].replace(/\n/g, "<br />"), {
'type': 'undefined'!==typeof response_data['ajx_data']['ajx_after_action_message_status'] ? response_data['ajx_data']['ajx_after_action_message_status']:'warning',
'delay': 0,
'show_here': {
'where': 'after',
'jq_node': '#booking_form' + params['resource_id']
}});
break;
case 'booking_can_not_save':
var message_id=wpbc_front_end__show_message(response_data['ajx_data']['ajx_after_action_message'].replace(/\n/g, "<br />"), {
'type': 'undefined'!==typeof response_data['ajx_data']['ajx_after_action_message_status'] ? response_data['ajx_data']['ajx_after_action_message_status']:'warning',
'delay': 0,
'show_here': {
'where': 'after',
'jq_node': '#booking_form' + params['resource_id']
}});
wpbc_booking_form__on_response__ui_elements_enable(response_data['resource_id']);
break;
default:
if('undefined'!==typeof response_data['ajx_data']['ajx_after_action_message']&&''!=response_data['ajx_data']['ajx_after_action_message'].replace(/\n/g, "<br />")){
var calendar_id=wpbc_get_resource_id__from_ajx_post_data_url(this.data);
var jq_node='#booking_form' + calendar_id;
var ajx_after_booking_message=response_data['ajx_data']['ajx_after_action_message'].replace(/\n/g, "<br />");
console.log(ajx_after_booking_message);
}}
wpbc_booking_form__on_response__ui_elements_enable(response_data['resource_id']);
wpbc_calendar__unselect_all_dates(response_data['resource_id']);
wpbc_calendar__load_data__ajx({
'resource_id': response_data['resource_id']
,
'booking_hash': response_data['ajx_cleaned_params']['booking_hash']
,
'request_uri': response_data['ajx_cleaned_params']['request_uri'],
'custom_form': response_data['ajx_cleaned_params']['custom_form']
,
'aggregate_resource_id_str': _wpbc.booking__get_param_value(response_data['resource_id'], 'aggregate_resource_id_arr').join(',')
});
return;
}
wpbc_booking_form__spin_loader__hide(response_data['resource_id']);
wpbc_booking_form__animated__hide(response_data['resource_id']);
wpbc_show_thank_you_message_after_booking(response_data);
jQuery('body').trigger('wpbc_booking_form_submit_success', [response_data['resource_id'], response_data, params]);
setTimeout(function (){
wpbc_do_scroll('#wpbc_scroll_point_' + response_data['resource_id'], 10);
}, 500);
}).fail(function (jqXHR, textStatus, errorThrown){
if(window.console&&window.console.log){
console.log('Ajax_Error', jqXHR, textStatus, errorThrown);
}
var error_message='<strong>' + 'Error!' + '</strong> ' + errorThrown;
if(jqXHR.status){
error_message +=' (<b>' + jqXHR.status + '</b>)';
if(403==jqXHR.status){
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>.';
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>';
}}
if(jqXHR.responseText){
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;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;") + '</div>';
}
error_message=error_message.replace(/\n/g, "<br />");
var calendar_id=wpbc_get_resource_id__from_ajx_post_data_url(this.data);
var jq_node='#booking_form' + calendar_id;
wpbc_front_end__show_message(error_message, {
'type': 'error',
'show_here': {
'jq_node': jq_node,
'where': 'after'
},
'is_append': true,
'style': 'text-align:left;',
'delay': 0
});
wpbc_booking_form__on_response__ui_elements_enable(calendar_id);
}
)
;
return true;
}
/**
* Update image in captcha and show warning message
*
* @param params
*
* Example of 'params':{
*							'resource_id': response_data[ 'resource_id' ],
*							'url':response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'url' ],
*							'challenge':response_data[ 'ajx_data' ][ 'captcha__simple' ][ 'challenge' ],
*							'message':response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace(/\n/g, "<br />")
*						}
*/
function wpbc_captcha__simple__update(params){
document.getElementById('captcha_input' + params['resource_id']).value='';
document.getElementById('captcha_img' + params['resource_id']).src=params['url'];
document.getElementById('wpdev_captcha_challenge_' + params['resource_id']).value=params['challenge'];
var message_id=wpbc_front_end__show_message__warning('#captcha_input' + params['resource_id'] + ' + img', params['message'], 'text');
jQuery('#' + message_id + ', ' + '#captcha_input' + params['resource_id']).fadeOut(350).fadeIn(300).fadeOut(350).fadeIn(400).animate({
opacity: 1
}, 4000);
jQuery('#captcha_input' + params['resource_id']).trigger('focus');
wpbc_booking_form__on_response__ui_elements_enable(params['resource_id']);
}
function wpbc_captcha__simple__maybe_remove_in_ajx_params(params){
if(!wpbc_captcha__simple__is_exist_in_form(params['resource_id'])){
delete params['captcha_chalange'];
delete params['captcha_user_input'];
}
return params;
}
function wpbc_captcha__simple__is_exist_in_form(resource_id){
return 0!==jQuery('#wpdev_captcha_challenge_' + resource_id).length||0!==jQuery('#captcha_input' + resource_id).length;
}
function wpbc_booking_form__on_submit__ui_elements_disable(resource_id){
wpbc_booking_form__send_button__disable(resource_id);
wpbc_booking_form__spin_loader__show(resource_id);
}
function wpbc_booking_form__on_response__ui_elements_enable(resource_id){
wpbc_booking_form__send_button__enable(resource_id);
wpbc_booking_form__spin_loader__hide(resource_id);
}
function wpbc_booking_form__send_button__enable(resource_id){
jQuery('#booking_form_div' + resource_id + ' input[type=button]').prop("disabled", false);
jQuery('#booking_form_div' + resource_id + ' button').prop("disabled", false);
}
function wpbc_booking_form__send_button__disable(resource_id){
jQuery('#booking_form_div' + resource_id + ' input[type=button]').prop("disabled", true);
jQuery('#booking_form_div' + resource_id + ' button').prop("disabled", true);
}
function wpbc_booking_form__this_button__disable(_this){
jQuery(_this).prop("disabled", true);
}
function wpbc_booking_form__spin_loader__show(resource_id){
var $form_container=jQuery('#booking_form_div' + resource_id);
var loader_text='Saving';
if('undefined'!==typeof _wpbc&&_wpbc.get_message){
loader_text=_wpbc.get_message('message_booking_saving')||loader_text;
}
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">' + '<div class="wpbc_spins_loading_container">' + '<div class="wpbc_booking_form_spin_loader"><div class="wpbc_spins_loader_wrapper"><div class="wpbc_spin_loader_one_new"></div></div></div>' + '<span>' + loader_text + '...</span>' + '</div>' + '</div>';
jQuery('#wpbc_booking_form_spin_loader' + resource_id).remove();
if($form_container.length&&$form_container.is(':visible')){
$form_container.addClass('wpbc_booking_form_is_submitting');
$form_container.prepend(loader_html);
return;
}
jQuery('#booking_form' + resource_id).after('<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>');
}
function wpbc_booking_form__spin_loader__hide(resource_id){
jQuery('#wpbc_booking_form_spin_loader' + resource_id).remove();
jQuery('#booking_form_div' + resource_id).removeClass('wpbc_booking_form_is_submitting');
}
function wpbc_booking_form__animated__hide(resource_id){
jQuery('#booking_form' + resource_id).hide();
}
function wpbc__spin_loader__micro__show__inside(id, jq_node_where_insert){
wpbc__spin_loader__mini__show(id, {
'color': '#444',
'show_here': {
'where': 'inside',
'jq_node': jq_node_where_insert
},
'style': 'position: relative;display: inline-flex;flex-flow: column nowrap;justify-content: center;align-items: center;margin: 7px 12px;',
'class': 'wpbc_one_spin_loader_micro'
});
}
function wpbc__spin_loader__micro__hide(id){
wpbc__spin_loader__mini__hide(id);
}
function wpbc__spin_loader__mini__show(parent_html_id, params={}){
var params_default={
'color': '#0071ce',
'show_here': {
'jq_node': '',
'where': 'after' // 'inside' | 'before' | 'after' | 'right' | 'left'
},
'style': 'position: relative;min-height: 2.8rem;',
'class': 'wpbc_one_spin_loader_mini 0wpbc_spin_loader_one_new'
};
for (var p_key in params){
params_default[p_key]=params[p_key];
}
params=params_default;
if('undefined'!==typeof params['color']&&''!=params['color']){
params['color']='border-color:' + params['color'] + ';';
}
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>';
if(''==params['show_here']['jq_node']){
params['show_here']['jq_node']='#' + parent_html_id;
}
if('after'==params['show_here']['where']){
jQuery(params['show_here']['jq_node']).after(spinner_html);
}else{
jQuery(params['show_here']['jq_node']).html(spinner_html);
}}
function wpbc__spin_loader__mini__hide(parent_html_id){
jQuery('#wpbc_mini_spin_loader' + parent_html_id).remove();
}
function wpbc_show_thank_you_message_after_booking(response_data){
if('undefined'!==typeof response_data['ajx_confirmation']['ty_is_redirect']&&'undefined'!==typeof response_data['ajx_confirmation']['ty_url']&&'page'==response_data['ajx_confirmation']['ty_is_redirect']&&''!=response_data['ajx_confirmation']['ty_url']){
jQuery('body').trigger('wpbc_booking_created', [response_data['resource_id'], response_data]);
window.location.href=response_data['ajx_confirmation']['ty_url'];
return;
}
var resource_id=response_data['resource_id'];
var confirm_content='';
if('undefined'===typeof response_data['ajx_confirmation']['ty_message']){
response_data['ajx_confirmation']['ty_message']='';
}
if('undefined'===typeof response_data['ajx_confirmation']['ty_payment_payment_description']){
response_data['ajx_confirmation']['ty_payment_payment_description']='';
}
if('undefined'===typeof response_data['ajx_confirmation']['payment_cost']){
response_data['ajx_confirmation']['payment_cost']='';
}
if('undefined'===typeof response_data['ajx_confirmation']['ty_payment_gateways']){
response_data['ajx_confirmation']['ty_payment_gateways']='';
}
var ty_message_hide=''==response_data['ajx_confirmation']['ty_message'] ? 'wpbc_ty_hide':'';
var ty_payment_payment_description_hide=''==response_data['ajx_confirmation']['ty_payment_payment_description'].replace(/\\n/g, '') ? 'wpbc_ty_hide':'';
var ty_booking_costs_hide=''==response_data['ajx_confirmation']['payment_cost'] ? 'wpbc_ty_hide':'';
var ty_payment_gateways_hide=''==response_data['ajx_confirmation']['ty_payment_gateways'].replace(/\\n/g, '') ? 'wpbc_ty_hide':'';
if('wpbc_ty_hide'!=ty_payment_gateways_hide){
jQuery('.wpbc_ty__content_text.wpbc_ty__content_gateways').html('');
}
confirm_content +=`<div id="wpbc_scroll_point_${resource_id}"></div>`;
confirm_content +=`  <div class="wpbc_after_booking_thank_you_section">`;
confirm_content +=`    <div class="wpbc_ty__message ${ty_message_hide}">${response_data['ajx_confirmation']['ty_message']}</div>`;
confirm_content +=`    <div class="wpbc_ty__container">`;
if(''!==response_data['ajx_confirmation']['ty_message_booking_id']){
confirm_content +=`      <div class="wpbc_ty__header">${response_data['ajx_confirmation']['ty_message_booking_id']}</div>`;
}
confirm_content +=`      <div class="wpbc_ty__content">`;
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>`;
if(''!==response_data['ajx_confirmation']['ty_customer_details']){
confirm_content +=`      	<div class="wpbc_ty__content_text wpbc_cols_2">${response_data['ajx_confirmation']['ty_customer_details']}</div>`;
}
if(''!==response_data['ajx_confirmation']['ty_booking_details']){
confirm_content +=`      	<div class="wpbc_ty__content_text wpbc_cols_2">${response_data['ajx_confirmation']['ty_booking_details']}</div>`;
}
confirm_content +=`        <div class="wpbc_ty__content_text wpbc_ty__content_costs ${ty_booking_costs_hide}">${response_data['ajx_confirmation']['ty_booking_costs']}</div>`;
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>`;
confirm_content +=`      </div>`;
confirm_content +=`    </div>`;
confirm_content +=`</div>`;
jQuery('#booking_form' + resource_id).after(confirm_content);
jQuery('body').trigger('wpbc_booking_created', [resource_id, response_data]);
};