Skip to content

Commit

Permalink
Shopping cart form should be better now
Browse files Browse the repository at this point in the history
  • Loading branch information
arc12012 committed Apr 11, 2017
1 parent 66dd230 commit 0a919e1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
5 changes: 3 additions & 2 deletions WebContent/html/webpages/orderFormHandler.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if(Integer.parseInt(request.getParameter("location_dropdown"))==0)
request.getParameter("locname"),
request.getParameter("state"),
request.getParameter("address"),
request.getParameter("city"),
request.getParameter("town"),
request.getParameter("zip"),
sso
);
Expand All @@ -35,9 +35,10 @@ if(Integer.parseInt(request.getParameter("location_dropdown"))==0)
//Now update employee
String userName = request.getParameter("name");
String phone = request.getParameter("phone");
String email = request.getParameter("email");
// read location ID, but only if we haven't already generated it when adding new location to db
if(location==-1){ location = Integer.parseInt(request.getParameter("location_dropdown"));}
EmployeeQueries.updateEmployee(sso, userName, phone, location);
EmployeeQueries.updateEmployee(sso, userName, phone, location, email);
System.out.print("updated employee "+userName);
// And now for the ticket
Expand Down
42 changes: 20 additions & 22 deletions WebContent/html/webpages/shoppingCart.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ if(c.getName().equals("ssoNum")) sso = Integer.parseInt(c.getValue());
text-align: center;
padding: 10px;
}
input[type=text]{ margin: 0 auto; width: 60%; }
input[type=tel]{ margin: 0 auto; width: 60%; }
input[type=number]{ margin: 0 auto; width: 60%; }
</style>

</head>
Expand Down Expand Up @@ -82,7 +87,10 @@ if(c.getName().equals("ssoNum")) sso = Integer.parseInt(c.getValue());
<label for="phone">Phone Number</label><br/>
<input type="tel" class="form-control" name="phone" placeholder="203-867-5309" style="margin: 0 auto; width:60%" required>
</div>

