const getCampReservations = (match_id, data) => { $.ajax({ url: `${base_url}ajax/getCampReservations/${match_id}`, type: 'POST', async: true, data: data, dataType: 'json', success: (result) => { if(result.status) { $(".match-data").fadeOut(() => { $(".match-data").empty().html(result.html).fadeIn('slow'); }) return result.html; } } }); } $(document).ready(function(){ //result description $('#display-text').live('click',function(){ var id = $(this).attr('class'); //alert(id); //if opened hide them $( ".desc_"+id ).toggle(); }); //if submited $('#save_result_desc').live('click',function(){ var match = $(this).attr('match_id'); var match_desc = $('textarea#results_desc_'+match).val(); //alert(match_desc); $.ajax({ url : base_url+'/ajax/saveResultDesc/', data : { match_id: match, desc:match_desc}, dataType: 'json', type: "POST", success: function(response) { // on success.. $('.response-'+match).html(response.msg); $('.response-'+match).fadeIn('slow'); $(".response-"+match).delay(500).fadeOut('slow'); //$('#etap_edit_imput').replaceWith(""+new_str+""); } }); }); /// When user selects match from dropdown, we need to change whole form, send request for all the data and show it. $("#match").live('change', function() { if($(this).find(':selected').data('camp_reservations') == 1) { $('.dialog').dialog("destroy"); $('.dialog').remove(); const match_id = $(this).val(); let alter_organizer = null; if ($("#alter_organizer_id").length) { alter_organizer = $("#alter_organizer_id").val(); } else { alter_organizer = null; } const data = { ajax: '1', alter_organizer_id: alter_organizer }; getCampReservations(match_id, data); return; } $('.dialog').dialog("destroy"); $('.dialog').remove(); var matchd = $(this).val(); var alter_organizer = null; if ($("#alter_organizer_id").length) { alter_organizer = $("#alter_organizer_id").val(); } else { alter_organizer = null; } var form_data = { match: matchd, ajax: '1', alter_organizer_id: alter_organizer }; if (matchd > 0) { $.ajax({ //url: base_url + 'ajax/getCheckingsOrganizer', url: base_url + 'ajax/getCheckingsOrganizerOptimizacija', type: 'POST', async: true, data: form_data, success: function(msg) { $(".match-data").fadeOut(function() { if (CKEDITOR.instances.editor1) CKEDITOR.instances.editor1.destroy(); $(this).empty().html(msg).fadeIn('slow'); /// Create dialog to show sent notifications! $('.dialog').dialog({ autoOpen: false, height: 'auto', resizable: false, width: 650, modal: true, closeText: 'Zapri' }); CKEDITOR.replace('editor1', { toolbar: 'Basic' }); countCheckins(); $(document).on('click', '.btn-change-checking', (e) => { e.preventDefault(); const element = $(e.target); const c_active = element.data('c_active'); const c_paid = element.data('c_paid'); const bankart_conditional = element.data('bankart_conditional'); if ((c_active == 1) && (c_paid == 1 || (c_paid == 4 && bankart_conditional == 1))) { noty({text: 'Odjava ni mogoča, ker je prijava plačana!', type: "error"}); return; } const hasCheckinClass = element.hasClass("checkinLeft"); const user_id = element.attr("user"); const checking_id = element.data('checking_id'); const holder = $("#left" + user_id); const race = $("#matchId").val(); showChangeCheckingDialog( element, hasCheckinClass, user_id, checking_id, holder, race, ); }); const showChangeCheckingDialog = ( element, hasCheckinClass, user_id, checking_id, holder, race ) => { // Ovde dodati jos jedno dugme da prikaze ispravno da li da sakrije ili da prikaze korisnika const dialogText = "Če kliknete dejanski gumb za odjavo, boste izbrisali prijavo uporabnika"; const fakeButtonText = hasCheckinClass ? "Prijava" : "Odjava"; $("#change-checking-dialog").html(dialogText) let buttons = [] const first_name = element.data('first_name'); const last_name = element.data('last_name'); if(element.data('is_relay_race') == 1) { buttons = [ { text: "Potrdi odjavo", click: () => { changeRelayMatchCheckin({ajax:1, checking_id}); element.closest('tr').remove(); countCheckins(); $("#change-checking-dialog").dialog("close"); } } ] }else{ buttons = [{ text: "Potrdi odjavo", click: () => { changeCheckin(race, user_id, "real-uncheck"); element.closest('tr').remove(); countCheckins(); $("#change-checking-dialog").dialog("close"); } }, { text: fakeButtonText, click: () => { if (hasCheckinClass) { changeCheckin(race, user_id, "check") element.removeClass("checkinLeft"); element.html("Odjava x"); element.addClass("checkoutLeft"); holder.addClass("checkedRacer"); } else { changeCheckin(race, user_id, "uncheck") element.html("Prijava x"); element.removeClass("checkoutLeft"); element.addClass("checkinLeft"); holder.removeClass("checkedRacer"); } countCheckins(); $("#change-checking-dialog").dialog("close"); } } ] } $("#change-checking-dialog").dialog({ resizable: false, height: "auto", width: 400, modal: true, title: `Sprememba aplikacije - ${first_name} ${last_name}`, buttons: buttons }); } }); } }); } }); // logic for importing results var resultupload = $(".import-results").upload({ action: '/import/import_results/'+$("#matchR").val(), onSelect: function() { resultupload.set({action:'/import/import_results/'+$("#matchR").val()}); }, onComplete: function(response_data) { alert(response_data); console.log(response_data); var match_id = $("#matchR").val(); $.ajax({ url: `${base_url}/organizer/check_table_access_privileges/`, type: 'GET', success: function(response) { response = JSON.parse(response); if (response.status == true) { if (confirm("Ali želite preveriti točnost uvoza?")) { window.location.href = `${base_url}organizer/table/${match_id}`; } } }, }); } }); //import-results2 var resultupload2 = $(".import-results2").upload({ action: '/import/import_results/'+$("#matchR").val(), onSelect: function() { resultupload2.set({action:'/import/import_results/'+$("#matchR").val()}); }, onComplete: function(response_data) { alert(response_data); console.log(response_data); } }); //club score upload var simple_score = $(".simple_score").upload({ action: '/import/simple_score_import/'+$("#matchR").val(), onSelect: function() { simple_score.set({action:'/import/simple_score_import/'+$("#matchR").val()}); }, onComplete: function(response_data) { alert(response_data); console.log(response_data); } }); $('#matchR').on('change',function(e){ var match = $("#matchR").val(); $.ajax({ url : 'https://prijavim.se/ajax/checkMatchetap/', data : { match_id: match }, dataType: 'json', type: "POST", success: function(response) { // on success.. // Na selektovanoj trci se nalazi info da li je moguć upload rezultata if(response.block_results_import == 1) { $('.import_buttons').hide('slow'); noty({text: "Za dano tekmo ni mogoče naložiti rezultatov.", type: "error"}); return; } if((response.etap.length > 0) && response.block_results_import == 0){ $('.import_buttons').show('slow'); var button_html = ' Uvozi rezultate etapne dirke'; $('#button-etap').html(button_html); $('.import-results').hide(); /*display response in dialog*/ var html = ''; var content_html = '
'; $.each( response.etap, function( key, value ) { console.log(value); if(value.specific_description != null){ var spec_desc = value.specific_description.replace("_", " "); }else{ var spec_desc = ''; } content_html+= '

'+value.etap_name+' - '+spec_desc+'

'; content_html+= '

'+value.etap_start_date+'

'; content_html+= 'Uvozi datoteko z rezultati'; }); content_html+= '
'; html = '
'; $('#show_etap_from').append(html); $('#dialog').append(content_html); $('#button-etap').show(); /*test**/ $('.import-etap-results').on('click',function(e){ var id = $(this).attr('id'); //var action = $('#forma').attr('action'); var action = '/import/import_results/'+match+'/'+id+'/'; $('#forma').get(0).setAttribute('action',action); console.log(action); e.preventDefault(); $('input[type=file][name=file]').trigger('click'); }); $('#etap_results').change(function() { $('#forma').submit(); }); //on click change text to input $('.edit_etap').on('click',function(){ var id = $(this).attr('id'); console.log(id); var str = $(this).text(); $(this).replaceWith(""); //on enter save $('#etap_edit_imput').keydown(function(e) { if(e.which == 13) { var new_str = $('#etap_edit_imput').val(); var etap_id = $(this).attr('class'); //save value when changed $.ajax({ url : 'https://prijavim.se/ajax/changeEtapName/', data : { new_str: new_str, etap_id:etap_id}, type: "POST", success: function(response) { // on success.. console.log(response); $('#etap_edit_imput').replaceWith(""+new_str+""); } }); return false; //end value } }); }); //edit start date of etap $('.edit_date_etap').on('click',function(){ var id = $(this).attr('id'); console.log(id); var str = $(this).text(); $(this).replaceWith(" "); $('#data_edit_imput').on('change',function(){ var new_str = $('#data_edit_imput').val(); var etap_id = $(this).attr('class'); //save value when changed $.ajax({ url : 'https://prijavim.se/ajax/changeEtapDate/', data : { new_str: new_str, etap_id:etap_id}, type: "POST", success: function(response) { // on success.. console.log(response); $('#data_edit_imput').replaceWith(""+new_str+"

Sacuvano

"); } }); return false; }); //on enter save $('#data_edit_imput').keydown(function(e) { console.log(e.which); if(e.which == 13) { var new_str = $('#data_edit_imput').val(); var etap_id = $(this).attr('class'); //save value when changed $.ajax({ url : 'https://prijavim.se/ajax/changeEtapDate/', data : { new_str: new_str, etap_id:etap_id}, type: "POST", success: function(response) { // on success.. console.log(response); $('#data_edit_imput').replaceWith(""+new_str+""); } }); return false; //end value } }); }); }else{ $('#button-etap').hide(); $('.import-results').show(); } } }); return false; }); /*upclick( { element: uploader, action: '/import/import_results/'+$("#matchR").val(), action_params: { match_id: $("#matchR").val() }, oncomplete: function(response_data) { alert(response_data); } });*/ /// Logic for clicking on right side of club checkins! $(".checkerRight").live('click', function(event) { var user_id = $(this).attr("user"); var holder = $("#"+user_id); var race = $("#matchId").val(); if($(this).hasClass("checkinRight")) { var status = changeCheckin(race, user_id, "check") if(status.responseText == "User already checked to this match!!!") { noty({text: 'Uporabnik je že prijavljen!', type: "error"}); } else { $(this).removeClass("checkinRight"); $(this).html("Odjava x"); $(this).addClass("checkoutRight"); holder.clone().appendTo(".leftRacers").hide().fadeIn('slow').addClass('leftRacerAdded checkedRacer').attr('id', "left"+user_id).css("background-color", "white"); countCheckins() } }else { changeCheckin(race, user_id, "uncheck") $(this).html("Prijava x"); $(this).removeClass("checkoutRight"); $(this).addClass("checkinRight"); $("#left"+user_id).fadeOut('slow').remove(); countCheckins() } event.preventDefault(); }) /// Logic for clicking on left side of club checkins! $(document).on('click',".checkerLeft", function(event) { console.log(this); var user_id = $(this).attr("user"); var holder = $("#left"+user_id); var race = $("#matchId").val(); if($(this).hasClass("checkinLeft")) { changeCheckin(race, user_id, "check") $(this).removeClass("checkinLeft"); $(this).html("Odjava x"); $(this).addClass("checkoutLeft"); holder.addClass("checkedRacer"); countCheckins() }else { changeCheckin(race, user_id, "uncheck") $(this).html("Prijava x"); $(this).removeClass("checkoutLeft"); $(this).addClass("checkinLeft"); holder.removeClass("checkedRacer"); countCheckins() } event.preventDefault(); }) /// We count all racers who have "checkedRacer" class and show it in div with fade effect! function countCheckins() { lenght = $(".checkedRacer").length; $("#number-checkins").fadeOut('fast').html(""+lenght+"").fadeIn('fast'); } /// We need to send request to database to add or remove specific user checkin for a specific match! function changeCheckin(match, user, type) { var form_data = { match : match, order : "date", user : user, type : type, ajax : '1' }; return $.ajax({ url: base_url+'ajax/changeCheckin', type: 'POST', async : false, data: form_data, dataType: "text", success: function(msg) { console.log("Prijavim.se Database Interaction!") return msg; } }); } const changeRelayMatchCheckin = (data, type = 'real-checkout') => { return $.ajax({ url: base_url+'ajax/changeRelayMatchChecking', type: 'POST', async : false, data: data, dataType: "text", success: (response) =>{ console.log(response); } }); } /// Search users by term in input and show them in table $("#search-enter").live('click', function(e) { var content = $(".rightRacers"); var term = $("#user-search").val(); var matchd = $("#matchId").val(); var form_data = { search : term, match : matchd, ajax : '1' }; $.ajax({ url: base_url+'ajax/searchUsersOrganizer', type: 'POST', async : false, data: form_data, success: function(data) { content.fadeOut('fast',function() { content.html(data).fadeIn('fast'); }) } }); e.preventDefault() }) /// Whole logic for sending mass mails to users! $("#send-notification").live('click',function() { var holder = $("#mail-notification"); var matchd = $("#matchId").val(); var subject_val = $("#subject").val(); var text_val = CKEDITOR.instances.editor1.getData() var type_val = $("input[name='type-notification']:checked").val(); var form_data = { match : matchd, sub : subject_val, text : text_val, type : 'organizer', ajax : '1' }; $.ajax({ url: base_url+'ajax/sendNotification', type: 'POST', async : false, data: form_data, success: function(status) { if(status == "1") { CKEDITOR.instances.editor1.setData( ' ' ); $("#subject").val(""); noty({text: 'Sporočilo uspešno poslano!', type: "success"}); /// Refresh list of mails in current match! $.ajax({ url: base_url+'ajax/latestMails', type: 'POST', async : false, data: form_data, success: function(html) { $("#mails").html(html); } }); } else { noty({text: 'Prišlo je do napake!', type: "error"}); } } }); }) /// Button opener for dialog of sent mails! $('#show-notification').live('click', function(){ $('.dialog').dialog( "open" ); }) /// Logic for requesting single mail content! $(".single-email").live('click', function(e) { var mail = $(this).attr("mail"); var content = $(".mail-content"); var form_data = { id : mail, ajax : '1' }; $.ajax({ url: base_url+'ajax/getMail', type: 'POST', async : false, data: form_data, success: function(data) { content.fadeOut('slow', function() { content.html(data).fadeIn('slow'); }) } }); e.preventDefault(); }) });