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 = $('#calendar').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() { }); }); */ } $(document).ready(function() { //on select change $( ".parameter" ).live('change',function() { var selected_value = this.value; if(selected_value != 'x'){ $('.enable').removeAttr('id'); $('.enable').attr('id','checkin'); }else{ $('.enable').removeAttr('id'); $('.enable').attr('id','disabled-checkings'); } console.log(); // }); $('.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! function changeCheckin(matchi, user, parameters, type, club) { 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(), parent: $("#mainUser").val(), type : type, parameters : parameters, ajax : '1' }; $.ajax({ url: base_url+'ajax/changeCheckinCalendar', type: 'POST', async : false, data: form_data, dataType: "text", success: function(msg) { if(type == 'check'){ //$('.checkinPopup').dialog('close'); noty({text: '', type: "success"}); window.setTimeout(function(){location.reload()},0); } if(type == 'uncheck'){ //$('.checkinPopup').dialog('close'); noty({text: '', type: "success"}); window.setTimeout(function(){location.reload()},0); } //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; //}) } }); } $("#checkin").live("click", function(e) { e.preventDefault(); console.log("Prijava"); // var match = $(this).attr("match"); // var club = $(this).attr("club"); // var user_id = $(".personCheck"+match).val(); // var parameters = new Array(); // $(".parameter").each(function() { // var answer = $(this).val(); // var parent = $(this).attr("parent"); // var parameter = answer+"$$"+parent; // parameters.push(parameter); // }) // changeCheckin(match, user_id, parameters, "check", club) // $.fancybox.close(); }); $(".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"); }); $( ".checkinPopup" ).dialog({ modal: true, width: 401, 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: 401, resizable: false, draggable: false }); $('.close').on('click',function(){ $('#checkoutConfirm').dialog('close'); }); $('.checkout-me').live('click',function(){ changeCheckin(match, user_id, 0, "uncheck"); }); } }); $( ".checkinButton" ).on("click", function(e) { e.preventDefault(); var match_id = $( e.target ).data("match_id"); $(".checkinPopup").dialog('destroy').remove() $('.display-uidialog').html(''); //get dialog datas = {}; datas.match_id = match_id; $.post(base_url+"ajax/get_popup/"+match_id, datas, function(data) { $( "#race_id_checkin_"+match_id ).html(data); },'html'); var popup = $( "#race_id_checkin_"+match_id ); var close_pop = $('.checkinPopup '); popup.dialog({ autoOpen: false, modal: true, width: 401, autoOpen: false, resizable: false, draggable: false, }); // if user has childs there is a popup for choosing which player to checkin. if (!$( e.target ).hasClass("load-ajax")) { // show popup popup.dialog( "open" ); } else { // if there is no popup, then user does not have childs. lets show him the checkin form. 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(); })