Skip to content

Commit

Permalink
nonfunctional commit because last time I changed branches without com…
Browse files Browse the repository at this point in the history
…miting I messed up with stashing and lost my work :p
  • Loading branch information
arc12012 committed Mar 3, 2017
1 parent 8a971dd commit 20d27ab
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 96 deletions.
21 changes: 21 additions & 0 deletions WebContent/html/webpages/orderForm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<form name="orderForm" onsubmit="return submitOrderForm()">
<div class="form-group">
<input type="hidden" name="userID">
<input type="hidden" name="deviceIDs">
<input type="hidden" name="orderAll">
<label for="name">Your name</label><br/>
<input type="text" class="form-control" name="name" placeholder="Name" />
</div>
<div class="form-group">
<label for="phone">Phone Number</label><br/>
<input type="text" class="form-control" name="phone" placeholder="No need to format it nicely (maybe we will implement a nicer phone# field soon)">
</div>
<div class="form-group">
<label for="location">Place to ship to</label><br/>
<input type="text" class="form-control" name="location" placeholder="Address" />
</div>
<div class="form-group">
<label for="timeNeeded">How many weeks do you think you'll need it?</label><br/>
<input type="text" class="form-control" name="timeNeeded" placeholder="Just estimate the number of weeks" />
</div> <button type="submit" class="btn btn-primary" name="Submit">Submit</button>
</form>
4 changes: 2 additions & 2 deletions WebContent/html/webpages/orderFormHandler.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ pageEncoding="ISO-8859-1"%>
<%
//First update employee
String userName = request.getParameter("name");
int phone = Integer.valueOf(request.getParameter("phone"));
String phone = request.getParameter("phone");
int location = Integer.valueOf(request.getParameter("location"));
MySQLAccess access = new MySQLAccess();
access.updateEmployee(1, userName, phone, location); //TODO get ID somehow
%>alert("updated employee "+userName);<%
// And now for the ticket
// TODO
%>
Expand Down
143 changes: 68 additions & 75 deletions WebContent/html/webpages/shoppingCart.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pageEncoding="ISO-8859-1"%>

