diff --git a/WebContent/html/javascript/listing.jsp b/WebContent/html/javascript/listing.jsp index 9ff0462..64ca8fc 100644 --- a/WebContent/html/javascript/listing.jsp +++ b/WebContent/html/javascript/listing.jsp @@ -1,6 +1,5 @@ <%@ page import = "database.MySQLAccess,entities.ListedDevice" %> -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
@@ -99,7 +98,7 @@ function show(){ if(hardwareMatch == true && softwareMatch == true){ - html += '' + devices[i].description + '
' + devices[i].description + '
' + devices[i].description + '
Choose an option to the left to begin requesting!
"; + } + else{ + //iterate through the hardcoded device DB and select all the ones that match the selected option + for(var i = 0; i < devices.length; i++){ + var hardwareMatch = false; + var softwareMatch = false; - if(html.localeCompare("")==0) - html += "There are no devices with the search criteria: " + this.textContent + "
"; - - //add to HTML page - document.getElementById('devContainer').innerHTML = html; - - //now we need to add event listeners to all the request buttons - var requestbuttons = document.getElementsByClassName('requestbutton'); - for(var i = 0; i < requestbuttons.length; i++){ - requestbuttons[i].addEventListener('click',addToCart); + for(var j = 0; j < activeHOptions.length; j++) { + if (activeHOptions[j] == devices[i].hardware){ + hardwareMatch = true; + } + } + + if (activeHOptions.length == 0) { + hardwareMatch = true; + } + + for(var j = 0; j < activeSOptions.length; j++) { + if (activeSOptions[j] == devices[i].manufacturer){ + softwareMatch = true; + } + } + + if (activeSOptions.length == 0) { + softwareMatch = true; + } + + + if(hardwareMatch == true && softwareMatch == true){ + //if((hw_type.localeCompare(devices[i].hardware) == 0 && sw_type.localeCompare(devices[i].software) == 0) && !isUnavailable(i)){ + html += '' + devices[i].description + '
There are no devices with the search criteria: " + this.textContent + "
"; + + //add to HTML page + document.getElementById('devContainer').innerHTML = html; + + //now we need to add event listeners to all the request buttons + var requestbuttons = document.getElementsByClassName('requestbutton'); + for(var i = 0; i < requestbuttons.length; i++){ + requestbuttons[i].addEventListener('click',addToCart); + } } } @@ -98,7 +140,6 @@ function readFilter() { //Constrcts a filter object for use in the database library that corresponds to the checked optionsin the sidebar var hw_type; var sw_type; - } function addToCart(){ @@ -106,7 +147,7 @@ function addToCart(){ id = parseInt(id.replace(/[^0-9\.]/g,''),10); //this gets just the numerical value from the id! if(!inCart(id)){ //if not in the cart var cart = getCartItems(); //this is an array - cart.push(id); //push to bottom of cart + cart.push(devices[id - 1]); //push to bottom of cart localStorage.setItem('cart', JSON.stringify(cart)); $('#added').fadeIn(1000); $('#added').fadeIn(1000); @@ -144,28 +185,10 @@ function getCartItems(){ return cart; } -function getUnavailableItems(){ - var unavailable = new Array; - var unavailable_str = localStorage.getItem('unavailable'); - if(unavailable_str !== "" && unavailable_str !== null){ - unavailable = JSON.parse(unavailable_str); - } - return unavailable; -} - -function isUnavailable(id){ - var unavailable = getUnavailableItems(); - if(unavailable.length == 0) - return 0; - else{ - for(var i = 0; i < unavailable.length; i++){ - if(unavailable[i] == (id+1)) - return 1; - } - } - return 0; +function makeDeviceArray(){ + window.json = '<%=deviceString%>'; + return JSON.parse(window.json); } - //this code allows a message to appear that indicates that the item was successfully placed in the shopping cart. diff --git a/WebContent/html/webpages/index.html b/WebContent/html/webpages/index.html index 5f5a100..20bd2a7 100644 --- a/WebContent/html/webpages/index.html +++ b/WebContent/html/webpages/index.html @@ -47,7 +47,7 @@