var tripObjects = jQuery.parseJSON('[]'); var tripObjectsSelect = jQuery.parseJSON('[]'); var priceObjects = jQuery.parseJSON('[]'); var journeyObjects = jQuery.parseJSON('[]'); var lessonObjects = jQuery.parseJSON('[]'); // Purpose: Display valid options // How it's done: Gather information from functions above // Status: IN USE function displayFormOptions() { var tripSelect = jQuery('#tripSelect').val(); var priceSelect = jQuery('#priceSelect').val(); var journeySelect = jQuery('#journeySelect').val(); var lessonSelect = jQuery('#lessonSelect').val(); // Hide all select elements, when no trip is selected // Reset selects (just to make sure) if(typeof tripSelect === 'undefined' | tripSelect === null || tripSelect === "") { jQuery('#priceSelectSection').addClass("d-none"); jQuery('#journeySelectSection').addClass("d-none"); jQuery('#lessonSelectSection').addClass("d-none"); jQuery('#tripBookingProgressbar').html("").addClass('d-none'); jQuery('#priceSelect').prop('selectedIndex', 0); jQuery('#journeySelect').prop('selectedIndex', 0); jQuery('#lessonSelect').prop('selectedIndex', 0); displayTripSelect(); return false; } else { jQuery('#tripSelect').removeClass("is-invalid").addClass("is-valid"); jQuery('#priceSelectHint').html('').addClass("d-none"); jQuery('#priceSelectSection').removeClass("d-none"); jQuery('#journeySelectSection').removeClass("d-none"); displayTripSelect(tripSelect); displayPriceSelect(tripSelect, priceSelect, lessonSelect); displayJourneySelect(tripSelect, journeySelect); //displayTripProgressBar(tripSelect); } } // Purpose: Fill select with trip data // How it's done: Rebuild a new JSON array which only contains the valid elements regarding age // Dependancies: calculateAge // Status: IN USE at displayFormOptions function displayTripSelect(tripSelect) { if(jQuery('#birthdate').val().length<10) { jQuery('#birthdayDayHint').removeClass('d-none'); jQuery('#tripSelectSection').addClass('d-none'); } var tripCount = 0; var selectElement = jQuery("#tripSelect"); var tripLength = Object.keys(tripObjectsSelect).length; jQuery("#tripSelect").empty(); var selectElement = jQuery("#tripSelect"); selectElement.append(jQuery(''); tripCount++; } }); // In the rare case, that no trips can be shown we hide the select section // Let's make sure to show a hint if the registrant is too young if(tripCount==0) { if(jQuery('#birthdate').val().length==10) { jQuery('#birthdayDayHint').addClass('d-none'); jQuery('#noTrips').remove(); jQuery('#tripSelectSection').removeClass('d-none').after(''); } jQuery('#priceSelectSection').addClass('d-none'); jQuery('#journeySelectSection').addClass('d-none'); jQuery('#lessonSelectSection').addClass('d-none'); } else { jQuery('#tripSelect').addClass('is-invalid'); jQuery('#birthdayDayHint').addClass('d-none'); jQuery('#noTrips').remove(); jQuery('#tripSelectSection').removeClass('d-none'); jQuery('#noTrips').remove(); } if(typeof tripSelect === 'undefined' | tripSelect === null || tripSelect === "") { } else { jQuery('#tripSelect'+tripSelect).prop("selected", true); } } // Purpose: Determine the priceOptions in regard of membership and age // How it's done: Rebuild a new JSON array which only contains the valid elements // Dependancies: calculateAge() function // Status: IN USE at displayPriceSelect function determinePriceOptions(tripSelect) { if(typeof tripSelect === 'undefined' | tripSelect === null || tripSelect === "") return false; var specificDate = tripObjects[tripSelect]["main_start"]; var age = calculateAge(specificDate); //var mitglied = jQuery("input[name='mitglied']:checked").val(); var mitglied = jQuery('#mitglied').val(); var validPriceObjects = {}; jQuery.each(priceObjects[tripSelect], function(key, value) { var age_min = priceObjects[tripSelect][key]['option_age_min']; var age_max = priceObjects[tripSelect][key]['option_age_max']; var option_kurs = priceObjects[tripSelect][key]['option_kurs']; var option_level = priceObjects[tripSelect][key]['option_level']; // Stage 1: Age if(age>=age_min && age<=age_max) { // Stage 2: Level if(mitglied==1 && option_level==2) { validPriceObjects[key] = priceObjects[tripSelect][key]; } else if(mitglied==0 && option_level!=2) { validPriceObjects[key] = priceObjects[tripSelect][key]; } } }); var validPriceObjectsJSON = JSON.stringify(validPriceObjects, null, 2); return validPriceObjectsJSON; } // Purpose: Display price options // How it's done: Gather information and build select options // Dependancy: determinePriceOptions // Status: IN USE at displayFormOptions function displayPriceSelect(tripSelect, priceSelect, lessonSelect) { var priceOptions = jQuery.parseJSON(determinePriceOptions(tripSelect)); var priceLength = Object.keys(priceOptions).length; // Name & prepare element var selectElement = jQuery("#priceSelect"); jQuery("#priceSelect").empty(); // If element has more than one option, then add a select option with no value if(priceLength>1) { selectElement.append(jQuery('