Skip to content

Commit

Permalink
Merge pull request #43 from 3296Fall2020/dl-inventory-frontend
Browse files Browse the repository at this point in the history
Dl inventory frontend
  • Loading branch information
Terence21 authored Nov 17, 2020
2 parents c78e3be + 47ebfd0 commit 7a6113a
Show file tree
Hide file tree
Showing 17 changed files with 654 additions and 5 deletions.
Binary file added web/icon/sortUpDown16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 16 additions & 5 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<link href="style/commonStyle.css" rel="stylesheet" type="text/css" />
<link href="style/dropdownStyle.css" rel="stylesheet" type="text/css" />
<link href="style/account.css" rel="stylesheet" type="text/css" />
<link href="style/clickSort.css" rel="stylesheet" type="text/css" />

</head>
<body>
Expand All @@ -28,14 +29,14 @@
<div class="dropHeader" onclick="dd.dropdown('accountDropDown')">Account</div>
<div class="dropContent" id="accountDropDown">
<a href="#/register">Register</a> <br/>
<a>Log On</a> <br/>
<a>Log Off</a>
<a href="#/login">Log In</a> <br/>
<a href="#/logout">Log out</a>
</div>
</div>
<div class="dropdown">
<div class="dropHeader" onclick="dd.dropdown('accountDropDown')">Inventory</div>
<div class="dropHeader" onclick="dd.dropdown('inventoryDropDown')">Inventory</div>
<div class="dropContent" id="inventoryDropDown">
<a>View Inventory</a>
<a href="#/sneakerInventory">View Inventory</a>
</div>
</div>
</div>
Expand All @@ -46,8 +47,15 @@

<script src="js/reusable/dropdownFw.js"></script>
<script src="js/reusable/routeFw.js"></script>
<script src="js/reusable/ajax.js"></script>
<script src="js/reusable/makeClickSort.js"></script>
<script src="js/components/home.js"></script>
<script src="js/components/register.js"></script>
<script src="js/components/login.js"></script>
<script src="js/components/logout.js"></script>
<script src="js/components/loginForm.js"></script>
<script src="js/components/registerForm.js"></script>
<script src="js/components/sneakerInventory.js"></script>



Expand All @@ -57,7 +65,10 @@

myRoutes['#/'] = home; // page reload will run function home
myRoutes['#/home'] = home; // function home
myRoutes['#/register'] = register; // function home
myRoutes['#/register'] = registerForm; // function register
myRoutes['#/login'] = loginForm; // function login
myRoutes['#/logout'] = logout; // function logout
myRoutes['#/sneakerInventory'] = sneakerInventory; // function sneakerInventory


// routeFw returns an object that has private and public
Expand Down
32 changes: 32 additions & 0 deletions web/js/components/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function login () {

var accountDiv = document.createElement("div");
accountDiv.classList.add("account");

var idSpan = document.createElement('span');
idSpan.innerHTML = "ID ";
accountDiv.appendChild(idSpan);
var idInput = document.createElement("input");
accountDiv.appendChild(idInput);

var passwordSpan = document.createElement('span');
passwordSpan.innerHTML = "Password ";
accountDiv.appendChild(passwordSpan);
var passwordInput = document.createElement("input");
passwordInput.setAttribute("type", "password");
accountDiv.appendChild(passwordInput);


var loginButton = document.createElement("button");
loginButton.innerHTML = "login";
accountDiv.appendChild(loginButton);

var msgDiv = document.createElement("div");
accountDiv.appendChild(msgDiv);

loginButton.onclick = function () {
alert("Do login here")
}; // onclick function

return accountDiv;
}
43 changes: 43 additions & 0 deletions web/js/components/loginForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function loginForm () {

var accountDiv = document.createElement("div");
accountDiv.classList.add("account");

//create break line element
var br = document.createElement("br");

//create a form
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "submit.php");

//create an input element for User ID
var id = document.createElement("input");
id.setAttribute("type", "text");
id.setAttribute("name", "id");
id.setAttribute("placeholder", "User ID");
id.setAttribute("required","true");

//create an input element for Password
var password = document.createElement("input");
password.setAttribute("type", "password");
password.setAttribute("name", "password");
password.setAttribute("placeholder", "Password");
password.setAttribute("required","true");

//create a submit button
var loginButton = document.createElement("input");
loginButton.setAttribute("type", "submit");
loginButton.setAttribute("value", "Log in");

form.appendChild(id);
form.appendChild(br.cloneNode());
form.appendChild(password);
form.appendChild(br.cloneNode());
form.appendChild(loginButton);

