Commit a1e35529 authored by jkerr's avatar jkerr
Browse files

Cleaned up code

parent b4ba9cba
Pipeline #2522 passed with stage
in 3 seconds
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JSLint" enabled="true" level="ERROR" enabled_by_default="true" />
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JSLintConfiguration">
<option browser="true" />
<option for="true" />
<option maxerr="50" />
<option multivar="true" />
<option this="true" />
<option white="true" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
......@@ -27,12 +27,12 @@
<main>
<section id="infoContainer">
<article id="infoContainer">
<h2>Welcome:</h2>
<p>Here at QuickCamp camping ground, we offer only the best cabins, as well as tent and caravan sites.</p>
</section>
<section>
<section id="book">
</article>
<div>
<article id="book">
<h2>Book a Site:</h2>
<input id="submit" name="submit" type="submit" value="Search">
<form>
......@@ -51,44 +51,28 @@
</tr>
</table>
</div>
</section>
<section id="mapContainer">
</article>
<div id="mapContainer">
<div id="map"></div>
</section>
</section>
<figure id="photo"><img src=""></figure>
</div>
</div>
<figure id="photo"></figure>
</main>
<footer>
<section id="footer">
<article id="footer">
<h3>More Info:</h3>
<p>QuickCamp is a purely fictional site, this webpage was created for educational purposes.</p>
<p>Contact Us: Lorem ipsum dolor sit amet.</p>
<p>Address: Consectetur adipiscing elit.</p>
<p>Maecenas commodo mattis purus, vitae facilisis diam.</p>
</section>
<section id="reviews">
</article>
<article id="reviews">
<h3>Reviews:</h3>
<div>
<h4></h4>
<p><cite></cite><p></p>
<h4>Placeholder title:</h4>
<p><cite>"Placeholder Review"</cite><p></p>
<p id="reviewer"></p>
</div>
</section>
</article>
</footer>
<section id="palette">
<section id="black"></section>
<section id="darkblue"></section>
<section id="medblue"></section>
<section id="lightblue"></section>
<section id="white"></section>
<p id="lato">Lato Text</p>
<p id="opensans">Opensans text</p>
<p id="quicksand">Quicksand text</p>
<p id="ubuntu">Ubuntu text</p>
</section>
</body>
</html>
\ No newline at end of file
......@@ -59,7 +59,7 @@
},
{
"number": "101",
"name": "Nicks Test # 101",
"name": "Nick Meek",
"checkin": {
"day": "1",
"month": "10",
......@@ -73,7 +73,7 @@
},
{
"number": "203",
"name": "Nicks Test # 203",
"name": "Stefanie Zollmann",
"checkin": {
"day": "1",
"month": "10",
......
......@@ -4,61 +4,61 @@
{
"number": "101",
"siteType": "Tent",
"description": "Tent site.",
"description": "20 Square Meters",
"pricePerNight": "40.0"
},
{
"number": "102",
"siteType": "Tent",
"description": "tent site.",
"description": "25 Square Meters",
"pricePerNight": "40.0"
},
{
"number": "201",
"siteType": "Tent",
"description": "Tent site",
"description": "15 Square meters",
"pricePerNight": "40.0"
},
{
"number": "202",
"siteType": "Tent",
"description": "tent site",
"description": "22 Square Meterse",
"pricePerNight": "40.0"
},
{
"number": "203",
"siteType": "Cabin",
"description": "Cabin",
"description": "Luxury Cabin for 2",
"pricePerNight": "195.00"
},
{
"number": "204",
"siteType": "Cabin",
"description": "Cabin",
"description": "Budget Cabin for 3",
"pricePerNight": "80.0"
},
{
"number": "205",
"siteType": "Cabin",
"description": "Cabin",
"description": "Budget Cabin for 3",
"pricePerNight": "80.0"
},
{
"number": "301",
"siteType": "Cabin",
"description": "Cabin",
"description": "Budget Cabin for 4",
"pricePerNight": "90.0"
},
{
"number": "302",
"siteType": "Van",
"description": "Van",
"description": "Powered Van Park",
"pricePerNight": "60.0"
},
{
"number": "303",
"siteType": "Van",
"description": "Van.",
"description": "Large Un-powered Van Park",
"pricePerNight": "60.0"
}
]
......
[
{
"title": "Great Campsite",
"author": "Test User",
"author": "Jackson Kerr",
"reviewcontent": "Great Campsite, I would come back and recommend this location."
},
{
"title": "Nice and quiet campsite",
"author": "Test User2",
"author": "Stefanie Zollmann",
"reviewcontent": "Nice campsite in quiet neighborhood."
},
{
"title": "Close to the beach",
"author": "Test User3",
"author": "Nick Meek",
"reviewcontent": "Nice and close to the beach. I recommend this location."
}
]
//global $
//global console
//global SetBooking
var FilterSites = (function () {
pub = {};
"use strict";
var pub = {};
/** Addes a site to the table **/
function tableAdd(site) {
$("#found").append("<tr class='resultRow'>"+
"<td>"+site.number+"</td>"+
"<td>"+site.siteType+"</td>"+
"<td>"+site.description+"</td>"+
"<td>$"+site.pricePerNight+"</td>"+
"<td><input class='bookButton' type='button' value='Book'></td>"+
"</tr>");
}
/** When the search button is pushed**/
function searchPushed() {
fullName = $("#name").val();
checkIn = $("#checkIn").val().replace(new RegExp("-", 'g'), "");
checkOut = $("#checkOut").val().replace(new RegExp("-", 'g'), "");
type = $("#siteType").val();
takenSites = [];
/** Get data from fields **/
var checkIn = $("#checkIn").val().replace(new RegExp("-", "g"), "");
var checkOut = $("#checkOut").val().replace(new RegExp("-", "g"), "");
var type = $("#siteType").val();
var takenSites = [];
//Gets all bookings
address = "scripts/data/bookings.json";
/** Get bookings **/
var address = "scripts/data/bookings.json";
$.ajax({
type: "GET",
url: address,
cache: false,
success: function(data) {
aBookings = data.bookings.booking;
for (i = 0; i < aBookings.length; i++) {
/** Add each site is already booked between the given dates to takenSites **/
var aBookings = data.bookings.booking;
var cBook,cInDay,cInMonth,cInYear,cInDate,cOutDay,cOutMonth,cOutYear,cOutDate,i;
for (i = 0; i < aBookings.length; i += 1) {
cBook = aBookings[i];
cInDay = cBook.checkin.day.padStart(2, "0");
cInMonth = cBook.checkin.month.padStart(2, "0");
......@@ -26,55 +45,46 @@ var FilterSites = (function () {
cOutMonth = cBook.checkin.month.padStart(2, "0");
cOutYear = cBook.checkin.year;
cOutDate = cOutYear+cOutMonth+cOutDay;
if ((cOutDate <= checkIn) || (checkOut <= cInDate)) {
continue;
if (!((cOutDate <= checkIn) || (checkOut <= cInDate))) {
takenSites.push(cBook.number);
}
//Search for site and add
takenSites.push(cBook.number);
}
},
error: function (data) {
error: function () {
console.log("Ajax error when retrieving "+address);
}
});
//Clears all sites from table
/** Clear all sites from table **/
$("#found tr").not("#tableHead").remove();
//Adds all campsites to table
/** Get sites **/
address = "scripts/data/campsites.json";
$.ajax({
type: "GET",
url: address,
cache: false,
success: function(data) {
sites = data.campSites.site;
for (i = 0; i < sites.length; i++) {
/** Call tableAdd on unbooked sites **/
var sites = data.campSites.site;
var i;
for (i = 0; i < sites.length; i += 1) {
if (sites[i].siteType.toLowerCase() === type || type === "any") {
if (takenSites.includes(sites[i].number)) {
continue;
if (!takenSites.includes(sites[i].number)) {
tableAdd(sites[i]);
}
tableAdd(sites[i]);
}
}
/** Call updateButtons to add a book button to each site in table **/
SetBooking.updateButtons();
},
error: function (data) {
error: function () {
console.log("Ajax error when retrieving "+address);
}
});
return false;
}
/** Addes a site to the table **/
function tableAdd(site) {
$("#found").append("<tr class='resultRow'>"+
"<td>"+site.number+"</td>"+
"<td>"+site.siteType+"</td>"+
"<td>"+site.description+"</td>"+
"<td>$"+site.pricePerNight+"</td>"+
"<td><input class='bookButton' type='button' value='Book'></td>"+
"</tr>");
}
/** Setup function **/
pub.setup = function() {
/** Adds click event for submit button **/
......@@ -83,9 +93,12 @@ var FilterSites = (function () {
searchPushed();
};
/** Calls searchPushed **/
pub.searchPushed = function() {
searchPushed();
};
return pub;
})();
}());
$(document).ready(FilterSites.setup);
\ No newline at end of file
//global $
var GetBookings = (function () {
pub = {};
/** When the search button is pushed**/
pub.setup = function() {
$.getJSON("scripts/data/bookings.json", function(data) {
for (i = 0; i < data.bookings.booking.length; i++) {
cBook = data.bookings.booking[i];
tableAdd(cBook);
"use strict";
var pub = [];
}
});
}
/** Addes a site to the table **/
/** Addes a booking to the table **/
function tableAdd(booking) {
checkIn = booking.checkin.day+"-"+booking.checkin.month+"-"+booking.checkin.year;
checkOut = booking.checkout.day+"-"+booking.checkout.month+"-"+booking.checkout.year;
var checkIn = booking.checkin.day+"-"+booking.checkin.month+"-"+booking.checkin.year;
var checkOut = booking.checkout.day+"-"+booking.checkout.month+"-"+booking.checkout.year;
$("#bookings").append("<tr class='resultRow'>"+
......@@ -25,6 +16,22 @@ var GetBookings = (function () {
"<td>"+checkOut+"</td>"+
"</tr>");
}
/** Setup Function **/
pub.setup = function() {
/** Get Bookings**/
$.getJSON("scripts/data/bookings.json", function(data) {
/** Add each booking to table **/
var cBook,i;
for (i = 0; i < data.bookings.booking.length; i += 1) {
cBook = data.bookings.booking[i];
tableAdd(cBook);
}
});
};
return pub;
})();
}());
$(document).ready(GetBookings.setup);
\ No newline at end of file
//global $
//global L
var Map = (function () {
pub = {};
"use strict";
var pub = [];
var map;
var markers = L.layerGroup();
var campPopup;
/** Setup Function **/
pub.setup = function() {
map = L.map('map').setView([-45.858578, 170.527263], 14.45);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
{
maxZoom: 18,
attribution: "Map data &copy; " +
'<a href="http://www.openstreetmap.org/copyright">' +
"OpenStreetMap contributors</a> CC-BY-SA"
}).addTo(map);
/** Adds buttons above map **/
$("#mapContainer").parent().prepend("" +
"<div id='mapButtons'><input type='button' id='mapShowAll' value='Show All'>" +
"<input type='button' id='mapShowRes' value='Show Restaurants'>" +
"<input type='button' id='mapShowAttr' value='Show Attractions'></div>");
// NEED TO ADD EVENTS TO BUTTONS HERE
$("#mapShowAll").on("click", function() {drawIcons("all")});
$("#mapShowRes").on("click", function() {drawIcons("restaurant")});
$("#mapShowAttr").on("click", function() {drawIcons("attraction")});
drawIcons("all");
/** Creates a marker with given geo and properties data **/
function createMarker(geo, properties) {
var marker = L.marker(geo.coordinates).addTo(markers);
if (geo.polygon === true) {
L.polygon(geo.polygonCoords).addTo(markers);
}
marker.bindPopup("<h2>" + properties.name + "</h2>" + "<p>" + properties.info + "</p>");
}
/** Draws all icons of given type to map, of all if "all" is given **/
/** Draws all icons of given type to map, or all if "all" is given **/
function drawIcons(type) {
map.removeLayer(markers);
markers = L.layerGroup();
$.getJSON("scripts/data/POI.json", function(data) {
for (i = 0; i < data.features.length; i++) {
var i, cFeature, geo, properties, cType;
for (i = 0; i < data.features.length; i += 1) {
cFeature = data.features[i];
geo = cFeature.geometry;
properties = cFeature.properties;
......@@ -45,16 +33,34 @@ var Map = (function () {
markers.addTo(map);
});
}
/** Creates a marker with given geo and properties data **/
function createMarker(geo, properties) {
marker = L.marker(geo.coordinates).addTo(markers);
if (geo.polygon === true) {
shape = L.polygon(geo.polygonCoords).addTo(markers);
}
marker.bindPopup("<h2>" + properties.name + "</h2>" + "<p>" + properties.info + "</p>");
}
/** Setup Function **/
pub.setup = function() {
/** Create map with leaflet and add to page **/
map = L.map("map").setView([-45.858578, 170.527263], 14.45);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
{
maxZoom: 18,
attribution: "Map data &copy; " +
"<a href='http://www.openstreetmap.org/copyright'>" +
"OpenStreetMap contributors</a> CC-BY-SA"
}).addTo(map);
/** Adds buttons above map **/
$("#mapContainer").parent().prepend("" +
"<div id='mapButtons'><input type='button' id='mapShowAll' value='Show All'>" +
"<input type='button' id='mapShowRes' value='Show Restaurants'>" +
"<input type='button' id='mapShowAttr' value='Show Attractions'></div>");
/** Adds events to buttons**/
$("#mapShowAll").on("click", function() {drawIcons("all");});
$("#mapShowRes").on("click", function() {drawIcons("restaurant");});
$("#mapShowAttr").on("click", function() {drawIcons("attraction");});
drawIcons("all");
};
return pub;
})();
}());
$(document).ready(Map.setup);
\ No newline at end of file
var Reviews = (function() {
pub = [];
//global jQuery
//global $
var Reviews = (function () {
"use strict";
var pub = [];
var reviews;
var cReview = 0;
//Get reviews
pub.setup = function () {
$.getJSON("scripts/data/reviews.json", function (data) {
reviews = data;
$("#reviews").find("div").css("opacity", 0);
nextReview();
reviewLoop();
});
};
function nextReview() {
var newReview = reviews[cReview];
$("#reviews").find("cite").text("\""+newReview.reviewcontent+"\"");
$("#reviews").find("h4").text(newReview.title);
$("#reviews").find("#reviewer").text("- "+newReview.author);
cReview += (cReview < reviews.length-1 ? 1 : 1-(reviews.length));
}
function reviewLoop() {
setInterval(function () {
......@@ -20,15 +24,15 @@ var Reviews = (function() {
}
function nextReview() {
newReview = reviews[cReview];
$("#reviews").find("cite").text("\""+newReview.reviewcontent+"\"");
$("#reviews").find("h4").text(newReview.title);
$("#reviews").find("#reviewer").text(newReview.author);
cReview += (cReview < reviews.length-1 ? 1 : 1-(reviews.length));
}
//Get reviews
pub.setup = function () {
$.getJSON("scripts/data/reviews.json", function (data) {
reviews = data;
$("#reviews").find("div").css("opacity", 0);
nextReview();
reviewLoop();
});
};
//Set review
......@@ -36,7 +40,7 @@ var Reviews = (function() {
return pub;
})();
}());
......
//global $
var SetBooking= (function () {
pub = {};
"use strict";
var pub = [];
function setBooking() {
booking = {};
var booking = {};
booking.siteId = $(this).parent().parent().find("td")[0].textContent;
booking.checkIn = $("#checkIn").val();
booking.checkOut = $("#checkOut").val();
localStorage.setItem("savedQuickCampBooking", JSON.stringify(booking))
localStorage.setItem("savedQuickCampBooking", JSON.stringify(booking));
}
pub.updateButtons = function() {
bookButtons = $(".bookButton");
for (i = 0; i < bookButtons.length; i++) {
var bookButtons = $(".bookButton");
var i;
for (i = 0; i < bookButtons.length; i += 1) {
bookButtons[i].onclick = setBooking;
}
}
};
return pub;
})();
\ No newline at end of file
}());
\ No newline at end of file
//global $
//global FilterSites
var changeType = (function () {