File: /var/www/html/bwcdev/wp-content/themes/salient-child/assets/custom/js/custom.js
var baseUrl = "https://shootinschool.com/wp-json/bwc-api/v1/";
// var baseUrl = "http://localhost/shootinschool_wp/wp-json/bwc-api/v1/";
var currenturl = "https://bwcsports.com/"
jQuery(document).ready(function () {
jQuery(".css_loader").hide();
});
var dtToday = new Date();
var month = dtToday.getMonth() + 1;
var day = dtToday.getDate() + 1;
var year = dtToday.getFullYear();
if(month < 10)
month = '0' + month.toString();
if(day < 10)
day = '0' + day.toString();
var maxDate = year + '-' + month + '-' + day;
// or instead:
// var maxDate = dtToday.toISOString().substr(0, 10);
// alert(maxDate);
jQuery('.date_sel').attr('min', maxDate);
function openNewChildModel(isAppend) {
//alert(localStorage.getItem('userid'));
if (isAppend == 0) {
jQuery(".css_loader").show();
}
var userID = jQuery("#loggedUid").val()
var settings = {
"url": baseUrl+"BwcRenderAppendChild?id="+userID,
"method": "POST",
"timeout": 0,
"data": "action=render_or_append_new_child&isAppend="+isAppend,
};
$.ajax(settings).done(function (response) {
// Show the response in a modal
if (isAppend == 1) {
jQuery("#appendNewChildDiv").append(response);
} else {
jQuery("#appendNewChildDiv").empty().append(response);
jQuery("#addNewChildModal").modal('show');
}
jQuery(".css_loader").hide();
showModal(response);
});
}
function showModal(content) {
// Create a modal with the response content
var modal = $('<div class="modal fade" id="addNewChildModal" role="dialog">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<button type="button" class="close" data-dismiss="modal" onclick="this.parentNode.parentNode.parentNode.parentNode.remove();">X</button>' +
'<h4 class="modal-title"> Add New Children</h4>' +
'</div>' +
'<div class="modal-body">' +
'<form id="createChild" method="POST" enctype="multipart/form-data">' +
'<div id="appendNewChildDiv">' +
'</div>' +
'</form>' +
'<div class="row">' +
'<div class="col-md-4 pull-left">' +
'<div class="form-group">' +
'<button type="button" class="btn btn-primary" onclick="openNewChildModel(1);">+ Add Another</button>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'<div class="modal-footer">' +
'<button type="button" class="btn" onclick="saveChild()">Add</button>' +
'<button type="button" class="btn" data-dismiss="modal">Cancel</button>' +
'</div>' +
'</div>' +
'</div>' +
'</div>');
// Append the modal to the body and show it
// modal.appendTo('body').modal('show');
}
function saveChild() {
if (jQuery("#createChild").parsley().validate()) {
jQuery(".css_loader").show();
var formData = new FormData();
// console.log(formData);
// console.log("ssssssssssssssssss", document.getElementsByClassName('fileinput').files);
// var file = document.getElementsByClassName('fileinput')[0].files;
// console.log(file);
// var filedata = document.getElementsByName('file').length;
// console.log(filedata);
// var i = 0,
// len = filedata.files.length,
// img, reader, file;
// for (; i < len; i++) {
// file = filedata.files[i];
// formData.append("file", file);
// }
// var fileinputmobile = document.getElementsByClassName('fileinput').files[0];
// console.log(fileinputmobile);
// if(file){
// formData.append("file", file);
// } else {
// formData.append("file", fileinputmobile);
// }
// var totalfiles = document.getElementById('fileinput').files.length;
// for (var index = 0; index < totalfiles; index++) {
// formData.append("files[]", document.getElementById('fileinput').files[index]);
// }
jQuery('.fileinput').each(function (i, file) {
var key = "file" + i;
formData.append(key, jQuery(this)[0].files[0]);
});
// console.log(formData);
formData.append("data", jQuery('#createChild').serialize());
formData.append("action", 'save_child');
var settings = {
"url": baseUrl+"BwcSaveChild",
"method": "POST",
"timeout": 0,
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": formData
};
$.ajax(settings)
.done(function (response) {
response = response.replace(/^\s+/g, '');
response = JSON.parse(response);
console.log(response.status)
// Success: Handle the response
if(response.status == true){
toastr.success("Child Added successfully");
setTimeout(function () {
location.reload();
}, 1000);
}else{
toastr.error("Sorry, your added Child cannot be done.");
setTimeout(function () {
location.reload();
}, 1000);
}
})
.fail(function (jqXHR, textStatus, errorThrown) {
// Error: Handle the error
toastr.error(response.message);
});
}
}
$('.hfe-nav-menu__toggle').click(function(){
$('.hfe-nav-menu__layout-horizontal').toggleClass('menu-open');
})
// $("#loginBtn").click(function () {
// var username = $("#username").val();
// var password = $("#password").val();
// // Perform basic client-side validation
// if (username === "" || password === "") {
// $("#message").html("Please enter both username and password.");
// return;
// }
// var form = new FormData();
// form.append("username", username);
// form.append("password", password);
// var settings = {
// "url": baseUrl+"BwcLogin",
// "method": "POST",
// "timeout": 0,
// "headers": {},
// "processData": false,
// "mimeType": "multipart/form-data",
// "contentType": false,
// "data": form
// };
// $.ajax(settings)
// .done(function (response) {
// try {
// // Parse the JSON string into an object
// var responseObject = JSON.parse(response);
// // Check if the parsed object is valid
// if (typeof responseObject === 'object' && responseObject !== null) {
// // Now you can access properties of the object
// if (responseObject.data) {
// var userID = responseObject.data.ID;
// var user_login = responseObject.data.user_login;
// var user_nicename = responseObject.data.user_nicename;
// var user_email = responseObject.data.user_email;
// var display_name = responseObject.data.display_name;
// localStorage.setItem("userid", userID);
// localStorage.setItem("user_login", user_login);
// localStorage.setItem("user_nicename", user_nicename);
// localStorage.setItem("user_email", user_email);
// localStorage.setItem("display_name", display_name);
// window.location.href = currenturl+"my-account?uid="+userID
// console.log(userID);
// } else {
// toastr.error(response.message);
// }
// } else {
// console.error("Parsed response is not an object");
// }
// } catch (error) {
// console.log("Error parsing JSON: " + error);
// }
// })
// .fail(function (jqXHR, textStatus, errorThrown) {
// // Handle failure
// console.error("AJAX request failed:", textStatus, errorThrown);
// // Display an error message to the user or handle the failure in another way
// })
// .always(function (response) {
// // console.log(response)
// // This block will always run, regardless of success or failure
// // You can perform cleanup or additional actions here
// });
// });
function openSubscriptionCancelModal(customer_purchase_id) {
jQuery("#cancelbtn").attr("data-customer_purchase_id", customer_purchase_id);
jQuery("#SubscriptionCancelModal").appendTo("body").modal("show");
}
function SubscriptionCancelfun(customer_purchase_id, is_customer = 0) {
jQuery(".css_loader").show();
var customer_purchase_id = customer_purchase_id;
jQuery.ajax({
url: ajaxurl,
method: "post",
dataType: "json",
data: {
action: "Subscription_cancel",
is_customer,
"customer_purchase_id": jQuery(customer_purchase_id).attr("data-customer_purchase_id")
},
success: function (response) {
if (response.status) {
jQuery("#SubscriptionCancelModal").hide();
jQuery(".css_loader").hide();
location.reload();
}
},
error: function (data) {
console.log("inside error");
}
});
}
function updateProfileDet() {
if (jQuery("#updateProfile").parsley().validate()) {
var userID = jQuery("#loggedUid").val()
jQuery(".css_loader").show();
var formData = new FormData();
console.log(formData);
var file = document.getElementById('fileinput').files[0];
formData.append("file", file);
formData.append("firstname", $("#update_first_name").val());
formData.append("last_name", $("#update_last_name").val());
formData.append("grade", $("#update_grade").val());
formData.append("jersey_size", $("#update_jersey_size").val());
formData.append("school_name", $("#update_school_name").val());
formData.append("player_id", $("#update_player_id").val());
formData.append("child_dob", $("#update_child_dob").val());
// formData.append("data", jQuery('#updateProfile').serialize());
jQuery.ajax({
url: baseUrl+"BwcUpdatePlayerProfile?uid="+userID,
method: "post",
// dataType: "json",
processData: false,
contentType: false,
data: formData,
success: function (response) {
jQuery(".css_loader").hide();
console.log(response.status)
// response = JSON.parse(status);
// if (typeof response === 'string') {
// response = response.replace("oldValue", "newValue");
// } else {
// console.error("Error: response is not a string");
// }
// response = response.replace(/^\s+/g, '');
if (response.status) {
toastr.success(response.message);
setTimeout(function () {
location.reload();
}, 1000);
} else {
// jQuery('#addchild_error_modalBody').html('<p><strong>'+response.message+'</strong></p>');
// jQuery('#addchild_error_modal').modal('show');
}
},
error: function (data) {
toastr.error(data.message);
}
});
}
}
function AddComemnt() {
if (jQuery("#chatForm").parsley().validate()) {
jQuery(".css_loader").show();
jQuery("#btn_submit").prop("disabled", true);
var formData = new FormData();
console.log(formData);
formData.append("playerID", $("#forum_playerID").val());
formData.append("customerID", $("#forum_customerID").val());
formData.append("forum_type", $("#forum_type").val());
formData.append("userType", $("#forum_userType").val());
formData.append("comment", $("#forum_comment").val());
jQuery.ajax({
url: baseUrl+"BwcAddComment",
method: "post",
dataType: "json",
processData: false,
contentType: false,
data: formData,
success: function (response) {
jQuery(".css_loader").hide();
if (response.status) {
toastr.success(response.message);
setTimeout(function () {
location.reload();
}, 1000);
} else {
// jQuery('#addchild_error_modalBody').html('<p><strong>'+response.message+'</strong></p>');
// jQuery('#addchild_error_modal').modal('show');
}
},
error: function (data) {
toastr.error(data.message);
}
});
}
}
function cloneAppointment(user_id) {
var user_id = jQuery("#loggedUid").val()
// if (!jQuery("#createAppointment").parsley().validate()) {
// jQuery('#booking_error_modalBody').html('<p><strong>Please fill all existing fields before initiating multiple booking.</strong></p>');
// jQuery('#booking_error_modal').modal('show');
// return false;
// }
var form_data = jQuery("#createAppointment").serialize();
jQuery(".css_loader").show();
jQuery.ajax({
url: baseUrl+"BwcRenderCloneAppointment?user_id="+user_id+"&clone_counter="+jQuery('.outerGroup').length,
method: "get",
dataType: "json",
processData: false,
contentType: false,
crossDomain: true,
success: function (response) {
if (response.status) {
jQuery("#cloneApptDiv").append(response.renderedHtml);
jQuery('.purchase_order_sel').select2();
jQuery('.session_sel').select2();
jQuery('.location_sel').select2();
jQuery('.slot_sel_start').select2();
jQuery('.slot_sel_end').select2();
getDatePicker([]);
jQuery(".css_loader").hide();
} else {
jQuery(".css_loader").hide();
if (response.infofailure) {
var appendinfo = '<p style="text-align: justify;"><strong>' + response.infofailure + '</strong></p>';
} else {
var appendinfo = '';
}
jQuery('#booking_error_modalBody').html('<p><strong>' + response.message + '</strong></p>' + appendinfo);
jQuery('#booking_error_modal').modal('show');
}
},
error: function (data) {
console.log(data);
}
});
}function getDatePicker(data) {
// hide_days = data;
// jQuery(".date_sel").datepicker({
// changeMonth: true,
// changeYear: true,
// minDate: new Date(),
// dateFormat: "DD, MM dd, yy",
// firstDay: 1,
// beforeShowDay: noWeekendsOrHolidays
// });
}
function noWeekendsOrHolidays(date) {
// console.log(hide_days);
var day = date.getDay();
var monday = new Date();
//Set the time of today's date to 00:00:00
monday.setHours(0, 0, 0, 0);
/*
Below Line sets the Date to monday (Start of that Week)
(monday.getDay() || 0) returns the value of getDay()
ie., [ 1 - Mon, 2 - Tue, 3 - Wed, 4 - Thu, 5 - Fri, 6 - Sat ]
except for monday where it returns 0.
The return value is used to calculate the Date of that Week's monday
*/
monday.setDate(monday.getDate() - (monday.getDay() || 0));
//Set the Date to monday
var sunday = new Date(monday);
//Now add 6 to monday to get the Date of Saturday (End of that Week)
sunday.setDate(monday.getDate() + 7);
//Now return the enabled and disabled dates to datepicker
// return [(date >= monday && date <= sunday && jQuery.inArray(day, hide_days) != -1), ''];
return [(date >= monday && date <= sunday), ''];
}
function getChildren(elm) {
invokeResetFollowingfn(elm, 'purchase_order');
if (elm.value == "") {
var target_parent = jQuery(elm).parents('div.outerGroup');
jQuery(".date_sel").prop('disabled',true);
jQuery(target_parent).find(".date_sel").val('').trigger('change').prop("disabled", true);
jQuery(target_parent).find(".location_sel").val('').trigger('change').prop("disabled", true);
jQuery(target_parent).find(".slot_sel_start").val('').trigger('change').prop("disabled", true);
jQuery(target_parent).find(".slot_sel_end").val('').trigger('change').prop("disabled", true);
jQuery(target_parent).find(".purchase_order_sel").val('').trigger('change').prop("disabled", true);
}
var target_parent = jQuery(elm).parents('div.outerGroup');
jQuery(target_parent).find(".date_sel").val('').trigger('change').prop("disabled", true);
jQuery(target_parent).find(".location_sel").val('').trigger('change').prop("disabled", true);
jQuery(target_parent).find(".slot_sel_start").val('').trigger('change').prop("disabled", true);
jQuery(target_parent).find(".slot_sel_end").val('').trigger('change').prop("disabled", true);
jQuery(target_parent).find(".purchase_order_sel").val('').trigger('change').prop("disabled", true);
var pur_sess_id = jQuery(elm).val();
// For managing bookings from admin panel
var user_id = jQuery("#loggedUid").val()
// if (jQuery("#sel_customer").length) {
// user_id = jQuery("#sel_customer").val();
// }
jQuery(".css_loader").show();
jQuery.ajax({
url: baseUrl+"BwcGetChild",
method: "post",
dataType: "json",
data: {
action: "get_child",
pur_sess_id,
user_id
},
success: function (response) {
jQuery(target_parent).find(".purchase_order_sel").empty().append(response.renderedHtml).val('').trigger('change').prop("disabled", false);
jQuery(".css_loader").hide();
jQuery(".date_sel").prop('disabled',false);
},
error: function (data) {
jQuery(".css_loader").hide();
console.log("inside error");
jQuery(".date_sel").prop('disabled',true);
}
});
}
function invokeResetFollowingfn(elm, par) {
// Alter Current Div data
var target_parent = jQuery(elm).parents('div.outerGroup');
switch (par) {
case 'date':
jQuery(target_parent).find(".location_sel").val('').trigger('change').prop("disabled", false);
jQuery(target_parent).find(".slot_sel_start").empty().append('<option value=""> -- Choose -- </option>').val('').trigger('change').prop("disabled", true);
jQuery(target_parent).find(".slot_sel_end").empty().append('<option value=""> -- Choose -- </option>').val('').trigger('change').prop("disabled", true);
//jQuery(target_parent).find(".session_sel").val('').trigger('change').prop("disabled", true);
//jQuery(target_parent).find(".purchase_order_sel").empty().append('<option value=""> -- Choose Child Name -- </option>').val('').trigger('change').prop("disabled", true);
break;
case 'location':
jQuery(target_parent).find(".slot_sel").empty().append('<option value=""> -- Choose Time Slot -- </option>').val('').trigger('change').prop("disabled", true);
//jQuery(target_parent).find(".session_sel").val('').trigger('change').prop("disabled", true);
//jQuery(target_parent).find(".purchase_order_sel").empty().append('<option value=""> -- Choose Child Name -- </option>').val('').trigger('change').prop("disabled", true);
break;
case 'time':
//jQuery(target_parent).find(".session_sel").val('').trigger('change').prop("disabled", false);
// jQuery(target_parent).find(".purchase_order_sel").empty().append('<option value=""> -- Choose Child Name -- </option>').val('').trigger('change').prop("disabled", true);
break;
case 'purchase_order':
//jQuery(target_parent).find(".purchase_order_sel").empty().append('<option value=""> -- Choose Child Name -- </option>').val('').trigger('change').prop("disabled", false);
break;
}
// Alter Multiple Other Div data
jQuery(elm).parents('div.outerGroup').nextAll().each(function (i, obj) {
jQuery(this).find(".date_sel").datepicker('setDate', null);
jQuery(this).find(".location_sel").val('').trigger('change').prop("disabled", false);
jQuery(this).find(".slot_sel_start").empty().append('<option value=""> -- Choose -- </option>').val('').trigger('change').prop("disabled", false);
jQuery(this).find(".slot_sel_end").empty().append('<option value=""> -- Choose -- </option>').val('').trigger('change').prop("disabled", false);
// jQuery(this).find(".session_sel").val('').trigger('change').prop("disabled", false);
//jQuery(this).find(".purchase_order_sel").empty().append('<option value=""> -- Choose Child Name -- </option>').val('').trigger('change').prop("disabled", false);
});
}
function enableLocations(elm) {
invokeResetFollowingfn(elm, 'date');
invokeResetFollowingfn(elm, 'package');
if (elm.value == "") {
return false;
}
var target_parent = jQuery(elm).parents('div.outerGroup');
var package = jQuery(target_parent).find(".session_sel").val();
jQuery(".css_loader").show();
jQuery.ajax({
url: baseUrl+"BwcGetLocatioBasedOnDay",
method: "post",
dataType: "json",
data: {
// action: "get_locations_based_on_day",
date: elm.value,
package: package
},
success: function (response) {
var appendHtml = "";
if (response.status) {
appendHtml += '<option value="">-- All Locations --</option>';
response.locations.forEach(element => {
appendHtml += '<option value="' + element.id + '">' + element.name + '</option>';
});
} else {
jQuery(target_parent).find(".location_sel").prop("disabled", true);
appendHtml = '<option value="">' + response.message + '</option>';
// toastr.error(response.message);
if (response.message2 != '') {
jQuery('#booking_error_modalBody').html('<p><strong>' + response.message2 + '</strong></p>');
jQuery('#booking_error_modal').modal('show');
}
}
jQuery(target_parent).find(".location_sel").empty().append(appendHtml).val('').trigger('change');
jQuery(".css_loader").hide();
},
error: function (data) {
console.log("inside error");
}
});
}
function getTimeSlots(elm) {
invokeResetFollowingfn(elm, 'location');
if (elm.value == "") {
return false;
}
console.log();
var target_parent = jQuery(elm).parents('div.outerGroup');
var date = jQuery(target_parent).find(".date_sel ").val();
var location_id = jQuery(target_parent).find(".location_sel").val();
var user_id = jQuery(target_parent).find(".user_sel").val();
var session_sel = jQuery(target_parent).find(".session_sel").val();
var form_data = jQuery("#createAppointment").serialize();
jQuery(".css_loader").show();
jQuery.ajax({
url: baseUrl+"BwcGetTimeSlots",
method: "post",
dataType: "json",
data: {
// action: "get_time_slots",
date,
session_sel,
location_id,
user_id,
form_data
},
success: function (response) {
if (response.status) {
jQuery(target_parent).find('.slot_sel_start').empty();
jQuery(target_parent).find('.slot_sel_end').empty();
//jQuery(target_parent).find('.session_sel').empty();
jQuery(target_parent).find(".slot_sel_start").prop("disabled", false);
// jQuery(target_parent).find(".slot_sel_end").prop("disabled", false);
jQuery(target_parent).find(".slot_sel_start").append('<option value="">--Choose--</option>' + response.start_timings).val('').trigger('change');
jQuery(target_parent).find(".slot_sel_end").append('<option value="">--Choose--</option>' + response.end_timings).val('').trigger('change');
//jQuery(target_parent).find(".session_sel").append('<option value="">--Choose--</option>' + response.package).val('').trigger('change');
} else {
jQuery(".slot_sel_start").empty();
jQuery(".slot_sel_end").empty();
var appendStart = '<option value="">' + response.message + '</option>';
// var appendEnd = '<option value="">'+ response.message +'</option>';
jQuery(target_parent).find(".slot_sel_start").append(appendStart).val('').trigger('change');
}
jQuery(".css_loader").hide();
},
error: function (data) {
console.log("inside error");
}
});
}
function getEndTimeSlots(elm) {
var target_parent = jQuery(elm).parents('div.outerGroup');
if (elm.value) {
jQuery(target_parent).find(".slot_sel_end").prop("disabled", false);
} else {
jQuery(target_parent).find(".slot_sel_end").prop("disabled", true);
}
}
function enablePurchaseOrders(elm) {
if (elm.value == "") {
return false;
}
invokeResetFollowingfn(elm, 'time');
}
function setPurchaseData(elm) {
if (elm.value == "") {
return false;
}
var target_parent = jQuery(elm).parents('div.outerGroup');
var id = jQuery('option:selected', elm).attr('data-id');
jQuery(target_parent).find(".order_session").val(id);
}
function saveAppointment() {
var encrypted_user_id = jQuery(".u_id").val();
if (jQuery("#createAppointment").parsley().validate()) {
jQuery(".css_loader").show();
jQuery.ajax({
url: baseUrl+"BwcSaveAppointment",
method: "post",
dataType: "json",
data: {
// action: "save_appointment",
'form_data': jQuery("#createAppointment").serialize(),
encrypted_user_id
},
success: function (response) {
jQuery(".css_loader").hide();
if (response.status) {
toastr.success(response.message);
setTimeout(function () {
location.reload();
}, 1000);
// jQuery("#createAppointment")[0].reset();
// getDatePicker([]);
// jQuery(".date_sel").prop('disabled',true);
// jQuery(".slot_sel").prop('disabled',true);
} else {
// toastr.error(response.message);
if (response.infofailure) {
var appendinfo = '<p style="text-align: justify;"><strong>' + response.infofailure + '</strong></p>';
} else {
var appendinfo = '';
}
jQuery('#booking_error_modalBody').html('<p><strong>' + response.message + '</strong></p>' + appendinfo);
jQuery('#booking_error_modal').modal('show');
}
},
error: function (data) {
toastr.error(data.message);
}
});
}
}
function openCancelWarningModal(appt, pur) {
var appt_pur_ids = appt + '|' + pur;
jQuery.ajax({
url: baseUrl+"BwcRenderCancelWarningModal",
method: "post",
dataType: "json",
data: {
"appointment_id": appt
},
success: function (response) {
if (response.status) {
jQuery("#cancelWarningModal #proceedBtn").attr("appt_pur_ids", appt_pur_ids);
jQuery("#cancelWarningModal #appendSavedCardsDiv").empty().append(response.renderedHtml);
jQuery("#cancelWarningModal").modal('show');
} else {
toastr.error(response.message);
}
},
error: function (data) {
console.log("inside error");
}
});
}
function cancelMyAppointment() {
var appt_pur_ids = jQuery("#cancelWarningModal #proceedBtn").attr("appt_pur_ids");
// Checking if the appointment cancellation requires cancellation fee or not
if (jQuery('#is_chargable').length && jQuery('#is_chargable').val() == '9zayp') {
var form_data = {
appt_pur_ids
}
} else {
if (!jQuery("#cancelWarningModal #savedCard_id").val()) {
toastr.error('Please choose a Card.');
return;
}
var savedCard_id = jQuery("#cancelWarningModal #savedCard_id").val();
var form_data = {
appt_pur_ids,
savedCard_id
}
}
jQuery("#cancelWarningModal").modal('hide');
jQuery(".css_loader").show();
jQuery.ajax({
url: baseUrl+"BwcCancelMyAppointment",
method: "post",
dataType: "json",
data: form_data,
success: function (response) {
jQuery(".css_loader").hide();
if (response.status) {
toastr.success(response.message);
setTimeout(function () {
location.reload();
}, 1000);
} else {
toastr.error(response.message);
}
},
error: function (data) {
console.log("inside error");
}
});
}