<body>
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
<%@ include file="navbar.html"%>
<%@ include file="navbar.html"%>
</nav>
<div id="orderInfoModal" class="modal">
<div class="modal-content">
Expand Down Expand Up @@ -102,9 +102,9 @@ pageEncoding="ISO-8859-1"%>
<script src = "../javascript/nhpup_1.1.js"></script>
<script type="text/javascript">
//adding event listeners to all the options, such as ordering and deleting
document.getElementById('os').addEventListener('click',showPopup);
document.getElementById('os').addEventListener('click',orderSelected_showPopup);
document.getElementById('ds').addEventListener('click',deleteSelected);
document.getElementById('oa').addEventListener('click',showPopup);
document.getElementById('oa').addEventListener('click',orderAll_showPopup);
document.getElementById('da').addEventListener('click',deleteAll);
document.onkeydown = function(e) {
Expand All @@ -130,7 +130,9 @@ var employee = {
name:"",
phone:""
}
var checked = new Array();
debug_add_item_to_cart();
show(); //on load, we want to show everything
Expand All @@ -143,26 +145,27 @@ function getCartItems(){
return cart; //return value is an array
}
// Sets cart in localstorage to stringified parameter
function setCart(cartArray) {
localStorage.setItem('cart',JSON.stringify(cartArray));
}
/**
This function displays a list of devices that a user has currently in their shopping cart.
**/
function show(){
var cart = getCartItems(); //get all the cart items you want to show
alert("cart: "+JSON.stringify(cart));
var html = ''; //html string initially empty
var part1 = "nhpup.popup('";
var part2 = "');"
if(cart.length !== 0){ //only continue if there are cart items
html += '<p>Tickets have been generated below based on your desired selections.</p><br>'
for(var i = 0; i < cart.length; i++){ //iterate cart
var id = cart[i]; //this gets the id value from the cart
for(var j = 0; j < devices.length; j++){ //iterate device list
if(devices[j].id === id){ //match the id's "nhpup.popup(' ');"
html += '<div> <input class = "deviceCheckbox" type = "checkbox" id = "' + id + '"> </input><a class = "divlink" href = "#" onmouseover = "'+ part1 + 'Hardware type: ' + devices[j].hardware + '<br><br>' + devices[j].description + part2 + '"><div id = "ticket' + id +'" class = "ticket"><p class = "tickettext">' + devices[j].name + '</p></div></a></div>'; //create listing of all the devices
break; //break out of loop when we match
html += '<div> <input class = "deviceCheckbox" type = "checkbox" id = "' + id + '"> </input><a class = "divlink" href = "#" onmouseover = "'+ part1 + 'Hardware type: ' + cart[i].hardware + '<br><br>' + cart[i].description + part2 + '"><div id = "ticket' + id +'" class = "ticket"><p class = "tickettext">' + cart[i].name + '</p></div></a></div>'; //create listing of all the devices
}
}
}
}
else{ //no point in doing all that computing if the list is empty
html += 'Shopping cart is empty.'; //so give a nice error message.
}
Expand Down Expand Up @@ -198,6 +201,7 @@ function clickTicket(){
document.getElementById(id).checked = true;
checked.push(id);
}
alert("the 'checked' array looks like this: "+JSON.stringify(cart));
}
/**
Expand All @@ -214,20 +218,33 @@ function changeStatus(){
checked.splice(i,1); //remove from the array
}
}
alert("the 'checked' array looks like this: "+JSON.stringify(cart));
}
/**
This function takes all the devices we selected and simulates an order on them.
**/
function showPopup(){
// These functions just redirect button pressed to call the showPopup method with the appropriate parameter
function orderSelected_showPopup() {
showPopup("false");
}
function orderAll_showPopup() {
showPopup("true");
}
// Opens order form and calls autofill method. Parameter is actually a string, not a boolean, because it will be put into a text field.
// It indicaties which button was used to call the method.
// If true, submitting the form will order everything in the cart. If false it only orders selected devices.
function showPopup(orderAllBool){
orderForm.style.display = "block";
autoFillFields();
autoFillFields(orderAllBool);
}
// Exits order form without subitting anything. Should maintain values in each field until page reload
function hidePopup(){
orderForm.style.display = "none";
}
function autoFillFields() {
// Populates orderform fields with database information
// Boolean parameter is applied to the hidden 'orderAll' field on the
// order form, which is read before submition to determine which devices to include
function autoFillFields(orderAllBool) {
<%
MySQLAccess access = new MySQLAccess();
User employee = access.getEmployeeByID(9); //replace with real ID
Expand All @@ -241,6 +258,7 @@ function autoFillFields() {
document.orderForm.name.value=employee.name;
document.orderForm.location.value=employee.locationName;
document.orderForm.phone.value=employee.phone;
document.orderForm.orderAll.value=orderAllBool;
}
function submitOrderForm() {
Expand All @@ -249,46 +267,24 @@ function submitOrderForm() {
// First, employee id
userID=getUserID();
document.orderForm.append('<input type="hidden" name="userID" value="'+userID+'">');
// Now selected devices. I have no idea how to send anything other than strings,
// so I'm pulling the same trick Connor did here and representing the array of
// selected devices as a string "[dev1]:[dev2]:[dev3]:..." where [devn] is a device ID
var deviceIDs=collectSelectedDevices();
for(var i = 0; i < checked.length; i++){ //iterate all the checked off devices
deviceIDs[i] = checked[i]; //get the id of each device
var cart = getCartItems(); //get the cart
for(var j = 0; j < cart.length; j++){ //iterate cart
if(cart[j] == id) //match id's
cart.splice(j,1); //remove from the cart
}
}
var selectedDeviceString="";
for (var i = deviceIDs.length - 1; i >= 0; i--) {
selectedDeviceString+=deviceIDs[i];
if (i!=0) {selectedDeviceString+=":";}
}
alert(selectedDeviceString);
// Now selected devices.
if(document.orderForm.orderAll.value=="true") //if the order form was opened using the order all button
{selectAllDevices();}
var selectedDeviceString=JSON.stringify(checked);
document.orderForm.append('<input type="hidden" name="deviceIDs" value="'+selectedDeviceString+'">');
return true;
}
function orderSelected(){
var response = confirm("Are you sure you'd like to order the selected items?");
if(response == true){ //if they confirm
for(var i = 0; i < checked.length; i++){ //iterate all the checked off devices
var id = checked[i]; //get the id of each device
var requested = getRequestedItems(); //get the unavailable items
var cart = getCartItems(); //get the cart
requested.push(id); //add to unavailable list
// Finally remove selected items from the cart
var cart = getCartItems();
for(var i = 0; i < checked.length; i++){ //iterate all the checked off devices
for(var j = 0; j < cart.length; j++){ //iterate cart
if(cart[j] == id) //match id's
cart.splice(j,1); //remove from the cart
}
localStorage.setItem('requested', JSON.stringify(requested)); //update local storage
localStorage.setItem('cart', JSON.stringify(cart)); //update local storage
}
checked = new Array; //reset the checked off array
show(); //reload the container
}
// And clear the checked array
checked=new Array();
return true;
}
/**
Expand All @@ -312,26 +308,27 @@ function deleteSelected(){
}
}
/**
This function takes all devices in the shopping cart and orders them.
**/
function orderAll(){
var response = confirm("Are you sure you'd like to order the selected items?");
if(response == true){ //if they confirm
var cart = getCartItems(); //get the cart
for(var i = 0; i < cart.length; i++){ //iterate the cart
var id = cart[i]; //get the id of each device
var requested = getRequestedItems(); //get the unavailable items
requested.push(id); //add to unavailable list
localStorage.setItem('requested', JSON.stringify(requested)); //update local storage
// Adds all ids to the checked array
function selectAllDevices() {
var cart = getCartItems();
var duplicate = false;
for (var i = cart.length - 1; i >= 0; i--) {
duplicate = false;
for (var j = checked.length - 1; j >= 0; j--) {
if(checked[j]==cart[i].id)
{
duplicate=true;
}
}
checked = new Array; //reset the checked off array
cart = new Array; //cart should now be empty, so reset also
localStorage.setItem('cart',JSON.stringify(cart)); //update local storage
show(); //reload container
if(!duplicate) checked.push(cart[i].id)
}
}
/**
This function takes all devices in the shopping cart and orders them.
**/
function orderAll(){}
/**
This function takes all devices in the shopping cart and deletes them.
**/
Expand All @@ -345,18 +342,14 @@ function deleteAll(){
}
}
/**
This function gets requested items from local storage.
**/
function getRequestedItems(){
var requested = new Array; //make new array
var requested_str = localStorage.getItem('requested'); //get the string from local storage
if(requested_str !== '' && requested_str !== null){ //as long as its not null
requested = JSON.parse(requested_str); //make into array
}
return requested; //return value is an array
function debug_add_item_to_cart() {
employee.id=5;
employee.location="test";
employee.name="test";
employee.phone="test";
var cart = [employee];
localStorage.setItem("cart",JSON.stringify(cart));
}
</script>
</body>
</html>
Expand Down
Loading

0 comments on commit 20d27ab

Please sign in to comment.