Commit 2837097d authored by jkerr's avatar jkerr
Browse files

Added localStorage

parent 4f423545
......@@ -7,6 +7,7 @@
<script src="scripts/jquery-3.3.1.min.js"></script>
<script src="scripts/switchbooking.js"></script>
<script src="scripts/filterSites.js"></script>
<script src="scripts/setbooking.js"></script>
<link rel="stylesheet" href="scripts/leaflet/leaflet.css"/>
<script src="scripts/leaflet/leaflet.js"></script>
......
var FilterSites = (function () {
pub = {};
/** A simple input validator **/
function pad(str) {
if (str.len < 2) {
return str.padStart(2, "0");
}
}
/** When the search button is pushed**/
pub.searchPushed = function() {
function searchPushed() {
fullName = $("#name").val();
checkIn = $("#checkIn").val().replace(new RegExp("-", 'g'), "");
checkOut = $("#checkOut").val().replace(new RegExp("-", 'g'), "");
......@@ -34,17 +26,15 @@ var FilterSites = (function () {
cOutMonth = cBook.checkin.month.padStart(2, "0");
cOutYear = cBook.checkin.year;
cOutDate = cOutYear+cOutMonth+cOutDay;
if ((cInDate < checkIn && checkIn < cOutDate) || (cInDate < checkOut && checkOut < cOutDate)) {
if ((cOutDate <= checkIn) || (checkOut <= cInDate)) {
continue;
}
//Search for site and add
console.log("Added: "+cBook.number);
takenSites.push(cBook.number);
}
console.log("TakenSites1: "+takenSites);
},
error: function (data) {
alert("ERROR");
alert(data);
}
});
//Clears all sites from table
......@@ -57,19 +47,18 @@ var FilterSites = (function () {
cache: false,
success: function(data) {
sites = data.campSites.site;
console.log("TakenSites2: "+takenSites);
top:
for (i = 0; i < sites.length; i++) {
if (sites[i].siteType.toLowerCase() === type || type === "any") {
if (takenSites.includes(sites[i].number)) {
continue top;
}
tableAdd(sites[i]);
for (i = 0; i < sites.length; i++) {
if (sites[i].siteType.toLowerCase() === type || type === "any") {
if (takenSites.includes(sites[i].number)) {
continue;
}
tableAdd(sites[i]);
}
}
SetBooking.updateButtons();
},
error: function (data) {
alert("ERROR");
alert(data);
}
});
return false;
......@@ -82,32 +71,21 @@ var FilterSites = (function () {
"<td>"+site.siteType+"</td>"+
"<td>"+site.description+"</td>"+
"<td>$"+site.pricePerNight+"</td>"+
"<td><input type='button' value='Book'></td>"+
"<td><input class='bookButton' type='button' value='Book'></td>"+
"</tr>");
}
/** Setup function **/
pub.setup = function() {
/** Adds click event for submit button **/
$("#submit").click(pub.searchPushed);
$("#submit").click(searchPushed);
/** Gets all sites from json and adds them to the table**/
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++) {
tableAdd(sites[i]);
}
},
error: function (data) {
alert("ERROR");
}
});
}
searchPushed();
};
pub.searchPushed = function() {
searchPushed();
};
return pub;
})();
$(document).ready(FilterSites.setup);
\ No newline at end of file
var changeType = (function () {
var SetBooking= (function () {
pub = {};
function setBooking() {
booking = {};
booking.siteId = $(this).parent().parent().find("td")[0].textContent;
booking.checkIn = $("#checkIn").val();
booking.checkOut = $("#checkOut").val();
console.log(booking);
localStorage.setItem("savedQuickCampBooking", JSON.stringify(booking))
}
pub.updateButtons = function() {
bookButtons = $(".bookButton");
console.log("Length: "+bookButtons.length);
for (i = 0; i < bookButtons.length; i++) {
bookButtons[i].onclick = setBooking;
}
}
return pub;
})();
$(document).ready(changeType.setup);
\ No newline at end of file
})();
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment