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

Nicole Trek #32

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
Binary file added images/beach.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TREKKER!</title>
<link rel="stylesheet" href="styles/index.css">
<link href="https://fonts.googleapis.com/css?family=Federo|Mallanna|Trade+Winds" rel="stylesheet">
</head>
<body>
<header>
<h1>Welcome to Trekker!</h1>
<img src="images/beach.jpg" alt="beach banner">
</header>

<section id="main">
<button type="button" class="button index-button" name="button">All Trips</button>

<section id="index">
<table id="trips-table">
<tr>
<th>Trip Name</th>
<th>Trip Continent</th>
</tr>
<tbody class="trips-tbody"></tbody>
</table>
</section>

<section id="show">

<div id="show-trip"></div>

<form id="add-reservation">
<h2>Book this trip!</h2>
<label for="name">Name: </label>
<input type="text" name="name"></input>
<br>
<label for="email">Email: </label>
<input type="text" name="email"></input>
<br>
<label for="age">Age: </label>
<input type="text" name="age"></input>
<br>

<input type="hidden" id="hidden-id-field">

<button type="submit" class="button form-button" name="submit-button">Trek On!</button>
</form>

</section>


</section>

<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script src="scripts/trek.js" type="text/javascript"></script>
</body>
</html>
94 changes: 94 additions & 0 deletions scripts/trek.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
$(document).ready(function() {
showLandingView();

////////// API URL
var url = 'https://trektravel.herokuapp.com/trips';

////////// GET REQUEST
$('.index-button').on('click', function() {
showIndexView(successCallback, failCallback)
})

////////// GET CALLBACKS
var successCallback = function (response) {
$.each(response, function(index, trip) {
var row = $("<tr></tr>"),
name = $('<td><a href="#" id=' + trip.id + ">" + trip.name + "</a></td>"),
continent = $("<td>" + trip.continent + "</td>");

row.append(name, continent);
$(".trips-tbody").append(row);
})
};

var failCallback = function(xhr) {
alert("There has been a problem, please refresh.");
};

///////// SHOW
$(".trips-tbody").on("click", "a", function() {
var tripId = $(this).attr('id'),
showUrl = url + '/' + tripId;

$.get(showUrl, showCallback);

showTripView();
});


var showCallback = function(trip) {
var tripId = $("<h6>Trip Id</h6><p>" + trip.id + "</p>"),
name = $("<h4>Name</h4><p>" + trip.name + "</p>"),
continent = $("<h4>Continent</h4><p>" + trip.continent + "</p>"),
category = $("<h4>Category</h4><p>" + trip.category + "</p>"),
weeks = $("<h4>Amount of Weeks</h4><p>" + trip.weeks + "</p>"),
cost = $("<h4>Cost</h4><p>$" + trip.cost + "</p>"),
about = $("<h4>About</h4><p>" + trip.about + "</p>");

$("#show-trip").empty();
$("#show-trip").append(tripId, name, continent, category, weeks, cost, about);
$("#hidden-id-field").val(trip.id)

showTripView();
};

////////// VIEWS
var speed = 1000; // thanks, kai

function showLandingView() {
$("#show").hide(speed);
$("#index").hide(speed);
}

function showIndexView(successCallback, failCallback) {
$("#show").hide(speed);
$("#index").show(speed);

$.get(url, successCallback)
.fail(failCallback);
}

function showTripView() {
$("#show").show(speed);
$("#index").hide(speed);
}

////////// POST
var addTripCallback = function(event) {
event.preventDefault();

var tripData = $(this).serialize(),
tripId = $("#hidden-id-field").val();

var reservationUrl = url + "/" + tripId + "/reserve";
$.post(reservationUrl, tripData, postCallback);

showIndexView();
};

$("#add-reservation").submit(addTripCallback);

var postCallback = function() {
alert("Reservation made!");
}
});
Loading