From cf6a423b3030302803eb69a94fc9793a15246ce6 Mon Sep 17 00:00:00 2001 From: John Costa Date: Thu, 23 Mar 2017 14:39:10 -0400 Subject: [PATCH] request page done, localstorage issue fixed --- WebContent/html/javascript/listing.jsp | 5 +- WebContent/html/javascript/navbar.js | 2 +- WebContent/html/javascript/request.jsp | 115 +++++++++++------- WebContent/html/webpages/index.html | 2 +- .../{requestPage.html => requestPage.jsp} | 26 ++-- 5 files changed, 86 insertions(+), 64 deletions(-) rename WebContent/html/webpages/{requestPage.html => requestPage.jsp} (75%) 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].name + '

' + devices[i].description + '



' + html += '
' + devices[i].name + '

' + devices[i].description + '



' } } document.getElementById('devContainer').innerHTML = html; diff --git a/WebContent/html/javascript/navbar.js b/WebContent/html/javascript/navbar.js index 3e706ea..ba46607 100644 --- a/WebContent/html/javascript/navbar.js +++ b/WebContent/html/javascript/navbar.js @@ -1 +1 @@ -document.getElementById('navbaruniversal').innerHTML = '
' +document.getElementById('navbaruniversal').innerHTML = '
' diff --git a/WebContent/html/javascript/request.jsp b/WebContent/html/javascript/request.jsp index 8b03631..b1cca96 100644 --- a/WebContent/html/javascript/request.jsp +++ b/WebContent/html/javascript/request.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"%> @@ -60,37 +59,80 @@ function ajaxFunction(){ } //add event listeners to the options in the left sidebar -for(var a = 0; a < options.length; a++){ - options[a].addEventListener('click', show); +for(var a = 0; a < hardwareOptions.length; a++){ + hardwareOptions[a].addEventListener('click', show); +} +for(var a = 0; a < softwareOptions.length; a++){ + softwareOptions[a].addEventListener('click', show); } //when an option is selected, show a new list of devices based on what the user asked for function show(){ - currentFilter = readFilter(); - selectedDevices = getDevices(currentFilter); //when connor is done with the database library getDevices should be redirected there - + //currentFilter = readFilter(); + //selectedDevices = getDevices(currentFilter); //when connor is done with the database library getDevices should be redirected there - + var type = this.getAttribute('data-type'); var html = ''; - - //iterate through the hardcoded device DB and select all the ones that match the selected option - for(var i = 0; i < devices.length; i++){ - if((hw_type.localeCompare(devices[i].hardware) == 0 && sw_type.localeCompare(devices[i].software) == 0) && !isUnavailable(i)){ - html += '
' + devices[i].name + '

' + devices[i].description + '



' + var activeHOptions = []; + var activeSOptions = []; + for(var i = 0; i < hardwareOptions.length; i++) { + if (hardwareOptions[i].checked == true) { + activeHOptions.push(hardwareOptions[i].getAttribute("data-type")); } } + for(var i = 0; i < softwareOptions.length; i++) { + if (softwareOptions[i].checked == true) { + activeSOptions.push(softwareOptions[i].getAttribute("data-type")); + } + } + if(activeHOptions.length == 0 && activeSOptions.length == 0){ + document.getElementById('devContainer').innerHTML = "

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].name + '

' + devices[i].description + '



' + } + } + + 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); + } } } @@ -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 @@