let getCheckingsInfoInterval = false; const fitIframeHeight = (height = false) => { const iframeContentHolderElement = document.querySelector('.iframe-content-holder'); if(iframeContentHolderElement) { let contentHeight = iframeContentHolderElement.clientHeight; if(height) { contentHeight = height; } parent.postMessage({source: 'prijavimse-checkin-frame', contentHeight},'*'); } } const showFirstStep = () => { const checkingStartStepsElement = document.querySelector('.checkin-start-steps') if(checkingStartStepsElement && !checkingStartStepsElement.classList.contains('d-none-m')) { checkingStartStepsElement.classList.add('d-none-m') } const checkingStepsHolder = document.querySelector('.checking-steps-holder') if(checkingStepsHolder && checkingStepsHolder.classList.contains('d-none-m')) { checkingStepsHolder.classList.remove('d-none-m') } const checkinForm = document.querySelector('.step-link>a[data-contend_holder_id="checkin-form"]'); if(checkinForm) { checkinForm.removeAttribute('disabled'); checkinForm.click() } } const showFourthStep = () => { const checkingStartStepsElement = document.querySelector('.checkin-start-steps') if(checkingStartStepsElement && !checkingStartStepsElement.classList.contains('d-none-m')) { checkingStartStepsElement.classList.add('d-none-m') } const checkingStepsHolder = document.querySelector('.checking-steps-holder') if(checkingStepsHolder && checkingStepsHolder.classList.contains('d-none-m')) { checkingStepsHolder.classList.remove('d-none-m') } const paymentTypeStep = document.querySelector('.step-link>a[data-contend_holder_id="payment-type-step"]'); if(paymentTypeStep) { paymentTypeStep.removeAttribute('disabled'); paymentTypeStep.click() } } const showThirdStep = () => { const checkingStartStepsElement = document.querySelector('.checkin-start-steps') if(checkingStartStepsElement && !checkingStartStepsElement.classList.contains('d-none-m')) { checkingStartStepsElement.classList.add('d-none-m') } const checkingStepsHolder = document.querySelector('.checking-steps-holder') if(checkingStepsHolder && checkingStepsHolder.classList.contains('d-none-m')) { checkingStepsHolder.classList.remove('d-none-m') } const payerInfoStep = document.querySelector('.step-link>a[data-contend_holder_id="payer-info-step"]'); if(payerInfoStep) { payerInfoStep.removeAttribute('disabled'); payerInfoStep.click() } } const showSecondStep = () => { const checkingStartStepsElement = document.querySelector('.checkin-start-steps') if(checkingStartStepsElement && !checkingStartStepsElement.classList.contains('d-none-m')) { checkingStartStepsElement.classList.add('d-none-m') } const checkingStepsHolder = document.querySelector('.checking-steps-holder') if(checkingStepsHolder && checkingStepsHolder.classList.contains('d-none-m')) { checkingStepsHolder.classList.remove('d-none-m') } const payOrCheckinMore = document.querySelector('.step-link>a[data-contend_holder_id="pay-or-checkin-more"]'); if(payOrCheckinMore) { payOrCheckinMore.removeAttribute('disabled'); payOrCheckinMore.click() } } const showLastStep = () => { const checkingStartStepsElement = document.querySelector('.checkin-start-steps') if(checkingStartStepsElement && !checkingStartStepsElement.classList.contains('d-none-m')) { checkingStartStepsElement.classList.add('d-none-m') } const checkingStepsHolder = document.querySelector('.checking-steps-holder') if(checkingStepsHolder && checkingStepsHolder.classList.contains('d-none-m')) { checkingStepsHolder.classList.remove('d-none-m') } const finalStep = document.querySelector('.step-link>a[data-contend_holder_id="final-step"]'); if(finalStep) { finalStep.removeAttribute('disabled'); finalStep.click() } } const disableAllOptions = () => { document.querySelectorAll('.step-link>a').forEach((element) => element.setAttribute('disabled', 'disabled')) } const showLoader = () => { $('#loader').fadeIn(); } // Hide loader const hideLoader = () => { $('#loader').fadeOut(); } const getMatchId = () => { if($("#match_id")) { return $("#match_id").val() } return -1; } const getUserCheckinForm = (loggedUser, match_id, content_holder_id) => { showLoader(); console.log("🚀 ~ getUserCheckinForm ~ loggedUser:", loggedUser) if(loggedUser.childs.length > 0) { $.post(`${base_url}ajax/get_popup/${getMatchId()}${getIframeQueryParameter()}`, {}, function(data) { $(`#${content_holder_id}`).html(data); $(".checkin-start-steps").fadeOut('slow', () => { $('.checking-steps-holder').fadeIn('slow') }) },'html'); hideLoader(); return; } if(loggedUser.checked) { hideLoader(); noty({text: "Na tekmo ste že prijavljeni", type: "error"}); $(".checkin-start-steps").fadeOut('slow', () => { $('.checking-steps-holder').fadeIn('slow') }) return; } $.get(`${base_url}ajax/userCheckinForm/main/${match_id}/${loggedUser.user_id}${getIframeQueryParameter()}`, function (data) { $(`#${content_holder_id}`).html(data); $(".checkin-start-steps").fadeOut('slow', () => { $('.checking-steps-holder').fadeIn('slow') }) showFirstStep() hideLoader(); }); } const getLoggedUser = () => { let loginData = sessionStorage.getItem("login_data"); if(!loginData) { return false; } return JSON.parse(loginData); } function isValidEmailAddress(emailAddress) { var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i); return pattern.test(emailAddress); }; const doLogin = (form_data, type, login_box, match_id) => { form_data.match_id = getMatchId(); showLoader(); $.ajax({ url: `${base_url}${type}${getIframeQueryParameter()}`, type: 'POST', async: false, dataType: 'json', data: form_data, success: (response) => { if(!response.status) { hideLoader(); noty({text: response.message, type: "error"}); return; } if(response.status) { hideLoader(); noty({text: response.message, type: "success"}); login_box.fadeOut('slow', () => { sessionStorage.setItem("login_data", JSON.stringify(response.data.login_data)); getUserCheckinForm(getLoggedUser(), getMatchId(), "checkin-form"); $("#login-popupbox").dialog("close"); }); return; } hideLoader(); return; } }); } const getIframeQueryParameter = () => { let parameters = []; let loginData = sessionStorage.getItem("login_data"); if(loginData) { parameters = [...parameters, `xmpl=${JSON.parse(loginData).hash}`]; } let lang = sessionStorage.getItem("lang"); if(!lang) { parameters = [...parameters, 'lang=sl']; } if(lang) { parameters = [...parameters, `lang=${lang}`]; } const params = new URLSearchParams(); // Loop through the array and append each item to the parameters parameters.forEach(param => { params.append(param.split('=')[0], param.split('=')[1]); }); return `?${params.toString()}`; } const getGuestCheckinForm = (match_id, content_holder_id) => { showLoader() $.ajax({ url: `${base_url}ajax/getGuestUserCheckinForm/main/${match_id}/-1${getIframeQueryParameter()}`, type: 'GET', async: true, success: (data) => { hideLoader() $(`#${content_holder_id}`).html(data) showFirstStep() // 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', () => { validateGuestUserFormElement(this); }); }); } fitIframeHeight(); } }); } const getCheckingsInfo = () => { let loggedUser = getLoggedUser() if(loggedUser) { fetch(`${base_url}iframe_calendar/get_checkings_info/${getMatchId()}${getIframeQueryParameter()}`, { method: 'GET' }) .then((response) => response.json()) .then((result) => { if(result.status) { if(!getCheckingsInfoInterval) { if(result.expired) { disableAllOptions() noty({text: `Your session expired`,type: "error"}); sessionStorage.removeItem("login_data"); window.location.reload() return; } if(result.data) { let loggedUser = getLoggedUser() if(loggedUser) { loggedUser.checkings_count = result.data.checkings_count; sessionStorage.setItem("login_data", JSON.stringify(loggedUser)); //Ukoliko je korisnik ulogovan i ukoliko ima 0 prijava tada: //Ukoliko je gost dohvatiti i prikazati guest formu u suprotnom formu za prijavu obicnog korisnika if(result.data.checkings_count == 0) { if(!loggedUser.is_guest) { getUserCheckinForm(getLoggedUser(), getMatchId(), "checkin-form"); }else{ getGuestCheckinForm(getMatchId(), 'checkin-form') } } } if(result.data.checkings) { $("#top-holder").html(result.data.checkings); } if(result.data.payer_info_step) { $("#payer-info-step").html(result.data.payer_info_step); if(result.data.checkings_count && result.data.checkings_count > 0) { showSecondStep() } } console.log("🚀 ~ .then ~ result.data.payment_type_step:", result.data.payment_type_step) if(result.data.payment_type_step) { $("#payment-type-step").html(result.data.payment_type_step); } if(result.data.transaction) { $("#proform").html(result.data.transaction.proform); showLastStep() disableAllOptions() } } } if(result.data && result.data.transaction) { hideLoader() $("#proform").html(result.data.transaction.proform); showLastStep() clearInterval(getCheckingsInfoInterval) disableAllOptions() } fitIframeHeight(); return } noty({text: ``,type: "error"}); }) } } 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); 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) { if(data.c_paid == 1) { showLastStep() return; } 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; }) } }); } //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 = ''; const loggedIn = JSON.parse(sessionStorage.getItem("login_data")); $.ajax({ url: `${base_url}ajax/changeCheckinCalendar${getIframeQueryParameter()}`, type: 'POST', async: false, data: form_data, dataType: "text", success: function (msg) { noty({text: '', type: "success"}); if (type == 'check') { $.get(`/ajax/get_last_user_checking/${form_data.user}${getIframeQueryParameter()}`, function (data) { getCheckingsInfo(); if(data.c_paid == 1) { showLastStep() return; } showSecondStep(); }, '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'); } } }); } 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; } if(element.name == 'camp_param_child_1_3') { 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 savePayerInformations = () => { // #user-payer-info-form - forma običnog korisnika // #club-payer-info-form - forma ukoliko plaća klub // input[type=radio][name=user_club] - radio button na osnovu koga se zna da li se prikupljaju informacije o klubu ili o običnom korisniku let formId = false; let payer_type = 1; document.querySelectorAll("input[type=radio][name=user_club]").forEach((payerRadioElement) => { if(payerRadioElement.checked) { if(payerRadioElement.value == 1) { formId = 'user-payer-info-form'; } if(payerRadioElement.value == 2) { formId = 'club-payer-info-form'; payer_type = 2; } } }); if(!formId) { console.log("Niste izabrali ko placa"); return } const formData = new FormData(document.querySelector(`#${formId}`)) formData.append('payer_type', payer_type) fetch(`${base_url}iframe_calendar/savePayerInformations${getIframeQueryParameter()}`, { method: 'POST', body: formData }) .then((response) => response.json()) .then((result) => { if(result.status) { showFourthStep() return; } noty({text: ``,type: "error"}); }) } 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; } return formValid; } const pay = (actionRoute) => { fetch(actionRoute, { method: 'GET', }) .then((response) => response.json()) .then((result) => { hideLoader() if(result.status) { getCheckingsInfo() return; } noty({text: ``,type: "error"}); }) } $(document).ready(function() { var lastLoginBtnSource = null; $(document).on('click', "#open-login-popupbox", function (e) { e.preventDefault(); const loggedIn = JSON.parse(sessionStorage.getItem("login_data")) const match_id = $(e.currentTarget).data('match_id'); if(loggedIn) { showFirstStep() noty({text: "Korisnik je već ulogovan", type: "error"}); return; } lastLoginBtnSource = this; $("#login-popupbox .register").attr('href', '/register/index/ajax/' + $(this).data('match_id')); $("#login-popupbox").dialog("open"); fitIframeHeight(700) }); $(".checkout").live("click", function(e) { e.preventDefault(); match = getMatchId(); user_id = $(".personUncheck"+match).val(); $("#checkoutConfirm").dialog({ width: '90vw' }); $('.close').on('click',function(){ $('#checkoutConfirm').dialog('close'); }); $('.checkout-me').live('click',function(){ changeCheckin(match, user_id, 0, "uncheck"); }); }); $('#submit-login').live('click', function (event) { event.preventDefault(); if (!isValidEmailAddress($('#form_login_username').val())) { //$('#submit-login').prop("disabled", true); // Element(s) are now enabled. $('#error-email-login').html('E-mail naslov ni pravilnega formata'); $('#error-email-login').show(); return false; } const match_id = $('.session_match').val(); var login_box = $('#login-popupbox'); var navigation = $("#main-nav"); var form_data = { username: $('#form_login_username').val(), password: $('#form_login_password').val(), ajax: '1' }; var type = $(event.target).hasClass("fb") ? 'login/fb' : 'iframe_calendar/doLogin'; const loggedIn = sessionStorage.getItem("login_data"); if(loggedIn) { noty({text: "Korisnik je već ulogovan", type: "error"}); } if(!loggedIn) { doLogin(form_data, type, login_box, match_id) } }); $("#login-popupbox").dialog({ modal: true, width: 301, autoOpen: false, resizable: false, draggable: false, close: function () { $("#login-popupbox .register").attr('href', '/register'); } }); $(document).on('click', '#checkin-like-quest', (e) => { var login_box = $('#login-popupbox'); login_box.fadeOut('slow', () => { $("#login-popupbox").dialog("close"); }); $(".checkin-start-steps").fadeOut('slow', () => { getGuestCheckinForm(getMatchId(), 'checkin-form') }) }); $(document).on('click', '.payment-item', 'click', (e) => { e.preventDefault(); const actionRoute = e.currentTarget.href; if(actionRoute.includes('bank/')) { pay(actionRoute) showLoader() return; } if(actionRoute.includes('bankart/preauth')) { document.getElementById("payment_form").submit(); }else{ window.open(actionRoute, '_blank', 'width=600,height=400'); } showLoader() getCheckingsInfoInterval = setInterval(getCheckingsInfo, 2500) }) $(document).on('click', '.open-payments', 'click', (e) => { e.preventDefault(); showThirdStep() }) $(document).on('click', '.submit-payer-info-step', 'click', (e) => { e.preventDefault(); savePayerInformations() }) // // $('.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'); // // }); // $(document).on('change', '.change-payer-type', (e) => { if (e.currentTarget.value == 1) { $('#club-payer-info-form').hide(); $('#user-payer-info-form').show(); } else if (e.currentTarget.value == 2) { $('#user-payer-info-form').hide(); $('#club-payer-info-form').show(); } }); $(document).on('submit', '.confirm_user_payer_data', function(e) { e.preventDefault(); var form = $('.user_payer_data_form').serialize(); if (validate_front(form, '.user_payer_data_form') === false) { //$.post(`${base_url}ajax/set_payer_data/`, form, function(data) { // console.log(data); // $('.payments_steps li a').each(function(index, value) { // console.log(this); // $(this).removeAttr('class'); // }); // $('#four').attr('class', 'active'); // $('.second_step').hide('slow'); // $('.final_step').show('slow'); //}); } }); //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')) { $(e.target).attr('disabled', true); checkinGuestUser(match, parameters, textual_parameter, true); return; } if(!validateTextualParameters()) { return false; } const isCampParamExists = campParamExists(); 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) { e.preventDefault(); $("input[type=hidden][name=checkin-check-more-users]").val(1); 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 $(e.target).attr('disabled', false); checkinGuestUser(match, parameters, textual_parameter, true); }); $(".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 + getIframeQueryParameter()); }else{ $('#showcalpopup'+match).attr('href', 'https://prijavim.se/ajax/userCheckinForm/main/'+match+'/'+valueSelected + getIframeQueryParameter()); } }); $(document).on('click', '#btn-checkin-more-users', (e) => { e.preventDefault() const match_id = e.currentTarget.dataset.match_id; const loggedUser = getLoggedUser(); if(loggedUser) { if(!loggedUser.is_guest) { $.post(`${base_url}ajax/get_popup/${match_id}${getIframeQueryParameter()}`, {match_id, stop: false}, function(data) { const popup = createCheckinPopup(match_id) popup.html(data); popup.dialog("open"); },'html'); return; } } getGuestCheckinForm(getMatchId(), 'checkin-form'); }) $( ".checkinButton" ).live("click", function(e) { showLoader() e.preventDefault(); $(".checkinPopup").dialog('destroy').remove(); var match_id = $(this).attr('data-match_id'); var stop = $(this).attr('data-stop'); $('.display-uidialog').empty(); if (!$( this ).hasClass("direct")) { $('.display-uidialog').html(''); } if($( "#race_id_checkin_"+match_id )) { $('.display-uidialog').html(''); } var popup = $( "#race_id_checkin_"+match_id ); if(popup) { popup.dialog({ autoOpen: false, modal: true, width: dWidth, autoOpen: false, resizable: false, draggable: false, }); $.get( `${$(this).attr('href')}${getIframeQueryParameter()}`, function( data ) { hideLoader() if(data.includes('competitor_global_limit_error')) { const error = JSON.parse(data); $('.checkin-dialog').dialog('destroy'); noty({text: error.message, type: "error"}); return; } $('.checkin-dialog').dialog('destroy'); $(`#checkin-form`).html(data); showFirstStep() }); } }); $("#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; } const popup = $('.checkin-dialog'); if(popup) { popup.dialog({ autoOpen: false, modal: true, width: dWidth, autoOpen: false, resizable: false, draggable: false, }); return popup; } return false; } 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_iframe_checkin: true, 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 = ''; $.ajax({ url: `${base_url}ajax/storeGuestUserChecking${getIframeQueryParameter()}`, type: 'POST', async: false, data: form_data, success: function (data) { const result = JSON.parse(data) if(result.status == false) { noty({text: result.message, type: "error"}); return; } noty({text: '', type: "success"}); if(result.login_data) { sessionStorage.setItem("login_data", JSON.stringify(result.login_data)); } getCheckingsInfo(); // 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]"); if(isCheckinAndAddMoreGuestUsersElement && (isCheckinAndAddMoreGuestUsersElement.val() == 1)) { getGuestCheckinForm(form_data.match, 'checkin-form') }else{ showSecondStep() } } }); } $(document).on('click', '.btn-buy-camp', (e) => { e.preventDefault(); const match_id = $(e.target).data('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'); }