update,
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
var storeId = document.getElementById("storeId").value;
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = "viewCart";
|
||||
var json;
|
||||
xhr.open("GET", url);
|
||||
xhr.send();
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
json = JSON.parse(xhr.responseText);
|
||||
console.log(json);
|
||||
if(json.statue && json.storeId != null && json.storeId != storeId){
|
||||
var size = window.location.href.search("#");
|
||||
location.replace("store?id=" + storeId + "#wraning-modal");
|
||||
}else if (json.statue && json.storeId == storeId) {
|
||||
let index = 0;
|
||||
var elemt = document.getElementsByTagName("ol")[0];
|
||||
for(var i = 0; i < elemt.childElementCount; i++){
|
||||
if(i == index && json.itemCount > 0){
|
||||
elemt.children[i].innerHTML += '<li id="cart"><a href="cart" class="selected"><span><div class="item-count">' + json.itemCount +'</div> Cart</span></a></li>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function closeModal(){
|
||||
location.replace("home#");
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = "viewCart";
|
||||
var json;
|
||||
var storeId;
|
||||
xhr.open("GET", url);
|
||||
xhr.send();
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
json = JSON.parse(xhr.responseText);
|
||||
console.log(json);
|
||||
if(json.statue && json.itemCount > 0){
|
||||
let index = 0;
|
||||
var elemt = document.getElementsByTagName("ol")[0];
|
||||
for(var i = 0; i < elemt.childElementCount; i++){
|
||||
if(i == index){
|
||||
elemt.children[i].innerHTML += '<li id="cart"><a href="cart" class="selected"><span><div class="item-count">' + json.itemCount +'</div> Cart</span></a></li>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function viewStore(id){
|
||||
//location.replace("store?id=" + id);
|
||||
storeId = id;
|
||||
if(json.storeId != id && json.storeId != null){
|
||||
location.replace("home#wraning-modal");
|
||||
}else{
|
||||
location.replace("store?id=" + id);
|
||||
}
|
||||
}
|
||||
|
||||
function closeModal(){
|
||||
location.replace("home#");
|
||||
}
|
||||
|
||||
function clearCart(){
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = "removeInCart";
|
||||
xhr.open("POST", url, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
var json = JSON.parse(xhr.responseText);
|
||||
if(json.statue == true){
|
||||
location.replace("store?id=" + storeId);
|
||||
}
|
||||
}
|
||||
};
|
||||
var data = JSON.stringify({"action": "remove"});
|
||||
xhr.send(data);
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
|
||||
var defaultForm;
|
||||
var defaultButton;
|
||||
|
||||
function login(){
|
||||
var username = document.getElementById("username").value;
|
||||
var password = document.getElementById("password").value;
|
||||
|
||||
if(username == "" || password == ""){
|
||||
document.getElementByClassName("message").innerHTML = "error";
|
||||
}else{
|
||||
document.getElementById("loginform").submit();
|
||||
}
|
||||
}
|
||||
|
||||
function signupForm(){
|
||||
var form = document.getElementById("loginform");
|
||||
var btn = document.getElementsByClassName("signup")[0];
|
||||
defaultForm = form.innerHTML;
|
||||
defaultButton = btn.innerHTML;
|
||||
form.id = "signupform";
|
||||
form.innerHTML = '<input type="email" name="email" id="email" value="" placeholder="Email"/>';
|
||||
form.innerHTML += '<input type="text" name="fname" id="fname" value="" placeholder="First Name"/>';
|
||||
form.innerHTML += '<input type="text" name="lname" id="lname" value="" placeholder="Last Name"/>';
|
||||
form.innerHTML += '<input type="tel" name="tel" id="tel" value="" placeholder="Phone Number"/>';
|
||||
form.innerHTML += '<input type="password" name="password" id="password" value="" placeholder="Password"/>';
|
||||
form.innerHTML += '<input type="button" onClick="signup()" value="Sign up"/>';
|
||||
form.action = "";
|
||||
btn.innerHTML = '<p>Ready have account? <a id="btnLogin" onclick="loginForm()">Login</a></p>';
|
||||
window.history.pushState("", "", 'signup');
|
||||
}
|
||||
|
||||
function loginForm(){
|
||||
document.getElementById("signupform").id = "loginform";
|
||||
document.getElementById("loginform").innerHTML = defaultForm;
|
||||
document.getElementsByClassName("signup")[0].innerHTML = defaultButton;
|
||||
window.history.pushState("", "", 'index');
|
||||
}
|
||||
|
||||
function signup(){
|
||||
console.log("sign")
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
|
||||
function profilePassword(){
|
||||
var currentPassword = document.getElementById("currentPassword").value;
|
||||
var password = document.getElementById("password").value;
|
||||
var cfmPassword = document.getElementById("cfmPassword").value;
|
||||
var vaild = true;
|
||||
if(currentPassword != "" ){
|
||||
|
||||
if(password != cfmPassword){
|
||||
document.getElementsByClassName("message")[0].innerHTML = '<div class="bs-callout bs-callout-danger"><h4>Password Incorrect</h4>Confirm password and new password not match</div>';
|
||||
vaild = false;
|
||||
}else if(password == ""){
|
||||
document.getElementsByClassName("message")[0].innerHTML = '<div class="bs-callout bs-callout-danger"><h4>Password Incorrect</h4>You need to input new password</div>';
|
||||
vaild = false;
|
||||
}
|
||||
}
|
||||
if(currentPassword == "" && (password != "" || cfmPassword != "")){
|
||||
document.getElementsByClassName("message")[0].innerHTML = '<div class="bs-callout bs-callout-danger"><h4>Input Password</h4>Please input the current password</div>';
|
||||
vaild = false;
|
||||
}
|
||||
|
||||
var fname = document.getElementById("fname").value;
|
||||
var lname = document.getElementById("lname").value;
|
||||
var tel = document.getElementById("tel").value;
|
||||
|
||||
if(fname == "" || lname == "" || tel == ""){
|
||||
document.getElementsByClassName("message")[0].innerHTML += '<div class="bs-callout bs-callout-danger"><h4>Information Missing</h4>Please input all required information</div>';
|
||||
}else if (vaild){
|
||||
document.getElementById("updateprofile").submit();
|
||||
}
|
||||
}
|
||||
|
||||
function deleteAccount(){
|
||||
var deletePwd = document.getElementById("deletePassword").value;
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = "checking";
|
||||
xhr.open("POST", url, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
var json = JSON.parse(xhr.responseText);
|
||||
if(json.statue == true){
|
||||
location.replace("logout");
|
||||
}else{
|
||||
console.log("test");
|
||||
document.getElementsByClassName("modal-message")[0].innerHTML = '<div class="bs-callout bs-callout-danger"><h4>Password Incorrect</h4></div>';
|
||||
}
|
||||
}
|
||||
};
|
||||
var data = JSON.stringify({"password": deletePwd});
|
||||
xhr.send(data);
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
function checkQty(id){
|
||||
var qty = document.getElementById(id).value;
|
||||
if(qty <= 0){
|
||||
document.getElementById(id).value = 1;
|
||||
document.getElementsByClassName('message')[0].innerHTML = '<div class="bs-callout bs-callout-danger"><h4>Error Callout</h4>Product quantity must not small than 1</div>';
|
||||
|
||||
if(document.getElementsByClassName("payment-button")[0] != null){
|
||||
console.log("test")
|
||||
document.getElementsByClassName("payment-button")[0].childNodes[1].childNodes[0].style.marginTop = "66px";
|
||||
}
|
||||
}else{
|
||||
document.getElementsByClassName('message')[0].innerHTML = "";
|
||||
if(document.getElementsByClassName("payment-button")[0] != null){
|
||||
console.log("test")
|
||||
document.getElementsByClassName("payment-button")[0].childNodes[1].childNodes[0].style.marginTop = "135px";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function addToCart(storeId, productId){
|
||||
var cartElemt = document.getElementById("cart");
|
||||
var productQty = document.getElementById(storeId + "-" + productId).value;
|
||||
|
||||
console.log("test1");
|
||||
console.log("test");
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = "addToCart";
|
||||
xhr.open("POST", url, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
var json = JSON.parse(xhr.responseText);
|
||||
if(json.statue == true){
|
||||
let index = 0;
|
||||
var elemt = document.getElementsByTagName("ol")[0];
|
||||
for(var i = 0; i < elemt.childElementCount; i++){
|
||||
if(i == index){
|
||||
console.log("index" + i);
|
||||
if (cartElemt != null){
|
||||
document.getElementsByClassName("item-count")[0].innerHTML = json.itemCount;
|
||||
}else{
|
||||
console.log("bot");
|
||||
elemt.children[i].innerHTML += '<li id="cart"><a href="cart" class="selected"><span><div class="item-count">' + json.itemCount +'</div> Cart</span></a></li>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
console.log(storeId + " " + productId + " " + productQty);
|
||||
var data = JSON.stringify({"storeId": storeId, "productId": productId, "qty": productQty});
|
||||
xhr.send(data);
|
||||
}
|
||||
|
||||
function removeInCart(productId){
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = "removeInCart";
|
||||
xhr.open("POST", url, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
var json = JSON.parse(xhr.responseText);
|
||||
var message = document.getElementsByClassName("message")[0].innerHTML;
|
||||
if(json.statue && json.itemCount < 1){
|
||||
location.replace("home?cart");
|
||||
}else if(json.statue){
|
||||
location.reload();
|
||||
}else{
|
||||
message = '<div class="bs-callout bs-callout-danger"><h4>System Error</h4>Remove Item Fail</div>';
|
||||
}
|
||||
}
|
||||
};
|
||||
var data = JSON.stringify({"productId": productId});
|
||||
xhr.send(data);
|
||||
}
|
Reference in New Issue
Block a user