var coaches = []; var coach = []; var postcode = ""; var land = ""; var searchstring = ""; $( document ).ready(function() { postcode = $("#postcode").val(); land = $("#land").val(); searchstring = $("#searchstring").val(); concept = $("#type").val(); //console.log(postcode, land, searchstring); ajaxCall(); $(".coachSelector").on("click", function(){ $(".coachesOverviewField").toggleClass("open"); }); $("#postcode").on("change keyup", function(){ postcode = $("#postcode").val(); land = $("#land").val(); searchstring = encodeURIComponent($("#searchstring").val()); ajaxCall(); }); $("#land").on("select2:select", function(){ postcode = $("#postcode").val(); land = $("#land").val(); searchstring = encodeURIComponent($("#searchstring").val()); ajaxCall(); }); $("#searchstring").on("change keyup", function(){ postcode = $("#postcode").val(); land = $("#land").val(); searchstring = encodeURIComponent($("#searchstring").val()); //console.log(postcode, land, searchstring); ajaxCall(); }); $(document).on("change", ".coachesOverviewField input", function(){ setCoachNameInField(); }); $(document).on("click", ".coachesOverviewField .coach .buttons .openLink", function(){ openCoachOverlay($(this).data("id")); }); }); function ajaxCall(){ coaches = []; locations = []; var success = false; $.ajax({ url: 'https://www.myfittergy.nl/JSON/getCoachv2myFittergy.html?postcode=' + postcode + '&land=' + land + '&concept=' + concept + '&search_naam=' + searchstring, contentType: "application/json", dataType: 'json', success: function (data) { if(data.results.length >= 1){ $(".coachesOverviewField .noResults").hide(); coaches.push(data.results); setCoachesHTML(); if($(".coachesOverviewField").data("coach")){ if($(".coachesOverviewField input[value='" + $(".coachesOverviewField").data("coach") + "']")){ $(".coachesOverviewField input[value='" + $(".coachesOverviewField").data("coach") + "']").prop("checked", true); setCoachNameInField(); } } } else { $(".coachSelector input").val(""); $(".coachesOverviewField .coachesOverviewFieldInner").html(""); $(".coachesOverviewField .noResults").show(); } }, error: function () { $(".coachSelector input").val(""); $(".coachesOverviewField .coachesOverviewFieldInner").html(""); $(".coachesOverviewField .noResults").show(); } }); //console.log('https://www.myfittergy.nl/JSON/getCoachv2myFittergy.html?postcode=' + postcode + '&land=' + land + '&concept=' + concept + '&search_naam=' + searchstring); } function setCoachesHTML(){ var html = ""; $(".coachesOverviewField .coachesOverviewFieldInner").html(""); $(coaches[0]).each(function(i, el){ html += ""; }); $(".coachesOverviewField .coachesOverviewFieldInner").html(html); setCoachNameInField(); } function setCoachNameInField(){ $(".coachSelector #coach, .coachSelector #coach_id").val(""); var activeCoach = $(".coachesOverviewField input:checked").closest(".coach"); var id = $(activeCoach).find("input").val(); var name = $(activeCoach).find(".coachName").text(); $(".coachSelector #coach").val(name); $(".coachSelector #coach_id").val(id); } function openCoachOverlay(id){ var html = ""; coach = []; $.ajax({ url: 'https://www.myfittergy.nl/JSON/getCoachInfo.html?coachID=' + id + '&language=nl', contentType: "application/json", dataType: 'json', success: function (data) { //console.log('nl'); $("html, body").addClass("overflow"); coach.push(data); $(".coachOverlay .overlayInnerContent").html(""); $(".coachOverlay").addClass("active"); html += "
"; html += "
"; html += "
"; if(coach[0].image){ html += "
"; } html += "
"; html += "
"; html += "
" + coach[0].name + "
"; html += "

" + coach[0].hoofdlocatie_term + "

"; html += "

" + coach[0].hoofdlocatie + "

"; var locations = coach[0].locaties.split(","); //console.log(locations); if(locations.length > 1){ html += "

" + coach[0].andere_locaties_term + "

"; $(locations).each(function(i, el){ if(i > 0){ html += "

" + el + "

"; } }); } html += "

" + coach[0].contactgegevens_term + "

"; if(coach[0].telefoon_presenteer_jezelf){ html += "

" + coach[0].telefoon_presenteer_jezelf + "

"; } if(coach[0].email_presenteer_jezelf){ html += "

" + coach[0].email_presenteer_jezelf + "

"; } if(coach[0].website_to_show_url){ html += "

" + coach[0].website_to_show_url + "

"; } if(coach[0].facebook || coach[0].linkedin|| coach[0].instagram){ html += "
"; if(coach[0].facebook){ html += ""; } if(coach[0].linkedin){ html += ""; } if(coach[0].instagram){ html += ""; } html += "
"; } html += "
"; html += "
"; if(coach[0].introductie){ html += "
"; html += "

" + coach[0].introductie_term + "

"; html += "

" + coach[0].introductie + "

"; html += "
"; } if(coach[0].eigen_ervaring_kuur){ html += "
"; html += "

" + coach[0].eigen_ervaring_kuur_term + "

"; html += "

" + coach[0].eigen_ervaring_kuur + "

"; html += "
"; } if(coach[0].opleidingen){ html += "
"; html += "

" + coach[0].opleidingen_term + "

"; html += "

" + coach[0].opleidingen + "

"; html += "
"; } if(coach[0].ervaring){ html += "
"; html += "

" + coach[0].ervaring_term + "

"; html += "

" + coach[0].ervaring + "

"; html += "
"; } if(coach[0].doelgroepen){ html += "
"; html += "

" + coach[0].doelgroepen_term + "

"; html += "

" + coach[0].doelgroepen + "

"; html += "
"; } if(coach[0].overigen){ html += "
"; html += "

" + coach[0].overigen_term + "

"; html += "

" + coach[0].overigen + "

"; html += "
"; } html += "
"; html += "
"; html += "
"; html += "
" + coach[0].starten_term + "
"; html += ""; $(".coachOverlay .overlayInnerContent").html(html); } }); }