Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trek with all functionalities #21

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

<title>TREK</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/foundation/6.2.4/foundation.min.css">
<link href="styles/index.css" media="screen" rel="stylesheet" type="text/css">
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="scripts/index.js"></script>
</head>
<body>
<h1>Find your Dream vacation!</h1>

<button type="button" name="button" class="button" id="trip-load-button">Load all trips!</button>

<section class="row">
<table class="small-6 columns">
<tr class="trips-headers">

</tr>
<tbody class='trips-body'>

</tbody>
</table>


<div class="small-6 columns trip-display">
</div>

<form id="reservation-form" class="small-6 columns">
<label for="name">Name</label>
<input type="text" name="name"></input>
<label for="email">Email</label>
<input type="text" name="email"></input>

<button type="submit" class="button">Reserve this trip!</button>

</form>



</section>







</body>
</html>
84 changes: 84 additions & 0 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

$(document).ready(function() {
var url = "https://trektravel.herokuapp.com/trips";
$('#reservation-form').hide();

var successCallback = function(response) {
console.log("yay trips!");
console.log(response);

$.each(response, function(index, trip){
console.log(trip);
var row = $('<tr></tr>');
var name = $('<td><a href="#" class="name-link" id=' + trip.id + ">" + trip.name + '</a></td>');
var continent = $('<td>' + trip.continent + '</td>');
var weeks = $('<td>' + trip.weeks + ' week(s)</td>');

row.append(name, continent, weeks);
$('.trips-body').append(row);

});
$('#trip-load-button').hide();
};

var tripCallback = function(trip) {
console.log('this should be a single trip');
console.log(trip);
$('.trip-display').empty();
$('#reservation-form').show();
var name = $('<h2>' + trip.name + '</h2>');
var duration = $('<div><span>Duration: </span>' + trip.weeks + ' week(s)</div>');
var cost = $('<div><span>Cost: $</span>' + trip.cost + '</div>');
var id = $('<div><span>ID: </span><span id="trip-id">' + trip.id + "</span></div>");
var continent = $('<div><span>Continent: </span>' + trip.continent + '</div>');
var category = $('<div><span>Category: </span>' + trip.category + '</div>');
var description = $('<div><span>Description: </span><br>' + trip.about + '</div>');
$('.trip-display').append(name, duration, cost, id, continent, category, description);
};

$('.trips-body').on('click', 'a', function(e){

e.preventDefault();
var id = $(this).attr('id');
var tripUrl = url + "/" + id;

$.get(tripUrl, tripCallback);
$("body").animate({ scrollTop: 0 }, "slow");
});

var failCallback = function(xhr) { //uses 'xhr' - 'XML header' - to denote all kinds of responses, including failures
console.log("failure");
console.log(xhr);
$('body').append("Sorry invalid URL!<br>");

};

var alwaysCallback = function() {
console.log("this always happens");
};

$('#trip-load-button').click(function() {
$.get(url, successCallback)
.fail(failCallback)
.always(alwaysCallback);
});


//POST

var postCallback = function(){
alert("Trip reserved! yay!");
console.log("did this work");
};

$('#reservation-form').submit(function(event){
var tripId =$("#trip-id").html();
var reservationUrl = url+ "/" + tripId + "/" + "reserve";
event.preventDefault();
var reservationData = $(this).serialize();
$.post(reservationUrl, reservationData, postCallback);

});


});
17 changes: 17 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
span {
font-weight: bold;
}
h1, #trip-load-button {
margin-left: 3%;
}

.button {
border: 2px solid darkgreen;
border-radius: 15px;
/*padding-left: 10px;*/
/*padding-top: 10px;*/
/*margin-bottom: 20px;*/
background-color: lightgreen;
color: black;

}