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

Added localStorage

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