<div class="form-group row">
<label for="email">Email</label><br/>
<input type="email" class="form-control" name="email" placeholder="name@org.domain" style="margin: 0 auto; width:60%" required>
</div>
<div class="form-group">
<label for="location_dropdown">Place to ship to</label><br/>
<select class="form-control" name="location_dropdown" id="dropdown" onchange="forceUpdateLocationMetadata()" style="width:65%; max-height: 80%; text-align: center; vertical-align: center; align-items: center; display: block; position: relative; margin: 0% auto; text-align-last:center; padding:">
Expand All @@ -99,8 +107,8 @@ if(c.getName().equals("ssoNum")) sso = Integer.parseInt(c.getValue());
<input type="text" onkeyup="forceDropdownCustomLocation" class="form-control" name="address" placeholder="Address" required/>
</div>
<div class="form-group row">
<label for="city">City</label>
<input type="text" onkeyup="forceDropdownCustomLocation" class="form-control" name="city" placeholder="City" required/>
<label for="town">City</label>
<input type="text" onkeyup="forceDropdownCustomLocation" class="form-control" name="town" placeholder="City" required/>
</div>
</div>
<div class="col-md-6" style="width:50%">
Expand Down Expand Up @@ -163,7 +171,7 @@ if(c.getName().equals("ssoNum")) sso = Integer.parseInt(c.getValue());
</div>
<div class="form-group row">
<label for="zip">Zip</label>
<input type="number" onkeyup="forceDropdownCustomLocation" class="form-control" name="zip" placeholder="Zip Code" style="margin: 0 auto; width:60%" required/>
<input type="text" onkeyup="forceDropdownCustomLocation" class="form-control" name="zip" placeholder="Zip Code" pattern="[0-9]{5}" title="Input must be 5 digits" style="margin: 0 auto; width:60%" required/>
</div>
</div>
</div>
Expand Down Expand Up @@ -205,7 +213,7 @@ document.getElementById('da').addEventListener('click',deleteAll);
// Event listeners for order form address fields, to force select New Location if a field is changed
document.orderForm.address.addEventListener('keyup',forceDropdownCustomLocation);
document.orderForm.city.addEventListener('keyup',forceDropdownCustomLocation);
document.orderForm.town.addEventListener('keyup',forceDropdownCustomLocation);
document.orderForm.state.addEventListener('keyup',forceDropdownCustomLocation);
document.orderForm.zip.addEventListener('keyup',forceDropdownCustomLocation);
Expand Down Expand Up @@ -235,7 +243,6 @@ var employee = {
var checked = new Array();
var locations = getLocations();
//debug_add_items_to_cart();
show(); //on load, we want to show everything
Expand Down Expand Up @@ -351,14 +358,17 @@ function autoFillFields(orderAllBool) {
int locationID = employee.getLocation();
String name = employee.getName();
String phone = employee.getPhone();
String email = employee.getEmail();
%>
employee.name = "<%=name%>";
employee.phone = "<%=phone%>";
employee.email = "<%=email%>";
document.orderForm.name.value=employee.name;
document.orderForm.phone.value=employee.phone;
document.orderForm.email.value=employee.email;
// already got locations on page load, now populate dropdown and mark appropriate option selected
document.orderForm.location_dropdown.innerHTML="<option value = 0>New Location...</option>";
for (var i = locations.length - 1; i >= 0; i--) {
for (var i = 0; i < locations.length; i++) {
document.orderForm.location_dropdown.innerHTML+=
("<option value = "+locations[i].id
+ (locations[i].id == "<%=locationID%>" ? " selected>" : ">")
Expand Down Expand Up @@ -394,7 +404,7 @@ function forceUpdateLocationMetadata() {
{
document.orderForm.locname.value = selectedLocation.name;
document.orderForm.address.value = selectedLocation.address;
document.orderForm.city.value = selectedLocation.town;
document.orderForm.town.value = selectedLocation.town;
document.orderForm.state.value = selectedLocation.state;
document.orderForm.zip.value = selectedLocation.zip;
// if we're force updating metadata, it means we don't want the name to be editable
Expand All @@ -414,10 +424,6 @@ function forceDropdownCustomLocation() {
function getLocations() {
<%
Location[] loci = LocationQueries.getLocations(sso);
for(int i=0; i<loci.length; i++)
{
System.out.println(loci[i].getName());
}
%>
var loci = new Array(<%=loci.length%>);
<%
Expand All @@ -430,7 +436,7 @@ function getLocations() {
address:"<%=loci[i].getAddress()%>",
town:"<%=loci[i].getTown()%>",
state:"<%=loci[i].getState()%>",
zip:<%=loci[i].getZip()%>
zip:"<%=loci[i].getZip()%>"
};
<%
}
Expand Down Expand Up @@ -513,15 +519,7 @@ function deleteAll(){
function getUserID() {
return <%=sso%>;
}
function debug_add_items_to_cart() {
employee.id=5;
employee.location="test";
employee.name="test";
employee.phone="test";
var cart = [employee];
cart.push({id:6,location:"test",name:"test",phone:"test"});
localStorage.setItem("cart",JSON.stringify(cart));
}
</script>
</body>
</html>
Expand Down
5 changes: 3 additions & 2 deletions src/database/EmployeeQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void initializeEmployee(int id) throws ClassNotFoundException, SQL
access.closeConnection();
}

public static void updateEmployee(int id, String name, String phone, int location) throws ClassNotFoundException, SQLException
public static void updateEmployee(int id, String name, String phone, int location, String email) throws ClassNotFoundException, SQLException
{
System.out.println("Updating employee "+id+": "+name+".\nPhone: "+phone+", location: "+location);
MySQLAccess access = new MySQLAccess();
Expand All @@ -28,7 +28,8 @@ public static void updateEmployee(int id, String name, String phone, int locatio
query+="Name='"+name;
query+="', Phone_Number='"+phone;
query+="', Location_ID="+location;
query+=" WHERE Employee_ID="+id;
query+=", Email='"+email;
query+="' WHERE Employee_ID="+id;
System.out.println(query);
statement.executeUpdate(query);
access.closeConnection();
Expand Down

0 comments on commit 0a919e1

Please sign in to comment.