diff --git a/index.css b/index.css new file mode 100644 index 00000000..61311160 --- /dev/null +++ b/index.css @@ -0,0 +1,68 @@ +body { + font-family: 'Roboto', sans-serif; + font-weight: 100; +} + +button, .button { + margin: 0.5em; + background: linear-gradient(#F0F0F0, #7C7B7B); + color: #FFFFFF; + border-radius: 5px; + font-size: 0.85em; + padding: 0.8em; + cursor: pointer; +} + +.container { + display: grid; + grid-template-columns: 1fr 1fr; +} + +.hidden { + display: none; +} + +.trip-detail h3 { + text-align: center; +} + +.trip-detail-section { + margin-bottom: 0.5em; +} + +.trip-detail-section, .reserve-trip{ + border: .5px solid black; + padding: 0 1em 1em 1em; +} + +.trips, span { + cursor: pointer; + margin-bottom: 1em; +} + +.trips li { + padding: 0.5em; + padding-left: 0; + list-style-type: none; +} + +#trip-form > div { + margin-bottom: 0.5em; +} + +#reserve-trip-button { + margin-top: 1em; +} + +.more { + background-color: lightgrey; +} + +@media screen and (max-width: 630px) { + .container { + display: flex; + flex-direction: column-reverse; + } + + .trips, .trip-detail-section { + } diff --git a/index.html b/index.html new file mode 100644 index 00000000..43d460e2 --- /dev/null +++ b/index.html @@ -0,0 +1,56 @@ + + +
+ + +${message}
Continent: ${data.continent}
`); + let category = $(`Category: ${data.category}
`); + let weeks = $(`Weeks: ${data.weeks}
`); + let cost = $(`Cost: $${data.cost}
`); + + tripDetail.append(name, about, aboutFullText, more, continent, category, weeks, cost); + + reportStatus(`Successfully loaded details for ${response.data.name} trip`) + }) + .catch((error) => { + console.log(error); + reportStatus(`Error: ${error.message}`); + }); +} + +// Form helpers +const FORM_FIELDS = ['name', 'email']; +const inputField = name => $(`#trip-form input[name="${name}"]`); + +const readFormData = () => { + const getInput = name => { + const input = inputField(name).val(); + return input ? input : undefined; + }; + + const formData = {}; + FORM_FIELDS.forEach((field) => { + formData[field] = getInput(field); + }); + + return formData; +}; + +const clearForm = () => { + FORM_FIELDS.forEach((field) => { + inputField(field).val(''); + }); +} + +// Reserve spot on trip +const reserveTrip = (event) => { + event.preventDefault(); + // let id = Number($('#trip-detail-section h4')[0].classList[0]); + let id = $('.trip-detail-section h4').attr("class"); + + const tripData = readFormData(); + + reportStatus('Sending trip reservation data...'); + + axios.post((`${URL}${id}/reservations`), tripData) + .then((response) => { + clearForm(); + reportStatus(`Successfully created trip reservation with ID ${response.data.trip_id}!`); + }) + .catch((error) => { + console.log(error.response); + if (error.response.data && error.response.data.errors) { + reportError( + `Encountered an error: ${error.message}`, + error.response.data.errors + ); + } else { + reportStatus(`Encountered an error: ${error.message}`); + } + }); +} + +$(document).ready(() => { + $('#load').click(loadTrips); + $('#asia').click(asiaTrips); + $('#africa').click(africaTrips); + $('#antartica').click(antarticaTrips); + $('#australasia').click(australasiaTrips); + $('#europe').click(europeTrips); + $('#north-amer').click(nAmericaTrips); + $('#south-amer').click(sAmericaTrips); + + $('#trip-list').on('click', 'li', function(event) { + let id = Number(event.target.id); + $("section").removeClass("hidden"); + getTripDetails(id); + }); + + $('#trip-form').submit(reserveTrip); + + $(".trip-detail-section").on('click', '.more', function(event) { + $(".moreinfo").removeClass("hidden"); + $(".more").addClass("hidden"); + }); + +//Failed attempts at reading input from a drop-down form to select specific continent... + // $('load-by-continent-form').submit(function() { + // console.log($("#load-by-continent-form").val()); + // }); + + // $('#submit').on('click', function() { + // let continent = $( "#load-by-continent" ).val(); + // loadTripsByContinent(continent); + // }); + + // $('#load-by-continent').submit(function() { + // let continent = $( "#load-by-continent" ).val(); + // loadTripsByContinent(continent); + // }); + +//More failed attempts at making a toggle read more/less function + // $('.moreinfo').hide(); + // $('.more').click(function (ev) { + // $(".more-info").removeClass("hidden"); + // console.log(ev); + // let t = ev.target + // $('#info' + $(this).attr('target')).toggle(500, function(){ + // $(t).html($(this).is(':visible')? 'I\'m done reading more' : 'Read more') + // }); + // return false; + // }); + // $(".more").toggle(function(){ + // $(this).text("less..").siblings(".complete").show(); + // }, function(){ + // $(this).text("more..").siblings(".complete").hide(); + // }); +});