const getCustomConsent = () => {
let customConsents = [];
$(".custom-consent-chb:checked").each((index, element) => {
customConsents = [...customConsents, $(element).val()]
});
if(customConsents.length == 0) {
return false;
}
return customConsents.join(',');
}
const changeCheckinAndAddMoreGuestUsersBtnDisabledOption = (disabled = true) => {
const element = $('.checkin-and-add-more-users');
if(!element) {
return;
}
if(disabled) {
element.removeAttr('id');
element.attr('id','disabled-checkings');
return;
}
element.removeAttr('id');
element.removeAttr('disabled');
//element.attr('id','checkin');
}
$(document).on('blur', ".parameter:visible", (e) => {
$(e.target).css('border-color', '')
var answer = $(e.target).val();
if(answer == 'x'){
$(e.target).css('border-color', 'red')
}
});
//$(document).on('blur', "#check_licence:visible", (e) => {
// $(e.target).css('border-color', '')
// var answer = $(e.target).val();
// if(answer == 'x'){
// $(e.target).css('border-color', 'red')
// }
//});
const validateCustomRequiredChb = () => {
let customRequiredCheckbox = true;
removeError('custom_required_checkbox');
$(".custom-required-chb").each((index, elementItem) => {
const checkboxHolder = $(elementItem).parent();
const checked = $(elementItem).is(':checked');
checkboxHolder.removeClass('is-invalid');
if(!checked) {
addError("custom_required_checkbox", "");
checkboxHolder.addClass('is-invalid');
}
customRequiredCheckbox &= checked;
});
return customRequiredCheckbox;
}
var message_errors = [];
function writeErrors() {
message_errors.sort(sortErrors);
$('#checking-error-reporting ul').html("");
for (var error of message_errors) {
$('#checking-error-reporting ul').append("
" + error[1] + "");
}
if (message_errors.length > 0) $("#checking-error-reporting h3").css('display', 'initial');
else $("#checking-error-reporting h3").css('display', 'none');
}
function addError(key, message) {
var exists = message_errors.some(function(subArray) {
return JSON.stringify(subArray) === JSON.stringify([key, message]);
});
if (!exists) message_errors.push([key, message]);
writeErrors();
}
function removeError(key) {
message_errors = message_errors.filter(function(item){ return item[0] != key });
writeErrors();
}
function sortErrors(a, b) {
if (a[1] === b[1]) {
return 0;
}
else {
return (a[1] < b[1]) ? -1 : 1;
}
}
function writeCategoryRouteErrors() {
removeError('no_categories_shown');
removeError('please_select_category');
removeError('no_duzina_trase');
removeError('Dolžina trase');
var number_of_category_options = $('#check_category option').filter(function() {
return $(this).css('display') !== 'none' && $(this).val() != 'x';
}).length;
if (number_of_category_options < 1) {
addError('no_categories_shown', "");
return;
}
else {
if ( $('#check_category').val() == 'x') {
addError('please_select_category', "");
return;
}
}
if ($('.select-ruta').length) {
var number_of_route_options = $('.select-ruta option').filter(function() {
return $(this).css('display') !== 'none';
}).length;
if (number_of_route_options <= 1) {
addError('no_duzina_trase', "");
return;
}
else {
if ( $('.select-ruta').val() == 'x') {
addError('Dolžina trase', ": 'Dolžina trase' ");
return;
}
}
}
}
function CheckInParameterCheck() {
var stop_loop = false
$('#check_category').removeClass('is-invalid');
$(".parameter").each(function(index, elementItem) {
const element = $(elementItem);
if(element) {
var route_element_id = $(this).attr('id');
var route_id = route_element_id.replace("rutes", "");
removeError(route_id);
element.removeClass('is-invalid');
}
});
$(".parameter:visible").each(function(index, elementItem) {
const element = $(elementItem);
var answer = $(this).val();
if(answer == 'x'){
if(element) {
var route_element_id = $(this).attr('id');
var route_id = route_element_id.replace("rutes", "");
var route_name = $(this).attr('name');
if (route_name != 'Dolžina trase') addError(route_id, ": " + route_name);
element.addClass('is-invalid');
}
//alert("");
stop_loop = true;
}
else {
if (element) {
var route_element_id = $(this).attr('id');
var route_id = route_element_id.replace("rutes", "");
removeError(route_id);
}
}
});
if($('#check_category').val() == 'x'){
$('#check_category').addClass('is-invalid');
//alert("");
stop_loop = true;
}
if(stop_loop === true){
$('.enable').attr('id','disabled-checkings');
return false;
}
return true;
}
function checkLicencesIfRequiredByCategory() {
var licence_element_exists = $("#check_licence").length;
var daily_licence_element_exists = $("#buy_daily_licence").length;
var is_licence_required = $('#check_category').find(':selected').data('licence_requirement');
var licence_value = $("#check_licence").val(); // Ne mora biti validno, samo da je uneto
var daily_licence = $("#buy_daily_licence").val(); // Mora imati vrednost
var is_validated = true;
removeError('check_licence');
if (is_licence_required == 1) {
if ((licence_value == '' || licence_value == null) && licence_element_exists) {
$("#check_licence").addClass('is-invalid');
addError('check_licence', "");
var is_validated = false;
}
else $("#check_licence").removeClass('is-invalid');
if ((daily_licence == '' || daily_licence == null) && daily_licence_element_exists) {
$("#buy_daily_licence").addClass('is-invalid');
var is_validated = false;
}
else $("#buy_daily_licence").removeClass('is-invalid');
}
else $("#check_licence").removeClass('is-invalid');
if (is_validated == false) return false;
return true;
}
const guestUserCheckinFormValid = () => {
if($("#createGuestUserForm")) {
return validateCreateGuestUserForm($("#createGuestUserForm"));
}
return true;
}
const registerUserCheckinFormValid = () => {
if($("#createRegisterUserCheckinForm")) {
return validateCreateRegisterUserForm($("#createRegisterUserCheckinForm"));
}
return true;
}
function cdtime(container, targetdate){
if (!document.getElementById || !document.getElementById(container)) return;
this.container=document.getElementById(container);
this.currentTime=new Date();
this.targetdate=new Date(targetdate);
this.timesup=false;
this.updateTime();
}
cdtime.prototype.updateTime=function(){
var thisobj=this;
this.currentTime.setSeconds(this.currentTime.getSeconds()+1);
setTimeout(function(){thisobj.updateTime()}, 1000); //update time every second
}
cdtime.prototype.displaycountdown=function(baseunit, functionref){
this.baseunit=baseunit;
this.formatresults=functionref;
this.showresults();
}
cdtime.prototype.showresults=function(){
var thisobj=this;
var timediff=(this.targetdate-this.currentTime)/1000; //difference btw target date and current date, in seconds
if (timediff<0){ //if time is up
this.timesup=true;
this.container.innerHTML=this.formatresults();
var parent_class = $('#'+this.container.id).parent().attr('class').split(' ')[1];
var race_id = parent_class.split("_")[1];
var element_id_o = 'podatki_za_odjavo_'+race_id;
var element_id_r = 'race_id_button_'+race_id;
//alert(element_id_r);
$('#'+element_id_o).remove();
$('.'+element_id_r).remove();
return;
}
var oneMinute=60; //minute unit in seconds
var oneHour=60*60; //hour unit in seconds
var oneDay=60*60*24; //day unit in seconds
var dayfield=Math.floor(timediff/oneDay);
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour);
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute);
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute));
if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
hourfield=dayfield*24+hourfield;
dayfield="n/a";
}
else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
minutefield=dayfield*24*60+hourfield*60+minutefield;
dayfield=hourfield="n/a";
}
else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
var secondfield=timediff;
dayfield=hourfield=minutefield="n/a";
}
this.container.innerHTML=this.formatresults(dayfield, hourfield, minutefield, secondfield);
setTimeout(function(){thisobj.showresults()}, 1000); //update results every second
}
function formatresults(){
if (this.timesup==false){ //if target date/time not yet met
var displaystring=""+arguments[0]+" "+arguments[1]+" "+arguments[2]+" ";
} else { //else if target date/time met
var displaystring="!"; //Don't display any text
}
return displaystring;
}
/*
function initCalendarHover() {
var calendarHoverConf = {
over: calendarHoverAction, // function = onMouseOver callback (REQUIRED)
timeout: 0, // number = milliseconds delay before onMouseOut
interval: 0,
out: calOutAction // function = onMouseOut callback (REQUIRED)
};
$("#calendar select").mouseleave(function(event){
event.stopPropagation();
});
$('#calendar .cal-col-2 a').click(function(){
var close = $(this).closest('tr');
if ($(close).hasClass('active')) {
$(close).removeClass('active');
}else{
$(close).addClass('active');
}
});
//$('#calendar .cal-col-1, #calendar .cal-col-2, #calendar .cal-col-3').hoverIntent(calendarHoverConf);
//$('#calendar .cal-col-1, #calendar .cal-col-2, #calendar .cal-col-3').live('click', calendarHoverAction);
var wWidth = $('body').width();
if(wWidth > 460){
var dWidth = wWidth * 0.5;
}else{
var dWidth = wWidth * 0.9;
}
$( ".checkinPopup" ).dialog({
modal: true,
width: dWidth,
autoOpen: false,
resizable: false,
draggable: false
});
}
*/
function initCalendarDescription() {
/*$(".thead").live("click", function(e) {
var trt = $(this).next();
var desc = $(this).next().find("div.holder");
$(".tdesc.open div.holder").animate({height: "0px"}, 500, 'linear', function() {
var tr = $(this).parent().parent();
$(tr).css('display', 'none');
$(tr).removeClass('open');
});
if (trt.hasClass('open')) return;
trt.addClass('open');
trt.css('display', 'table-row');
hght = desc.find("div").height();
desc.animate({height: hght}, 500, 'linear', function() {
});
});
*/
}
/**
* element must be a instance of jquery $({"selector"|element|etc})
*/
const simpleTextValidation = (element, lengthRequired = 0, displayError = false) => {
if(!element) {
return false;
}
if(displayError) {
element.removeClass('is-invalid')
}
if(element.val().length <= lengthRequired) {
if(displayError) {
element.addClass('is-invalid');
}
return false;
}
return true;
}
const validateTextualParameters = () => {
let textualParametersValid = true;
const textualParameters = $('.textual_parameter');
if(textualParameters.length == 0) {
return true;
}
textualParameters.each((index, elementItem) => {
const element = $(elementItem);
console.log("🚀 ~ file: calendar_addon.php:279 ~ textualParameters.each ~ element:", element)
var text_param_name = $(elementItem).data('param_name');
removeError(text_param_name);
element.removeClass('is-invalid');
const validationResult = simpleTextValidation(element);
if(!validationResult) {
addError(text_param_name, ": " + text_param_name);
element.addClass('is-invalid');
}
textualParametersValid &= validationResult;
});
return textualParametersValid;
}
const checkDonation = () => {
const element = document.querySelector('input[type=number][name=donation]');
const messageElement = document.querySelector('span#donation_error_message');
if(element) {
const min_donation = element.dataset.min_donation;
if(+element.value != 0) {
if(+element.value < min_donation) {
element.classList.add('is-invalid');
messageElement.style.display = 'block'
return false;
}
}
messageElement.style.display = 'none';
element.classList.remove('is-invalid');
}
return true;
}
const validateRequiredCheckbox = (selector) => {
const element = document.querySelector(`${selector}`);
if(element) {
$(selector).parent().removeClass('is-invalid')
removeError('general_terms');
const checked = document.querySelector(`${selector}`).checked;
if(!checked) {
$(selector).parent().addClass('is-invalid');
addError('general_terms', "");
}
return checked;
}
return true;
}
const validateBuyDailyLicence = (selector) => {
const dailyLicenceElement = document.querySelector(`#buy_daily_licence`);
if(dailyLicenceElement) {
dailyLicenceElement.classList.remove('is-invalid');
removeError('daily_licence');
}
if(getBuyDailyLicenceValue().length == 0) {
if(dailyLicenceElement) {
dailyLicenceElement.classList.add('is-invalid');
addError('daily_licence', "");
}
return false;
}
return true;
}
const getDonation = () => {
const element = document.querySelector('input[type=number][name=donation]');
if(element) {
return element;
}
return false;
}
function multiChangeCheckin(match_id,user,parameters,type,dataz , parameter_type,redirect,form_id){
var redirect = redirect || true;
if($("#stafeta_id").length > 0){
var stafeta_id = $("#stafeta_id").val();
}else{
var stafeta_id = null;
}
if(parameter_type == null){
}
var form_data = {
match : match_id,
club : $("#check_club").val(),
club_other: $("#check_club_other").val(),
user : user,
category: dataz.category[user],
licence: dataz.licence[user],
licence2: $("#check_licence2").val(),
parent: $("#mainUser").val(),
licence_valid: $("#licence_valid").val(),
type : type,
parameters : parameters,
param_type : (parameter_type != null) ? parameter_type[0] :' ' ,
duatlon_t : dataz.duatlon_type[user],
stafeta : parseInt(stafeta_id),
admin_id : $('#checked_by').val(),
payment_item_id : $("input[name=payment_item_id]").val(),
discount_parameter: $("input[type=hidden][name=discount_parameter]").val(),
ajax : '1'
};
//new textual logic
if($('.textual_parameter').length > 0){
var txt_p = Array();
$('#form-'+form_id).find('.textual_parameter').each(function() {
var txt_value = $(this).val();
var txt_parent = $(this).attr('id');
var txt_parameter = txt_value+"|"+txt_parent;
txt_p.push(txt_parameter);
});
}
//
form_data.txt_parameter = txt_p;
var admin_id = $('#checked_by').val();
$.ajax({
url: base_url+'ajax/changeCheckinCalendar',
type: 'POST',
async : false,
data: form_data,
dataType: "text",
success: function(msg)
{
if(type == 'check'){
//get last inserted checkin
$.get( "/ajax/get_last_user_checking/"+form_data.user, function( data ) {
console.log("🚀 ~ $.get ~ data:", data)
//$( ".result" ).html( data );
//$('.checkinPopup').dialog('close');
//window.setTimeout(function(){location.reload()},0);
if(typeof admin_id == 'undefined'){
if(data.checking_id != 'false'){
if(redirect == true){
window.setTimeout(function(){location.replace("https://prijavim.se/payments/payments_type/"+form_data.match+"/"+data.checking_id)},0);
}
}else{
if(redirect == true){
window.setTimeout(function(){location.reload()},0);
}
noty({text: '', type: "success"});
}
}else{
if(redirect == true){
window.setTimeout(function(){location.reload()},0);
}
noty({text: '', type: "success"});
}
},'json');
return;
}
if(type == 'uncheck'){
$.get( "/ajax/get_paid_status/"+form_data.user+"/"+form_data.match, function( data ) {
if(data.c_paid == 1 || data.c_paid == 4){
noty({text: '', type: "error"});
}else{
noty({text: '', type: "success"});
window.setTimeout(function(){location.reload()},0);
}
},'json');
}
//window.location.href = window.location.pathname;
return false;
//console.log("prijavim.se Database Interaction!")
$("#matchCol"+matchi).fadeOut(function(){
$(this).html(msg).fadeIn();
//initCalendarHover();
window.location.href = window.location.pathname;
})
}
});
}
//same category checking
function multiCheckingsCategory(match_id,user,parameters,type,dataz , parameter_type,redirect){
var redirect = redirect || true;
if($("#stafeta_id").length > 0){
var stafeta_id = $("#stafeta_id").val();
}else{
var stafeta_id = null;
}
var form_data = {
match : match_id,
club : $("#check_club").val(),
club_other: $("#check_club_other").val(),
user : user,
category: $("#check_category").val(),
licence: dataz.licence[user],
licence2: $("#check_licence2").val(),
licence_valid: $("#licence_valid").val(),
parent: $("#mainUser").val(),
type : type,
parameters : parameters,
param_type : parameter_type,
duatlon_t : dataz.duatlon_type[user],
stafeta : parseInt(stafeta_id),
admin_id : $('#checked_by').val(),
payment_item_id : $("input[name=payment_item_id]").val(),
discount_parameter: $("input[type=hidden][name=discount_parameter]").val(),
ajax : '1'
};
var admin_id = $('#checked_by').val();
$.ajax({
url: base_url+'ajax/changeCheckinCalendar',
type: 'POST',
async : false,
data: form_data,
dataType: "text",
success: function(msg)
{
if(type == 'check'){
//get last inserted checkin
$.get( "/ajax/get_last_user_checking/"+form_data.user, function( data ) {
//$( ".result" ).html( data );
//$('.checkinPopup').dialog('close');
//window.setTimeout(function(){location.reload()},0);
if(typeof admin_id == 'undefined'){
if(data.checking_id != 'false'){
if(redirect == true){
window.setTimeout(function(){location.replace("https://prijavim.se/payments/payments_type/"+form_data.match+"/"+data.checking_id)},0);
}
}else{
if(redirect == true){
window.setTimeout(function(){location.reload()},0);
}
noty({text: '', type: "success"});
}
}else{
if(redirect == true){
window.setTimeout(function(){location.reload()},0);
}
noty({text: '', type: "success"});
}
},'json');
}
if(type == 'uncheck'){
$.get( "/ajax/get_paid_status/"+form_data.user+"/"+form_data.match, function( data ) {
if(data.c_paid == 1 || data.c_paid == 4){
noty({text: '', type: "error"});
}else{
noty({text: '', type: "success"});
window.setTimeout(function(){location.reload()},0);
}
},'json');
}
//window.location.href = window.location.pathname;
return false;
//console.log("prijavim.se Database Interaction!")
$("#matchCol"+matchi).fadeOut(function(){
$(this).html(msg).fadeIn();
//initCalendarHover();
window.location.href = window.location.pathname;
})
}
});
}
// for raw js elements
const isElementVisible = (element) => {
return element.offsetParent !== null;
}
const getBuyDailyLicenceValue = () => {
const dailyLicenceSelect = document.querySelector(`#buy_daily_licence`);
const dailyLicenceHolder = document.querySelector("#buy-daily-licence");
if(dailyLicenceHolder && !dailyLicenceHolder.classList.contains('d-none-m')) {
return dailyLicenceSelect.value;
return 0;
}
return 0;
}
function changeCheckin(matchi, user, parameters, type, club,parameter_type,redirect, register_user = false){
var redirect = redirect || true;
//duatlon type
if($("#duatlon_type").length > 0){
var duatlon_type = $("#duatlon_type").val();
}else{
var duatlon_type = null;
}
if($("#stafeta_id").length > 0){
var stafeta_id = $("#stafeta_id").val();
}else{
var stafeta_id = null;
}
let donation = 0;
let is_donation = 0;
if(getDonation()) {
donation = getDonation().value;
is_donation = 1;
}
const bought_daily_licence = getBuyDailyLicenceValue();
var form_data = {
match : matchi,
club : $("#check_club").val(),
club_other: $("#check_club_other").val(),
user : user,
category: $("#check_category").val(),
licence: $("#check_licence").val(),
licence2: $("#check_licence2").val(),
licence_valid: $("#licence_valid").val(),
parent: $("#mainUser").val(),
type: type,
donation,
is_donation,
camp_params: getCampParameters(),
parameters : parameters,
param_type : parameter_type,
duatlon_t : duatlon_type,
stafeta : parseInt(stafeta_id),
payment_item_id : $("input[name=payment_item_id]").val(),
discount_parameter: $("input[type=hidden][name=discount_parameter]").val(),
accept_general_terms: getCheckboxValue('input[type=checkbox][name=accept_general_terms]'),
accept_using_images: getCheckboxValue('input[type=checkbox][name=accept_using_images]'),
bought_daily_licence,
custom_consents: getCustomConsent(),
ajax : '1'
};
var admin_id = $('#checked_by').val();
if(typeof admin_id == 'undefined'){
//console.log("🚀 ~ file: calendar_addon.php:507 ~ changeCheckin ~ typeof admin_id == 'undefined':", typeof admin_id == 'undefined')
}else{
form_data.admin_id = admin_id;
}
//new textual logic
var txt_p = Array();
$('.textual_parameter').each(function() {
var txt_value = $(this).val();
var txt_parent = $(this).attr('id');
var txt_parameter = txt_value+"|"+txt_parent;
txt_p.push(txt_parameter);
});
form_data.txt_parameter = txt_p;
var redirect_to = '';
if (register_user != false) form_data.register_user = register_user;
$.ajax({
url: base_url + 'ajax/changeCheckinCalendar',
type: 'POST',
async: false,
data: form_data,
dataType: "text",
success: function (msg) {
if (type == 'check') {
//get last inserted checkin
$.get("/ajax/get_last_user_checking/" + form_data.user, function (data) {
//$( ".result" ).html( data );
//$('.checkinPopup').dialog('close');
//window.setTimeout(function(){location.reload()},0);
if(data.c_paid == 1) {
noty({text: '', type: "success"});
}
if (typeof admin_id == 'undefined') {
if (data.checking_id != 'false') {
if (redirect == true) {
if (redirect_to != '') {
var m = 'all';
//https://prijavim.se/payments/proforma/all/2700
window.setTimeout(function () { location.replace("https://prijavim.se/payments/proforma/all/" + form_data.match + "/") }, 0);
} else {
//var m = form_data.match;
window.setTimeout(function () { location.replace("https://prijavim.se/payments/payments_type/" + form_data.match + "/" + data.checking_id) }, 0);
}
// noty({text: '', type: "success"});
}
} else {
//if(redirect == true){
// window.setTimeout(function(){location.reload()},0);
//}
//noty({text: '', type: "success"});
}
} else {
var url = window.location.href;
if (redirect == true) {
if (url.indexOf("calendar") >= 0 && url.indexOf("group_register") < 0) {
//window.setTimeout(function(){location.replace("https://prijavim.se/payments/payments_type/"+form_data.match+"/"+data.checking_id)},0);
//for all users
window.setTimeout(function () { location.replace("https://prijavim.se/payments//proforma/all/" + form_data.match + "/") }, 0);
} else {
if (redirect_to != '') {
var m = 'all';
//https://prijavim.se/payments/proforma/all/2700
window.setTimeout(function () { location.replace("https://prijavim.se/payments/proforma/all/" + form_data.match + "/") }, 0);
} else {
window.setTimeout(function () { location.reload() }, 0);
}
}
}
//noty({text: '', type: "success"});
}
}, 'json');
}
if (type == 'uncheck') {
$.get("/ajax/get_paid_status/" + form_data.user + "/" + form_data.match, function (data) {
console.log("🚀 ~ data:", data)
if (data.c_paid == 1 || data.c_paid == 4) {
noty({ text: '', type: "error" });
} else {
noty({ text: '', type: "success" });
window.setTimeout(function () { location.reload() }, 0);
}
}, 'json');
}
//window.location.href = window.location.pathname;
return false;
//console.log("prijavim.se Database Interaction!")
$("#matchCol" + matchi).fadeOut(function () {
$(this).html(msg).fadeIn();
//initCalendarHover();
window.location.href = window.location.pathname;
})
}
});
}
const getCheckboxValue = (selector) => {
const element = document.querySelector(`${selector}`);
if(element) {
return element.checked ? 1 : 0
}
return -1;
}
const campParamExists = () => {
if(document.getElementById('camp_param_main')) {
return true;
}
return false;
}
const vallidateCampParam = () => {
$('#camp_param_main').removeClass('is-invalid');
if(campParamExists()) {
removeError('camp_main');
if(getMainCampParamValue() == -1) {
$('#camp_param_main').addClass('is-invalid');
addError('camp_main', "");
return false;
}
if(getMainCampParamValue() == 4) {
// ovde proveriti da li su vrenosti za polja number i da li su setovana, ako nisu vratiti false da se blokira dugme za checkinGuestUser
let campParamValid = true;
document.querySelectorAll('.camp-child-input').forEach((element) => {
element.classList.remove('is-invalid');
var camp_param_name = $(element).data('param_name');
removeError(camp_param_name);
if((element.value == '') || (element.value < 0)) {
element.classList.add('is-invalid');
addError(camp_param_name, ": " + camp_param_name);
campParamValid &= false;
}
console.log("Odjen🚀 ~ file: calendar_addon.php:667 ~ document.querySelectorAll ~ element.name:", element.name)
if(element.name == 'camp_param_child_1_3') {
console.log("🚀 ~ file: calendar_addon.php:667 ~ document.querySelectorAll ~ element.name:", element.name)
const errorMessageElement = document.querySelector(".error_message_camp_param_child_1_3");
if(errorMessageElement) {
errorMessageElement.classList.add('d-none-m');
if(element.value > 2) {
document.querySelector(".error_message_camp_param_child_1_3").classList.remove('d-none-m');
element.classList.add('is-invalid');
addError(camp_param_name, "");
campParamValid &= false;
}
}
}
});
return campParamValid;
}
}
return true;
}
const getMainCampParamValue = () => {
const element = document.getElementById('camp_param_main');
if(element) return element.value;
return false;
}
const getCampParameters = () => {
if(campParamExists()){
let campParamValues = [
`${$('#camp_param_main').data('param_id')}$$${getMainCampParamValue()}`
];
if(getMainCampParamValue() == 4) {
$('.camp-child-input').each((index, element) => {
const elementValue = `${$(element).data('param_id')}$$${$(element).val()}`
campParamValues.push(elementValue)
});
return campParamValues.join(',');
}
return campParamValues.join(',');
}
return '-1';
}
//const calculateCampPrice = () => {
// const useCamp = $("#camp_param_main").val();
// if(useCamp == 4) {
// const price = +$("#camp_param_main").data('price');
// let childElementsVal = 1;
// $('.camp-child-input').each((index, element) => {
// if(($(element).val() != '') && ($(element).data('param_id') != 6)) {
// childElementsVal *= +$(element).val();
// console.log('childElementsVal', childElementsVal);
// }
// });
//
// const totalcampPrice = childElementsVal * price;
// const currencySing = $("#camp-param-currency").val();
// $('#camp-price').html(`(${totalcampPrice}${currencySing})`)
// return;
// }
// $('#camp-price').html('')
//}
const validateBasicForm = () => {
let formErrors = [];
let formValid = true;
if(!validateTextualParameters()) {
formErrors = [...formErrors, 'Textual parameter invalid'];
formValid &= false;
}
if(!validateBuyDailyLicence()) {
formErrors = [...formErrors, 'Daily licence invalid'];
formValid &= false;
}
if(!CheckInParameterCheck()) {
formErrors = [...formErrors, 'Parameters invalid'];
formValid &= false;
}
if(!checkDonation()) {
formErrors = [...formErrors, 'Donation invalid'];
formValid &= false;
}
if(!vallidateCampParam()) {
formErrors = [...formErrors, 'Camp parameter invalid'];
formValid &= false;
}
if(!validateRequiredCheckbox('input[type=checkbox][name=accept_general_terms]')) {
formErrors = [...formErrors, 'Required checkbox invalid'];
formValid &= false;
}
if(!guestUserCheckinFormValid() ) {
formErrors = [...formErrors, 'Guest user checkin form invalid'];
formValid &= false;
}
if(!registerUserCheckinFormValid() ) {
formErrors = [...formErrors, 'Register user checkin form invalid'];
formValid &= false;
}
if(!validateCustomRequiredChb()) {
formErrors = [...formErrors, 'Custom required checkbox invalid'];
formValid &= false;
}
if(!checkLicencesIfRequiredByCategory()) {
formErrors = [...formErrors, 'Licence fields are required for this category'];
formValid &= false;
}
writeCategoryRouteErrors();
writeErrors();
console.log("🚀 ~ file: calendar_addon.php:849 ~ validateBasicForm ~ formErrors:", formErrors)
console.log("🚀 ~ file: calendar_addon.php:855 ~ validateBasicForm ~ formValid:", formValid)
return formValid;
}
$(document).ready(function() {
$('.remember-click').on('click',function(){
//console.log(this);
datas = {};
datas.match_id = $(this).attr('data-match_id');
datas.selector = this.id;
var href = 'https://prijavim.se/register/newUser/'+$(this).attr('data-match_id');
$('.register-user').attr('href',href);
$.post(base_url+"ajax/openChecking/", datas, function(data) {
//$( "#race_id_checkin_"+match_id ).html(data);
},'html');
});
//on select change
$( ".parameter" ).live('change',function() {
var selected_value = this.value;
let donationValid = true;
if(getDonation()) {
donationValid = checkDonation();
}
if(validateBasicForm()){
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(false);
$('.enable').removeAttr('id');
$('.enable').attr('id','checkin');
}else{
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(true);
$('.enable').removeAttr('id');
$('.enable').attr('id','disabled-checkings');
}
});
$("#buy_daily_licence:visible").live('change',function() {
if(validateBasicForm()){
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(false);
$('.enable').removeAttr('id');
$('.enable').attr('id','checkin');
}else{
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(true);
$('.enable').removeAttr('id');
$('.enable').attr('id','disabled-checkings');
}
});
$(document).live('keyup', '.camp-child-input', (e) => {
if(validateBasicForm()){
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(false);
$('.enable').removeAttr('id');
$('.enable').attr('id','checkin');
}else{
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(true);
$('.enable').removeAttr('id');
$('.enable').attr('id','disabled-checkings');
}
//calculateCampPrice();
});
//$(document).on('keyup', 'input[type=text][name=licence]', (e) => {
// if(validateRequiredCheckbox('input[type=checkbox][name=accept_general_terms]') && CheckInParameterCheck() && checkDonation() && guestUserCheckinFormValid() && vallidateCampParam() && validateBuyDailyLicence()){
// changeCheckinAndAddMoreGuestUsersBtnDisabledOption(false);
// $('.enable').removeAttr('id');
// $('.enable').attr('id','checkin');
// }else{
// changeCheckinAndAddMoreGuestUsersBtnDisabledOption(true);
// $('.enable').removeAttr('id');
// $('.enable').attr('id','disabled-checkings');
// }
//});
$(document).on('blur', 'input[type=text][name=licence]', (e) => {
if(validateBasicForm()){
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(false);
$('.enable').removeAttr('id');
$('.enable').attr('id','checkin');
}else{
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(true);
$('.enable').removeAttr('id');
$('.enable').attr('id','disabled-checkings');
}
});
$( "#camp_param_main" ).live('change',function() {
if(validateBasicForm()){
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(false);
$('.enable').removeAttr('id');
$('.enable').attr('id','checkin');
}else{
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(true);
$('.enable').removeAttr('id');
$('.enable').attr('id','disabled-checkings');
}
});
$(document).live('keyup', 'input[type=number][name=donation]', (e) => {
if(validateBasicForm()){
$('.enable').removeAttr('id');
$('.enable').attr('id','checkin');
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(false);
}else{
$('.enable').removeAttr('id');
$('.enable').attr('id','disabled-checkings');
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(true);
}
});
$(document).live('keyup', '.textual_parameter', (e) => {
if(validateBasicForm()){
$('.enable').removeAttr('id');
$('.enable').attr('id','checkin');
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(false);
}else{
$('.enable').removeAttr('id');
$('.enable').attr('id','disabled-checkings');
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(true);
}
});
$(document).live('change', 'input[type=checkbox][name=accept_general_terms]', (e) => {
if(validateBasicForm()){
$('.enable').removeAttr('id');
$('.enable').attr('id','checkin');
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(false);
}else{
$('.enable').removeAttr('id');
$('.enable').attr('id','disabled-checkings');
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(true);
}
});
$('.toggleInfo').live('click',function(e){
//alert(this.id);
//alert(e.target.id);
$('.show_additional_data').hide();
$('#descCol'+this.id).show();
})
/*
$('.toggleInfo').click(function(){
var trt = $(this).closest('tr').next();
var desc = $(this).closest('tr').next().find("div.holder");
//$('.tdesc').css('display', 'none');
$(".tdesc.open div.holder").animate({height: "0px"}, 500, 'linear', function() {
$('.tdesc').css('display', 'none');
$('.tdesc').removeClass('open');
});
if (trt.hasClass('open')) return;
trt.addClass('open');
trt.css('display', 'table-row');
hght = desc.find("div").height();
desc.animate({height: hght}, 500, 'linear', function() {
});
})
*/
/// We need to send request to database to add or remove specific user checkin for a specific match!
$("#checkin").live("click", function(e) {
e.preventDefault($('.textual_parameter').val());
var match = $(this).attr("match");
var club = $(this).attr("club");
var user_id = $(".personCheck"+match).val();
var textual_parameter = $('.textual_parameter').val();
var param_id = $('.textual_parameter').attr('id');
var stop_loop = false;
$(".parameter:visible").each(function() {
var answer = $(this).val();
if(answer == 'x'){
alert("");
event.preventDefault();
stop_loop = true;
return false;
}
});
if($('#check_category').val() == 'x'){
alert("");
event.preventDefault();
stop_loop = true;
return false;
}
if(stop_loop === true){
return false;
}
if($('#check_licence').hasClass('licence_important')){
if($('#check_licence').val().length == 0 && $('#check_licence2').val().length == 0){
alert('');
return false;
}
//Licenca je obavezna
}
var parameters = new Array();
$(".parameter:visible").each(function() {
// Ukoliko ima donaciju i ukoliko je name parent-a 'Dolžina trase', tada izuzeti dohvatanje cene
var answer = $(this).val();
var parent = $(this).attr("parent");
var parameter = answer+"$$"+parent;
parameters.push(parameter);
});
if(match == 4966) {
if($(".parameter.select-ruta")) {
var answer = $(".parameter.select-ruta").val();
var parent = $(".parameter.select-ruta").attr("parent");
var parameter = answer+"$$"+parent;
parameters.push(parameter);
}
}
// Proveriti da li je guest prijava, ako jeste pozvati tu funkciju
if($(e.target).hasClass('btn-guest-user-login')) {
console.log("Odavde pozivam 1130");
if(!$(e.target).attr('disabled')) {
$(e.target).attr('disabled', true);
checkinGuestUser(match, parameters, textual_parameter, true, e.target);
return;
}
}
// Proveriti da li je prijava gde se registruje nov korisnik i povezuje sa ulogovanim korisnikom
var register_user = false;
if($(e.target).hasClass('btn-register-user-login')) {
console.log("Odavde pozivam 1130");
if(!$(e.target).attr('disabled')) {
$(e.target).attr('disabled', true);
var child_user_id = checkinRegisterUser(match, parameters, textual_parameter, true, club);
console.log(child_user_id);
if (child_user_id == null) return;
else {
user_id = child_user_id;
var register_user = true;
}
//return;
}
}
if(!validateTextualParameters()) {
return false;
}
const isCampParamExists = campParamExists();
console.log("🚀 ~ file: calendar_addon.php:990 ~ $ ~ textual_parameter:", textual_parameter)
if(textual_parameter){
var stextural_value = textual_parameter;
var sparam_id = param_id;
var test = 0+"$$"+param_id;
//parameters.push(stextural_value);
parameters.push(test);
changeCheckin(match, user_id, parameters, "check", club,stextural_value,true, register_user);
}else{
changeCheckin(match, user_id, parameters, "check", club,null,true, register_user);
}
// changeCheckin(match, user_id, parameters, "check", club,null);
$.fancybox.close();
});
$(".checkin-and-add-more-users").live("click", function(e) {
console.log("Odavde krećen 1060");
e.preventDefault();
$("input[type=hidden][name=checkin-check-more-users]").val(1);
console.log("🚀 ~ file: calendar_addon.php:1156 ~ $ ~ ", $("input[type=hidden][name=checkin-check-more-users]").val())
var match = $(this).attr("match");
//var club = $(this).attr("club");
//var user_id = $(".personCheck"+match).val();
//var textual_parameter = $('.textual_parameter').val();
//var param_id = $('.textual_parameter').attr('id');
//var stop_loop = false;
//
//$(".parameter:visible").each(function() {
// var answer = $(this).val();
// if(answer == 'x'){
// alert("");
// event.preventDefault();
// stop_loop = true;
// return false;
// }
//});
//
//if($('#check_category').val() == 'x'){
// alert("");
// event.preventDefault();
// stop_loop = true;
// return false;
//}
//
//if(stop_loop === true){
// return false;
//}
//
//
//if($('#check_licence').hasClass('licence_important')){
// if($('#check_licence').val().length == 0 && $('#check_licence2').val().length == 0){
// alert('');
// return false;
// }
// //Licenca je obavezna
//}
//
//var parameters = new Array();
//$(".parameter:visible").each(function() {
// // Ukoliko ima donaciju i ukoliko je name parent-a 'Dolžina trase', tada izuzeti dohvatanje cene
// var answer = $(this).val();
// var parent = $(this).attr("parent");
// var parameter = answer+"$$"+parent;
// parameters.push(parameter);
//})
//
//// Proveriti da li je guest prijava, ako jeste pozvati tu funkciju
//checkinGuestUser(match, parameters, textual_parameter, true);
//$(e.target).attr('disabled', false);
if($("#checkin")) {
$("#checkin").click();
}
$.post('/ajax/writeStoreGuestSession', { match_id: match }).done(function(response) {
location.reload();
})
.fail(function(jqXHR, textStatus, errorThrown) {
});
// location.reload();
});
$(".checkout").live("click", function(e) {
e.preventDefault();
match = $(this).attr("match");
user_id = $(".personUncheck"+match).val();
$('#race_id_checkin_'+match).dialog('close');
$("#checkoutConfirm").dialog({
modal: true,
width: 401,
resizable: false,
draggable: false
});
$('.close').on('click',function(){
$('#checkoutConfirm').dialog('close');
});
$('.checkout-me').live('click',function(){
changeCheckin(match, user_id, 0, "uncheck");
});
//changeCheckin(match, user_id, 0, "uncheck");
});
var wWidth = $('body').width();
if(wWidth > 601){
var dWidth = 601;
}else{
var dWidth = wWidth * 0.9;
}
$( ".checkinPopup" ).dialog({
modal: true,
width: dWidth,
autoOpen: false,
resizable: false,
draggable: false
});
$( ".checkoutButton" ).live("click", function(e) {
e.preventDefault();
var popup = $( "#"+e.target.id.replace('button', 'checkin') );
// if user has childs there is a popup for choosing which player to checkin.
if ($.trim(popup.html()) != "") {
// show popup
popup.dialog( "open" );
} else {
// if there is no popup, then user does not have childs. lets check him out. ADD show confirmation popup
var match = $(this).data('match_id');
var user_id = $(this).data('user_id');
$('.chechout-me').attr('data-match_id',match);
$('.chechout-me').attr('data-user_id',user_id);
$("#checkoutConfirm").dialog({
modal: true,
width: dWidth,
resizable: false,
draggable: false
});
$('.close').on('click',function(){
$('#checkoutConfirm').dialog('close');
});
$('.checkout-me').live('click',function(){
changeCheckin(match, user_id, 0, "uncheck");
});
}
});
$('#select-checkin').live('change',function(e){
var optionSelected = $("option:selected", this);
var valueSelected = this.value;
var match = $('#select-checkin').attr('data_id');
var main_user = $(this).children(":selected").attr("id");
if(main_user > 0){
$('#showcalpopup'+match).attr('href', 'https://prijavim.se/ajax/userCheckinForm/main/'+match+'/'+valueSelected+'/'+main_user);
}else{
$('#showcalpopup'+match).attr('href', 'https://prijavim.se/ajax/userCheckinForm/main/'+match+'/'+valueSelected);
}
});
$( ".checkinButton" ).live("click", function(e) {
message_errors = [];
e.preventDefault();
$(".checkinPopup").dialog('destroy').remove();
//var match_id = $( e.target ).data("match_id");
var match_id = $(this).attr('data-match_id');
//var stop = $( e.target ).data("stop");
var stop = $(this).attr('data-stop');
$('.display-uidialog').empty();
//if($('#race_id_checkin_'+match_id+'').length == 0){
if (!$( this ).hasClass("direct")) {
$('.display-uidialog').html('');
}
if($( "#race_id_checkin_"+match_id )) {
$('.display-uidialog').html('');
}
var popup = $( "#race_id_checkin_"+match_id );
var close_pop = $('.checkinPopup ');
popup.dialog({
autoOpen: false,
modal: true,
width: dWidth,
autoOpen: false,
resizable: false,
draggable: false,
zIndex: 100002,
close : function(event, ui) {
$(".checkinPopup").dialog('destroy').remove();
}
});
//get dialog
datas = {};
datas.match_id = match_id;
datas.stop = stop;
// if user has childs there is a popup for choosing which player to checkin.
if (!$( this ).hasClass("load-ajax")) {
// show popup
$.post(base_url+"ajax/get_popup/"+match_id, datas, function(data) {
$( "#race_id_checkin_"+match_id ).html(data);
},'html');
popup.dialog( "open" );
} else {
// if there is no popup, then user does not have childs. lets show him the checkin form.
$.get( $(this).attr('href'), function( data ) {
console.log("🚀 ~ file: calendar_addon.php:1181 ~ $.get ~ data:", data)
if(data.includes('competitor_global_limit_error')) {
console.log("🚀 ~ file: calendar_addon.php:1183 ~ $.get ~ data.includes('competitor_global_limit_error'):", data.includes('competitor_global_limit_error'))
const error = JSON.parse(data);
$(".checkinPopup").dialog('destroy').remove();
noty({text: error.message, type: "error"});
return;
}
popup.html(data);
popup.dialog("open");
validateBasicForm();
console.log("🚀 ~ file: calendar_addon.php:1192 ~ $.get ~ popup.dialog(open):", popup.dialog("open"))
});
/*popup.load($(e.target).attr('href'), function() {
popup.dialog("open");
});*/
}
//}
});
$("#check_club").live("change", function() {
if ($("#check_club").val() == -2)
$("#check_club_other").css('display', 'inline');
else
$("#check_club_other").css('display', 'none');
});
$(".ajax-func").fancybox({
fitToView : false,
autoSize : true,
minWidth : 220,
minHeight : 520,
closeClick : false,
openEffect : 'none',
closeEffect : 'none'
});
//initCalendarHover();
//initCalendarDescription();
//$( "#calendar" ).accordion();
$('.register-user').click(function () {
if (/\/invite_checkin/i.test(window.location)) {
var match_id = $('.invite-checking-button').data('match_id');
$.ajax({
url: base_url + 'ajax/writeRegisterRedirectToInviteCheckin/',
async: false,
data: { match_id: match_id },
type: 'GET',
success: function (data) {
}
});
}
})
})
function validateAfterLicenceChange() {
setTimeout(function () {
if(validateBasicForm()){
$('.enable').removeAttr('id');
$('.enable').attr('id','checkin');
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(false);
}else{
$('.enable').removeAttr('id');
$('.enable').attr('id','disabled-checkings');
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(true);
}
}, 1300);
}
function addToMyCalendar(id,match,click){
var send = {};
send.user_id = id;
send.match_id = match;
if($(click).attr('data-action') == 'add'){
//add to my calendar
if (confirm("")) {
//procced
send.action = 'add';
$.post( "/ajax/addRaceToMyCalendar", send,function( data ) {
$(click).removeClass('my-calendar-btn');
$(click).removeClass('grey');
$(click).attr('data-action','remove');
$(click).addClass('my-calendar-btn-green');
$(click).html(' ');
$('#event_'+match).addClass('my-calendar-yes');
});
} else {
return false;
}
}else if($(click).attr('data-action') == 'remove'){
//remove from my calendar
if (confirm("")) {
send.action = 'remove';
$.post( "/ajax/addRaceToMyCalendar", send,function( data ) {
$(click).removeClass('my-calendar-btn-green');
$(click).attr('data-action','add');
$(click).addClass('my-calendar-btn');
$(click).addClass('grey');
$(click).html(' ');
$('#event_'+match).removeClass('my-calendar-yes');
});
}else{
return false;
}
}
}
$(document).on('click', ".guest-checkin", (e) => {
// $('#checkin-like-quest').css('display', 'initial');
$('#checkin-like-quest').data('match_id', $(e.target).data('match_id'));
});
$(document).on('click', '.checkinbtn', (e) => {
const element = $(e.target);
if (element.hasClass('guest-checkin') && $(element).data('is_relay') == 1) $('#checkin-like-quest').css('display', 'none');
else {
if(!element.hasClass('guest-checkin') && ( (window.location.href.includes("calendar/checkings") || window.location.href.includes("calendar/search_results")))) {
$('#checkin-like-quest').css('display', 'none');
}
else $('#checkin-like-quest').css('display', 'initial');
}
});
function createQuestCheckinRedirectQuestion(match_id) {
$('.display-uidialog').html(`
`);
var popupNew = $( "#new_guest_dialog" );
popupNew.dialog({
autoOpen: false, // Keep the dialog closed initially
modal: true, // Make the dialog modal (prevents interaction with the rest of the page)
width: 400,
height: 250
});
popupNew.dialog("open");
$(".guest_action_redirect").click(function () {
popupNew.dialog("close");
var protocol = window.location.protocol;
var hostname = window.location.hostname;
window.location.href = protocol + '//www.' + hostname + '/payments/proforma/all/'+match_id;
});
$(".guest_action_add_more").click(function () {
popupNew.dialog("close");
createNewQuestCheckin(match_id);
});
}
const createCheckinPopup = (match_id) => {
var wWidth = $('body').width();
if(wWidth > 601){
var dWidth = 601;
}else{
var dWidth = wWidth * 0.9;
}
var popup = $( "#race_id_checkin_"+match_id );
var close_pop = $('.checkinPopup ');
popup.dialog({
autoOpen: false,
modal: true,
width: dWidth,
autoOpen: false,
resizable: false,
draggable: false,
zIndex: 100002,
close : function(event, ui) {
$(".checkinPopup").dialog('destroy').remove();
}
});
return popup;
}
const getRegisterUserCheckinForm = (match_id, popup) => {
message_errors = [];
$.ajax({
url: `${base_url}ajax/getRegisterUserCheckinForm/main/${match_id}/-1`,
type: 'GET',
async: true,
success: (data) => {
popup.html(data);
popup.dialog("open");
$("#login-popupbox").dialog("close");
setTimeout(() => {
window.scrollTo({
top: 20,
left: 0,
behavior: 'smooth'
});
}, 200);
$('.ui-dialog').css('top', '40px');
const registerUserFormTitle = 'Checkin more people';
$('.register-user-form-title').html(registerUserFormTitle)
}
});
}
var visible_pop_up_lines;
const getGuestCheckinForm = (match_id, popup) => {
message_errors = [];
$.ajax({
url: `${base_url}ajax/getGuestUserCheckinForm/main/${match_id}/-1`,
type: 'GET',
async: true,
success: (data) => {
popup.html(data);
popup.dialog("open");
$("#login-popupbox").dialog("close");
setTimeout(() => {
window.scrollTo({
top: document.querySelector(`#race_id_checkin_${match_id}`).offsetTop,
left: 0,
behavior: 'smooth'
});
}, 200);
$('.ui-dialog').css('top', '40px');
let userNumber = +$('#number_of_checkings').val() + 1;
var number_of_checkings = 0;
const guestUserFormTitle = number_of_checkings < 1 ? `` : ` ${userNumber}`
visible_pop_up_lines = $('.popup-line-param:visible');
//$(visible_pop_up_lines).addClass("disable_guest_params");
$('.guest-user-form-title').html(guestUserFormTitle)
// Ukoliko postoji forma za unos korisnika dodati dodatnu proveru pri validaciji, da validira i polja forme da li su ok, pa tek onda da se salje i odblokira dugme
if($("#createGuestUserForm")) {
$("#createGuestUserForm :input").each(function(){
$(this).live('blur', () => {
console.log("Ovaj blur 1514");
validateGuestUserFormElement(this);
});
});
}
}
});
}
$(document).on('click', '#checkin-like-quest', (e) => {
const element = $(e.target);
const match_id = element.data('match_id');
$('.display-uidialog').html('');
const popup = createCheckinPopup(match_id);
getGuestCheckinForm(match_id, popup);
$(document).on('click', '#btnCreateGuestUser', () => validateCreateGuestUserForm($("#createGuestUserForm")));
});
function createNewQuestCheckin(match_id) {
$('.display-uidialog').html('');
const popup = createCheckinPopup(match_id);
getGuestCheckinForm(match_id, popup);
$(document).on('click', '#btnCreateGuestUser', () => validateCreateGuestUserForm($("#createGuestUserForm")));
}
const validateEmail = (email) => {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
const storeGuestUser = (form_data) => {
$.ajax({
url: `${base_url}ajax/storeGuestUser/`,
type: 'POST',
async : false,
data: form_data,
dataType: 'json',
success: (data) => {
//console.log("🚀 ~ file: calendar_addon.php:1285 ~ storeGuestUser ~ data:", data)
}
});
}
const getGuestUserFormData = () => {
const userFormData = {}
$("#createGuestUserForm").serialize().split('&').forEach((element) => {
const elementParts = element.split('=');
userFormData[elementParts[0]] = elementParts[1];
});
return userFormData;
}
const getRegisterUserFormData = () => {
const userFormData = {}
$("#createRegisterUserCheckinForm").serialize().split('&').forEach((element) => {
const elementParts = element.split('=');
userFormData[elementParts[0]] = elementParts[1];
});
return userFormData;
}
var create_user_errors = [];
const validateCreateGuestUserForm = (form) => {
let result = true;
create_user_errors = [];
$(form).find(".req").each(function(index, element) {
result &= validateGuestUserFormElement(element);
});
removeError('create_guest_user');
if ( create_user_errors.length > 0 ) {
var create_user_error_message = create_user_errors.join(", ");
addError('create_guest_user', ": " + create_user_error_message);
}
return result;
}
const validateGuestUserFormElement = (element) => {
if ($.trim($(element).val()) == '' || $.trim($(element).val()) == 'x') {
if ( $(element).is('[data-guest_ch_name]') ) {
create_user_errors.push( $(element).data('guest_ch_name') );
}
$(element).attr('style', 'border:solid 1px red;');
return false;
}
const elementName = $(element).attr('name');
removeError( $(element).data('guest_ch_name') );
if ((elementName == 'guest_user_email') && (!validateEmail($(element).val()))) {
$(element).attr('style', 'border:solid 1px red;');
$(`#${$(element).attr('id')}_error_message`).html('Napaka, e-mail naslov ni pravilnega formata.');
addError($(element).data('guest_ch_name'), "");
return false;
}
// if(elementName == 'terms') {
// console.log("Validacija terms-a: ")
// }
removeError( $(element).data('guest_terms') );
if ((elementName == 'terms') && !$(element).is(":checked")) {
$('.terms-text').attr('style', 'color: red;');
addError($(element).data('guest_terms'), "Please accept guest creation terms");
return false;
}
$(element).attr('style', '');
$(`#${$(element).attr('id')}_error_message`).html('');
return true;
}
const validateCreateRegisterUserForm = (form) => {
let result = true;
create_user_errors = [];
$(form).find(".req").each(function(index, element) {
result &= validateRegisterUserFormElement(element);
});
removeError('create_register_user');
if ( create_user_errors.length > 0 ) {
var create_user_error_message = create_user_errors.join(", ");
addError('create_register_user', ": " + create_user_error_message);
}
return result;
}
const validateRegisterUserFormElement = (element) => {
if ($.trim($(element).val()) == '' || $.trim($(element).val()) == 'x') {
if ( $(element).is('[data-register_ch_name]') ) {
create_user_errors.push( $(element).data('register_ch_name') );
}
$(element).attr('style', 'border:solid 1px red;');
return false;
}
const elementName = $(element).attr('name');
removeError( $(element).data('register_ch_name') );
if ((elementName == 'register_user_email') && (!validateEmail($(element).val()))) {
$(element).attr('style', 'border:solid 1px red;');
$(`#${$(element).attr('id')}_error_message`).html('Napaka, e-mail naslov ni pravilnega formata.')
addError($(element).data('register_ch_name'), "");
return false;
}
// if(elementName == 'terms') {
// console.log("Validacija terms-a: ")
// }
removeError( $(element).data('register_user_terms') );
if ((elementName == 'terms') && !$(element).is(":checked")) {
$('.terms-text').attr('style', 'color: red;');
addError($(element).data('register_user_terms'), "Please accept user creation terms");
return false;
}
$(element).attr('style', '');
$(`#${$(element).attr('id')}_error_message`).html('');
return true;
}
// Potrebno je napraviti deo gde ce se validirati na osnovu datuma da se izlistaju kategorije koje su dostupne
$('#guest_user_year,#register_user_year').live('change',function(){
showUserCategories();
})
$('#guest_user_gender,#register_user_gender').live('change',function(){
showUserCategories()
})
const showUserCategories = () => {
$("#check_category").val('x')
if ( $("#guest_user_year").length > 0 ) {
var user_gender = $("#guest_user_gender").val().substr(0,1);
var user_age = (+(new Date).getFullYear()) - (+$("#guest_user_year").val())
}
else if ( $("#register_user_year").length > 0 ) {
var user_gender = $("#register_user_gender").val().substr(0,1);
var user_age = (+(new Date).getFullYear()) - (+$("#register_user_year").val())
}
// Ovde dohvatiti sve opcije kategorija
$("#check_category option").each((index, element) => {
const categoryMinAge = $(element).data('min_age');
const categoryGender = $(element).data('gender');
const categoryMaxAge = $(element).data('max_age');
if ((user_age >= categoryMinAge) && (user_age <= categoryMaxAge) && (!categoryGender || categoryGender == 'u' || categoryGender == user_gender)) {
$(element).css('display', 'initial');
}else{
$(element).css('display', 'none');
}
});
}
function checkinGuestUser(match, parameters, parameter_type, redirect, button_element = null){
var redirect = redirect || true;
//duatlon type
if($("#duatlon_type").length > 0){
var duatlon_type = $("#duatlon_type").val();
}else{
var duatlon_type = null;
}
if($("#stafeta_id").length > 0){
var stafeta_id = $("#stafeta_id").val();
}else{
var stafeta_id = null;
}
let donation = 0;
let is_donation = 0;
if(getDonation()) {
donation = getDonation().value;
is_donation = 1;
}
var form_data = {
match,
club: $("#check_club").val(),
club_other: $("#check_club_other").val(),
category: $("#check_category").val(),
licence: $("#check_licence").val(),
licence2: $("#check_licence2").val(),
licence_valid: $("#licence_valid").val(),
parent: $("#mainUser").val(),
donation,
is_donation,
parameters: parameters,
param_type: parameter_type,
duatlon_t: duatlon_type,
stafeta: parseInt(stafeta_id),
payment_item_id: $("input[name=payment_item_id]").val(),
accept_general_terms: getCheckboxValue('input[type=checkbox][name=accept_general_terms]'),
accept_using_images: getCheckboxValue('input[type=checkbox][name=accept_using_images]'),
discount_parameter: $("input[type=hidden][name=discount_parameter]").val(),
custom_consents: getCustomConsent(),
ajax: '1'
};
var admin_id = $('#checked_by').val();
if(typeof admin_id == 'undefined'){
console.log('bll');
}else{
form_data.admin_id = admin_id;
}
var txt_p = Array();
$('.textual_parameter').each(function() {
var txt_value = $(this).val();
var txt_parent = $(this).attr('id');
var txt_parameter = txt_value+"|"+txt_parent;
txt_p.push(txt_parameter);
});
form_data.txt_parameter = txt_p;
form_data.guest_user = getGuestUserFormData();
var redirect_to = '';
console.log("🚀 ~ file: calendar_addon.php:1680 ~ checkinGuestUser ~ form_data:", form_data)
$.ajax({
url: base_url + 'ajax/storeGuestUserChecking',
type: 'POST',
async: false,
data: form_data,
dataType: "text",
success: function (data) {
const result = JSON.parse(data)
if(result.status == false) {
noty({text: result.message, type: "error"});
$(button_element).attr('disabled', false);
if (result.guest_already_checked_in == true) return;
}
// Ovde ispitati da li je gost prijava u pitanju, ako jeste i ako je kliknuto na prijavi i dodaj takmicara tada mu prikazati poruku da je uspesno ulogovan i otvoriti novu formu za unos
const isCheckinAndAddMoreGuestUsersElement = $("input[type=hidden][name=checkin-check-more-users]");
console.log("🚀 ~ checkinGuestUser ~ isCheckinAndAddMoreGuestUsersElement:", isCheckinAndAddMoreGuestUsersElement)
console.log("🚀 ~ checkinGuestUser ~ isCheckinAndAddMoreGuestUsersElement.val():", isCheckinAndAddMoreGuestUsersElement.val())
if(isCheckinAndAddMoreGuestUsersElement && (isCheckinAndAddMoreGuestUsersElement.val() == 1)) {
$("input[type=hidden][name=checkin-check-more-users]").val(0);
$(".checkin-and-add-more-users").attr('disabled', false);
const popup = $(`#race_id_checkin_${form_data.match}`);
//getGuestCheckinForm(form_data.match, popup);
noty({text: '', type: "success"});
}else{
if(result.number_of_checkings && result.number_of_checkings > 1) {
window.location.href = `https://prijavim.se/payments/proforma/all/${result.match_id}`;
}else{
window.location.href = `https://prijavim.se/payments/payments_type/${result.match_id}/${result.checking_id}`;
}
}
}
});
}
function checkinRegisterUser(match, parameters, parameter_type, redirect, club){
var redirect = redirect || true;
//duatlon type
if($("#duatlon_type").length > 0){
var duatlon_type = $("#duatlon_type").val();
}else{
var duatlon_type = null;
}
if($("#stafeta_id").length > 0){
var stafeta_id = $("#stafeta_id").val();
}else{
var stafeta_id = null;
}
let donation = 0;
let is_donation = 0;
if(getDonation()) {
donation = getDonation().value;
is_donation = 1;
}
var form_data = {
match,
club: $("#check_club").val(),
club_other: $("#check_club_other").val(),
category: $("#check_category").val(),
licence: $("#check_licence").val(),
licence2: $("#check_licence2").val(),
licence_valid: $("#licence_valid").val(),
parent: $("#mainUser").val(),
donation,
is_donation,
parameters: parameters,
param_type: parameter_type,
duatlon_t: duatlon_type,
stafeta: parseInt(stafeta_id),
payment_item_id: $("input[name=payment_item_id]").val(),
discount_parameter: $("input[type=hidden][name=discount_parameter]").val(),
ajax: '1'
};
var admin_id = $('#checked_by').val();
if(typeof admin_id == 'undefined'){
console.log('bll');
}else{
form_data.admin_id = admin_id;
}
var txt_p = Array();
$('.textual_parameter').each(function() {
var txt_value = $(this).val();
var txt_parent = $(this).attr('id');
var txt_parameter = txt_value+"|"+txt_parent;
txt_p.push(txt_parameter);
});
form_data.txt_parameter = txt_p;
form_data.register_user = getRegisterUserFormData();
var redirect_to = '';
console.log("🚀 ~ file: calendar_addon.php:1680 ~ checkinRegisterUser ~ form_data:", form_data)
child_id = null;
$.ajax({
url: base_url + 'ajax/storeRegisterUserChecking',
type: 'POST',
async: false,
data: form_data,
dataType: "text",
success: function (data) {
const result = JSON.parse(data)
if(result.status == false) noty({text: result.message, type: "error"});
else if (result.status == true) {
child_id = result.child_id;
}
}
});
return child_id;
}
$(document).on('click', '.btn-buy-camp', (e) => {
e.preventDefault();
const match_id = $(e.target).data('match_id');
console.log("🚀 ~ file: calendar_addon.php:1525 ~ $ ~ match_id:", match_id)
$.ajax({
url: `${base_url}ajax/getBuyCampForm/${match_id}`,
type: 'POST',
dataType: "json",
success: (response) => {
if(response.status) {
$("#buy-camp-dialog").dialog({
modal: true,
width: 401,
resizable: false,
draggable: false,
close: function(event, ui) {
$('#buy-camp-dialog').html('');
}
});
$('#buy-camp-dialog').html(response.html);
return;
}
noty({text: response.message, type: "error"});
}
});
});
const validateCheckin = () => {
if(validateRequiredCheckbox('input[type=checkbox][name=accept_general_terms]') && CheckInParameterCheck() && checkDonation() && guestUserCheckinFormValid() && vallidateCampParam() && validateBuyDailyLicence()){
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(false);
$('.enable').removeAttr('id');
$('.enable').attr('id','checkin');
return
}
changeCheckinAndAddMoreGuestUsersBtnDisabledOption(true);
$('.enable').removeAttr('id');
$('.enable').attr('id','disabled-checkings');
}
$(document).ready(function() {
$( "#guest_user_gender" ).live('change',function() {
var parameter_pop_ups = $('.popup-line-param');
var parameters = $('.parameter');
var selected_gender = $(this).val();
$('.popup-line-param').each(function () {
var gender = $(this).data('gender');
var child = $(this).find('.parameter').first();
if (gender != selected_gender && gender != null && gender != 'unisex') {
$(this).addClass("disable_guest_params");
child.attr('disabled', 'true');
}
else {
$(this).removeClass("disable_guest_params");
child.removeAttr('disabled');
}
});
});
});