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; $(".custom-required-chb").each((index, elementItem) => { const checkboxHolder = $(elementItem).parent(); const checked = $(elementItem).is(':checked'); checkboxHolder.removeClass('is-invalid'); if(!checked) { checkboxHolder.addClass('is-invalid'); } customRequiredCheckbox &= checked; }); return customRequiredCheckbox; } function CheckInParameterCheck() { var stop_loop = false $('#check_category').removeClass('is-invalid'); $(".parameter").each(function(index, elementItem) { const element = $(elementItem); if(element) { element.removeClass('is-invalid'); } }); $(".parameter:visible").each(function(index, elementItem) { const element = $(elementItem); var answer = $(this).val(); if(answer == 'x'){ if(element) { element.addClass('is-invalid'); } //alert(""); stop_loop = true; } }); 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; } const guestUserCheckinFormValid = () => { if($("#createGuestUserForm")) { return validateCreateGuestUserForm($("#createGuestUserForm")); } 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) element.removeClass('is-invalid'); const validationResult = simpleTextValidation(element); if(!validationResult) { 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') const checked = document.querySelector(`${selector}`).checked; if(!checked) { $(selector).parent().addClass('is-invalid') } return checked; } return true; } const validateBuyDailyLicence = (selector) => { const dailyLicenceElement = document.querySelector(`#buy_daily_licence`); if(dailyLicenceElement) { dailyLicenceElement.classList.remove('is-invalid'); } if(getBuyDailyLicenceValue().length == 0) { if(dailyLicenceElement) { dailyLicenceElement.classList.add('is-invalid'); } 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){ 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 = ''; $.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()) { if(getMainCampParamValue() == -1) { $('#camp_param_main').addClass('is-invalid'); 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'); if((element.value == '') || (element.value < 0)) { element.classList.add('is-invalid'); 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'); 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(!validateCustomRequiredChb()) { formErrors = [...formErrors, 'Custom required checkbox invalid']; formValid &= false; } 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); 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); }else{ changeCheckin(match, user_id, parameters, "check", club,null,true); } // 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(); } }); $(".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 > 460){ var dWidth = 401; }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) { 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, 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"); 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(); }) 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')) $('#checkin-like-quest').css('display', 'none'); }); const createCheckinPopup = (match_id) => { var wWidth = $('body').width(); if(wWidth > 460){ var dWidth = 401; }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, close : function(event, ui) { $(".checkinPopup").dialog('destroy').remove(); } }); return popup; } const getGuestCheckinForm = (match_id, popup) => { $.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); let userNumber = +$('#number_of_checkings').val() + 1; const guestUserFormTitle = number_of_checkings < 1 ? `` : ` ${userNumber}` $('.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"))); }); 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 validateCreateGuestUserForm = (form) => { let result = true; $(form).find(".req").each(function(index, element) { result &= validateGuestUserFormElement(element); }); return result; } const validateGuestUserFormElement = (element) => { if ($.trim($(element).val()) == '' || $.trim($(element).val()) == 'x') { $(element).attr('style', 'border:solid 1px red;'); return false; } const elementName = $(element).attr('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.') return false; } // if(elementName == 'terms') { // console.log("Validacija terms-a: ") // } if ((elementName == 'terms') && !$(element).is(":checked")) { $('.terms-text').attr('style', 'color: red;'); 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').live('change',function(){ showGuestUserCategories(); }) $('#guest_user_gender').live('change',function(){ showGuestUserCategories() }) const showGuestUserCategories = () => { $("#check_category").val('x') const guest_user_gender = $("#guest_user_gender").val().substr(0,1); const guest_user_age = (+(new Date).getFullYear()) - (+$("#guest_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 ((guest_user_age >= categoryMinAge) && (guest_user_age <= categoryMaxAge) && (!categoryGender || categoryGender == 'u' || categoryGender == guest_user_gender)) { $(element).css('display', 'initial'); }else{ $(element).css('display', 'none'); } }); } function checkinGuestUser(match, parameters, parameter_type, redirect){ 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.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"}); } // 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}`; } } } }); } $(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'); }