accountDiv.appendChild(form);

return accountDiv;

}
14 changes: 14 additions & 0 deletions web/js/components/logout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function logout () {
var accountDiv = document.createElement("div");
accountDiv.classList.add("account");

var logoutButton = document.createElement("button");
logoutButton.innerHTML = "logout";
accountDiv.appendChild(logoutButton);

logoutButton.onclick = function () {
alert("Do logout here")
}; // onclick function

return accountDiv;
}
56 changes: 56 additions & 0 deletions web/js/components/registerForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function registerForm () {

var accountDiv = document.createElement("div");
accountDiv.classList.add("account");

//create break line element
var br = document.createElement("br");

//create a form
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "submit.php");

//create an input element for User ID
var id = document.createElement("input");
id.setAttribute("type", "text");
id.setAttribute("name", "id");
id.setAttribute("placeholder", "User ID");
id.setAttribute("required","true");
id.setAttribute("maxlength","15");

//create an input element for Password
var password = document.createElement("input");
password.setAttribute("type", "password");
password.setAttribute("name", "password");
password.setAttribute("placeholder", "Password");
password.setAttribute("required","true");
password.setAttribute("maxlength","15");

//create an input element for Confirm Password
var confirmPassword = document.createElement("input");
confirmPassword.setAttribute("type", "password");
confirmPassword.setAttribute("name", "confirmPassword");
confirmPassword.setAttribute("placeholder", "Confirm Password");
confirmPassword.setAttribute("required","true");
confirmPassword.setAttribute("maxlength","15");


//create a submit button
var registerButton = document.createElement("input");
registerButton.setAttribute("type", "submit");
registerButton.setAttribute("value", "Register");

form.appendChild(id);
form.appendChild(br.cloneNode());
form.appendChild(password);
form.appendChild(br.cloneNode());
form.appendChild(confirmPassword);
form.appendChild(br.cloneNode());
form.appendChild(registerButton);

accountDiv.appendChild(form);

return accountDiv;

}
29 changes: 29 additions & 0 deletions web/js/components/sneakerInventory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function sneakerInventory() {
var clickSortContainer = document.createElement("div");
clickSortContainer.classList.add("clickSort");
ajax("json/inventory.json", processSneakerInventory, clickSortContainer);

function processSneakerInventory (list) {

var inventoryList = [];
for (var i=0; i <list.length; i++) {
inventoryList[i] = {};
inventoryList[i].sneakerName = list[i].sneakerName;
inventoryList[i].image = "<img src='" + list[i].image + "' style=width:5rem'>";
inventoryList[i].currentValue = list[i].currentValue;
inventoryList[i].releaseDate = list[i].releaseDate;
inventoryList[i].webUserId = list[i].webUserId;
}

var params = {
list: inventoryList,
sortOrderPropName: "sneakerName",
sortIcon: "icon/sortUpDown16.png",
title: "Sneaker Inventory"
}

var myClickSort = makeClickSort(params);
clickSortContainer.appendChild(myClickSort);
}
return clickSortContainer;
}
45 changes: 45 additions & 0 deletions web/js/reusable/ajax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function ajax(url, successCallBackFn, errorEle) {

var httpReq;
if (window.XMLHttpRequest) {
httpReq = new XMLHttpRequest(); //For Firefox, Safari, Opera
} else if (window.ActiveXObject) {
httpReq = new ActiveXObject("Microsoft.XMLHTTP"); //For IE 5+
} else {
alert('ajax not supported');
}

console.log("ready to get content " + url);
httpReq.open("GET", url); // specify which page you want to get


httpReq.onreadystatechange = function () {
//console.log("in ajax, ready state is " + httpReq.readyState);

if (httpReq.readyState === 4) { // 4 means that the data transfer is complete
console.log("in ajax, status is " + httpReq.status);

if (httpReq.status === 200) { // 200 means file found (unlike 404 which means not found)
console.log("in ajax, js object printed next");

var obj = JSON.parse(httpReq.responseText);
console.log(obj);

// Here we call back whichever function wanted us to make the AJAX call.
successCallBackFn(obj);

} else { // error, file not found

// One input parameter to this ajax function is a DOM element designed to hold any possible error message.
// Populate it with as much information as we know about the error.
errorEle.innerHTML = "Error " + httpReq.status + "-" + httpReq.statusText +
" while attempting to read '" + url + "'";
}
}
}; // end of anonymous callback function definition

httpReq.send(null); // initiate ajax call
console.log("call initiated");


} // end function ajax
Loading

0 comments on commit 7a6113a

Please sign in to comment.