diff --git a/html/javascript/navbar.js b/html/javascript/navbar.js new file mode 100644 index 0000000..cfee4c6 --- /dev/null +++ b/html/javascript/navbar.js @@ -0,0 +1 @@ +document.getElementById('navbar').innerHTML = '
' \ No newline at end of file diff --git a/html/javascript/request.js b/html/javascript/request.js index bd94d4f..013bc49 100644 --- a/html/javascript/request.js +++ b/html/javascript/request.js @@ -87,9 +87,15 @@ function addToCart(){ var cart = getCartItems(); //this is an array cart.push(id); //push to bottom of cart localStorage.setItem('cart', JSON.stringify(cart)); + $('#added').fadeIn(1000); + $('#added').fadeIn(1000); + $('#added').fadeOut(1000); + } + else{ + $('#already').fadeIn(1000); + $('#already').fadeIn(1000); + $('#already').fadeOut(1000); } - else - alert("That item is already in your cart!"); } function inCart(id){ @@ -137,4 +143,6 @@ function isUnavailable(id){ } } return 0; -} \ No newline at end of file +} + +//this code allows a message to appear that indicates that the item was successfully placed in the shopping cart. diff --git a/html/javascript/return.js b/html/javascript/return.js new file mode 100644 index 0000000..54a64dd --- /dev/null +++ b/html/javascript/return.js @@ -0,0 +1,144 @@ + +var dev1 = { + id: 1, + name:"George", + hardware:"iphone", + checkout: new Date("11/11/2016"), +}; + +var dev2 = { + id: 2, + name:"Greyson", + hardware:"iphone", + checkout: new Date("8/10/2016"), +}; + +var dev3 = { + id: 3, + name:"Linkin Park", + hardware:"ipad", + checkout: new Date("8/20/2016"), +}; + +var dev4 = { + id: 4, + name:"Abercrombie", + hardware:"ipad", + checkout: new Date("11/3/2016"), +}; + +var dev5 = { + id: 5, + name:"Hulk", + hardware:"computerStick", + checkout: new Date("4/28/2016"), +}; + +var dev6 = { + id: 6, + name:"Captain America", + hardware:"computerStick", + checkout: new Date("10/22/2016"), +}; + +var devices = [dev1, dev2, dev3, dev4, dev5, dev6]; +//This array corresponds to the hardcoded inventory in request.js. The description has been replaced with a +//checkout date, because I imagine that is more the kind of info to pull from the database for this page. +//IDs, names and hardware are the same. + +populateDeviceList(); + +function populateDeviceList() +//generates html and writes to 'devContainer' div in returnPage.html +{ + var devicesToList = getCheckedOutDevices(null); + var htmlString=""; + for (var i = 0; i < devicesToList.length; i++) { + var id = devicesToList[i].id; + var name = devicesToList[i].name; + var hardware = devicesToList[i].hardware; + var checkout = devicesToList[i].checkout; + htmlString+="
"; + htmlString+=name; + htmlString+="

Checked out: " + htmlString+=checkout.toISOString().substring(0,10); + htmlString+="

You've had this device for "; + var milliseconds=new Date().getTime()-checkout.getTime(); + var seconds=Math.floor(milliseconds/1000); + var minutes=Math.floor(seconds/60); + var hours=Math.floor(minutes/60); + var days=Math.floor(hours/24); + var weeks=Math.floor(days/7); + htmlString+= weeks+ " weeks!"; + htmlString+="


"; + } + document.getElementById("devContainer").innerHTML = htmlString; + + var returnbuttons = document.getElementsByClassName('returnbutton'); + for (var i = 0; i < returnbuttons.length; i++) { + returnbuttons[i].addEventListener('click',returnDevice); + } +} + +function returnDevice() +{ + var id = this.getAttribute('id'); + id = parseInt(id.replace(/[^0-9\.]/g,''), 10); + if(isUnavailable(id)) + { + var unavailable = getUnavailableIDs(); + unavailable.splice(unavailable.indexOf(id),1); + localStorage.setItem('unavailable',JSON.stringify(unavailable)); + } + else + alert("That's already marked available. Something may have gone wrong."); + populateDeviceList(); +} + +function getCheckedOutDevices(user) +//Eventually this will return information about all devices checked out by *user* +//Right now there is only one user, and the function just returns IDs of all checked out devicess. +{ + var unavailable = getUnavailableIDs(); + var checkedDevices = new Array(); + for (var i = 0; i < unavailable.length; i++) { + for (var j = 0; j < devices.length; j++) { + if(unavailable[i] == devices[j].id) + { + checkedDevices.push(devices[j]); + break; + } + } + } + return checkedDevices; +} + +function isUnavailable(id){ + var unavailable = getUnavailableIDs(); + if(unavailable.length == 0) + return 0; + else{ + for(var i = 0; i < unavailable.length; i++){ + if(unavailable[i] == (id)) + return 1; + } + } + return 0; +} +function getUnavailableIDs() +//Identical to the function in request.js: just reads the 'unavailable' array in local storage. +//Will need to be changed (or may be obsolete) when we get a database +{ + var unavailable = new Array; + var unavailable_str = localStorage.getItem('unavailable'); + if(unavailable_str !== ""){ + unavailable = JSON.parse(unavailable_str); + } + return unavailable; +} \ No newline at end of file diff --git a/html/webpages/homePage.html b/html/webpages/homePage.html index 6697ed6..cad2f3e 100644 --- a/html/webpages/homePage.html +++ b/html/webpages/homePage.html @@ -1,96 +1,81 @@ - - - - - - - + + + + + + + - Synchrony Financial + Synchrony Financial - - - - - - - + div.menuBox{ + text-align: center; + position: absolute; + top: 50%; + left: 50%; + margin-top: -160px; + margin-left: -260px; + } + + + - + - + -