$(document).ready(function() { $.ajaxSetup({ cache: false }); var time =4; $.LoadFav = function(){ $("#navBookMark").click(function(){ $("#favModal").html(""); $("#modal_box").html(""); $("#modal_box").html(""); $.getJSON("jsonDB/"+sessionStorage.getItem("username")+".json", function(obj){ try{ $.getJSON("jsonDB/restaurants.json", function(result){ for(var i=0; i
  • "+name.name+"

    delete
  • "); $.deleteFav(); $.each(name.tag, function(tagIndex, tagName){ $("#favTag"+obj.favorite[i]).append("
    " + tagName + "
    "); }); } }); }); //}); }catch(err){ console.log("NOT Thing here"); } }); }); } $.deleteFav = function(){ $(".deleteFav").click(function(){ var favVal = $(this).attr("id").substring(6,7); $.getJSON("jsonDB/"+sessionStorage.getItem("username")+".json", function(obj){ $.each(obj.favorite, function(favIndex, favName){ if(favVal == favName){ obj.favorite.splice(favIndex, 1); console.log(obj); $.ajax({ url: "jsonDB/update.php", type: "POST", async: false, cache: false, dataType: "json", data: {dataCus: JSON.stringify(obj), dataEmail: sessionStorage.getItem("username"), fav: 1} }); $("#delcollFav"+favVal).effect("slide"); $("#delcollFav"+favVal).html(""); } console.log() $("#fav"+favVal).html("favorite"); }); }); }); } $.windowsChecksize = function() { var winWidth = $(window).width(); console.log(sessionStorage.getItem("rule")); if (winWidth < 943) { if(sessionStorage.getItem("username")){ $("nav .right").html("
  • account_circle
  • "); }else{ $("nav .right").html("
  • account_circle
  • "); } } else { if(sessionStorage.getItem("username")){ $("nav .right").html("
  • "); }else{ $("nav .right").html("
  • account_circleLogin
  • "); } } if(sessionStorage.getItem("username")){ $("#slide-out").html(""); $("#modal_box").addClass("modal"); $("#modal_box").html(""); $("#favModal").html(""); $('.sidenav').sidenav(); if(sessionStorage.getItem("rule")=="operator"){ $("#slide-out").append("
  • peopleRestaurant Management
  • settingsPersonal Information
  • Log Out
  • "); }else if (sessionStorage.getItem("rule")=="admin"){ $("#slide-out").append("
  • peopleUser Management
  • settingsPersonal Information
  • Log Out
  • "); }else{ $("#slide-out").append("
  • bookmarkfavorite restaurant
  • settingsPersonal Information
  • Log Out
  • "); } $("#navName").append(sessionStorage.getItem("name")); $("#navEmail").append(sessionStorage.getItem("username")); $("#navLogout").click(function(){ sessionStorage.removeItem("username"); sessionStorage.removeItem("name"); window.location.replace("index.html"); }); $("#modal_box").html(""); $.LoadFav(); } $("#btnLogin").click(function() { $('#modal1').modal('open'); }); } $.getRestanauent = function(){ $.getJSON("jsonDB/restaurants.json", function(result) { $.each(result.restaurants, function(index, name) { var count = 0, rate = 0; $.each(result.commRestaurants, function(comIndex, comName) { if (name.id == comName.resID) { rate += comName.rate; count++; } }); rate /= count; if (isNaN(rate)) rate = "Not a comment"; else rate = "Rate: " + rate + "/5.0"; $("#menu").append("
    " + name.name + "

    " + rate + "

    "); $.each(name.tag, function(tagIndex, tagName) { $("#" + name.id).append("
    " + tagName + "
    "); }); if(sessionStorage.getItem("username")){ $.getJSON("jsonDB/"+sessionStorage.getItem("username")+".json", function(obj){ var seaVaild = false; $.each(obj.favorite, function(seaFavIndex, seaFavName){ if(seaFavName == name.id){ seaVaild = true; $("#fav"+name.id).append("delete"); } }); if(!seaVaild) $("#fav"+name.id).append("favorite"); }); }else{ $("#fav"+name.id).append("favorite"); } }); var foodText = GetURLParameter('food'); if(typeof foodText!="undefined"){ $(".searchRest").hide().filter(":contains('" + foodText + "')").show(); if($(".searchRest:hidden").length >= $(".searchRest").length){ $("#searchMessage").html("

    Sorry, not found about "+ foodText+ " Restanauent. Click Here to see All Restanauent

    '"); } } if(!sessionStorage.getItem("username")){ $(".searchRest a").attr("href", "#"); $(".searchRest a").click(function(){ $("#btnLoginNavli a").click(); }); }else{ $.clickFav(); } }); } $.clickFav = function(){ $(".fav").click(function(){ if(sessionStorage.getItem("username")){ var favVal = $(this).attr("id").substring(3,4); var vaild = false; $.getJSON("jsonDB/"+sessionStorage.getItem("username")+".json", function(obj){ $.each(obj.favorite, function(favIndex, favName){ if(favVal == favName){ vaild = true; obj.favorite.splice(favIndex, 1); $("#fav"+favVal).html("favorite"); } }); if(!vaild){ obj.favorite.push(favVal); console.log(obj); $("#fav"+favVal).html("delete"); } $.ajax({ url: "jsonDB/update.php", type: "POST", async: false, cache: false, dataType: "json", data: {dataCus: JSON.stringify(obj), dataEmail: sessionStorage.getItem("username"), fav: 1}, }); }); }else{ $("#btnLoginNavli a").click(); } }); } $("#createInfo").hide(); $("#createAccount").click(function() { $("#loginInfo").hide(); $("#createInfo").show(); }); $("#loginAccount").click(function() { $("#createInfo").hide(); $("#loginInfo").show(); }); $(window).resize(function() { $.windowsChecksize(); }); //$("#btnFBLogin").click(function(){ // //}); $("#btnSubmitLogin").click(function() { $("#loginAlert").html(""); var loginPwd = $("#loginPwd").val(); var loginEmail = $("#loginEmail").val(); if(loginEmail=="" && loginPwd==""){ $("#loginAlert").append("
    The Email and password is required!
    "); }else if(loginEmail==""){ $("#loginAlert").append("
    Missing the Email Address
    "); }else if(loginPwd==""){ $("#loginAlert").append("
    Missing the Password
    "); }else{ var valid = true; $.getJSON("jsonDB/adminCustomer.json",function(result){ $.each(result.customers, function(index, name){ if(name.email==loginEmail && name.pwd!=loginPwd){ valid = false; $("#loginAlert").append("
    Your Password is Worng.
    "); }else if(name.email==loginEmail && name.pwd==loginPwd){ //$("#navIcon").attr("src", name.icon); $("#loginAlert").html(""); valid = false; sessionStorage.setItem("username", name.email); sessionStorage.setItem("name", name.fname+ " " + name.lname); sessionStorage.setItem("rule", name.rule); if(sessionStorage.getItem("rule")=="operator") window.location.replace("operatorIndex.html"); else if(sessionStorage.getItem("rule")=="admin") window.location.replace("admin.html"); else{ location.reload(); } valid = false; } }); if(valid) $("#loginAlert").append("
    Your Email or Password is Worng!
    "); $("#loginAlert").effect("shake"); }); } }); $("#btnSubmitRegister").click(function(){ $("#pwdAlert").html(""); var pwd = $("#regPassword").val(); var pwdCheck = $("#checkPassword").val(); var email = $("#regEmail").val(); var fname = $("#first_name").val(); var lname = $("#last_name").val(); var btnVal = $("#btnSubmitRegister").text(); var valid = false; if(pwd=="" && pwdCheck=="" && email=="" && fname=="" && lname==""){ $("#pwdAlert").append("
    You need input the all field!
    "); valid = true; $("#pwdAlert").effect("shake"); return 0; } if(email==""){ $("#pwdAlert").append("
    You need input the Email address
    "); valid = true; $("#pwdAlert").effect("shake"); } else if(!IsEmail(email)){ $("#pwdAlert").append("
    Please check your email format
    "); valid = true; $("#pwdAlert").effect("shake"); } if(pwd==""||pwdCheck==""){ $("#pwdAlert").append("
    Missing Password
    "); valid = true; $("#pwdAlert").effect("shake"); } if(fname=="" || lname==""){ $("#pwdAlert").append("
    Name is required
    "); valid = true; $("#pwdAlert").effect("shake"); } $.getJSON("jsonDB/adminCustomer.json", function(obj){ $.each(obj.customers, function(index,name){ if(name.email == email){ $("#pwdAlert").append("
    Your Email Registed!
    "); valid = true; $("#pwdAlert").effect("shake"); } }); }); if(pwd != pwdCheck){ $("#pwdAlert").append("
    Your Comfirm Password Not Match!
    "); $("#pwdAlert").effect("shake"); valid = true; } if(!valid){ $.getJSON("jsonDB/adminCustomer.json", function(obj){ var getID = 0; $.each(obj.customers, function(index, name){ if(getID
    Your Account Created.
    "); $("#loginAlert").effect("slide"); if(btnVal == "Add User"){ $(".modal").modal("close"); $("#adminUserTable").html(""); $.getAdminUserInf(); } }); } }); $.checkRestaurantInf = function(){ var name = $("#createRestaurantName").val(); var tel = $("#createRestaureantTel").val(); var address = $("#createRestaureantAdde").val(); var area = $("#createRestaurantSelect").val(); var opTime = $("#createRestaureantOPTime").val(); var clTime = $("#createRestaureantCLTime").val(); var valid = true; $("#stepOneAlert").html(""); if(name=="" && tel=="" && address=="" && area=="" && opTime=="" && clTime==""){ $("#stepOneAlert").append("
    You need input the all field!
    "); valid=false; } if(name==""){ $("#stepOneAlert").append("
    Missing the Restaurant Name
    "); valid=false; } if(tel==""){ $("#stepOneAlert").append("
    Missing the Restaurant Name
    "); valid=false; } if(address==""){ $("#stepOneAlert").append("
    Missing the Restaurant Address
    "); valid=false; } if(clTime==""||opTime==""){ $("#stepOneAlert").append("
    Missing the Restaurant opening hours
    "); valid=false; } if(!valid){ $("#firstStep").addClass("red-text"); }else{ $("#firstStep").removeClass("red-text"); } } $("#btnSubmitUpdate").click(function(){ $("#pwdAlert").html(""); var pwd = $("#regPassword").val(); var pwdCheck = $("#checkPassword").val(); var oldPassword = $("#oldPassword").val(); var email = $("#regEmail").val(); var fname = $("#first_name").val(); var lname = $("#last_name").val(); var btnVal = $("#btnSubmitRegister").text(); var valid = false; if(pwd=="" && pwdCheck=="" && email=="" && fname=="" && lname==""){ $("#pwdAlert").append("
    You need input the all field!
    "); valid = true; $("#pwdAlert").effect("shake"); return 0; } if(email==""){ $("#pwdAlert").append("
    You need input the Email address
    "); valid = true; $("#pwdAlert").effect("shake"); } else if(!IsEmail(email)){ $("#pwdAlert").append("
    Please check your email format
    "); valid = true; $("#pwdAlert").effect("shake"); } if(fname=="" || lname==""){ $("#pwdAlert").append("
    Name is required
    "); valid = true; $("#pwdAlert").effect("shake"); } if(pwd==""||pwdCheck==""){ $("#pwdAlert").append("
    Missing Password
    "); valid = true; $("#pwdAlert").effect("shake"); } if(pwd==pwdCheck){ $.getJSON("jsonDB/"+sessionStorage.getItem("username")+".json", function(obj){ if(obj.pwd!=oldPassword){ console.log(obj.pwd+ " "+ oldPassword); $("#pwdAlert").append("
    Old password not match
    "); valid = true; $("#pwdAlert").effect("shake"); } }); }else{ $("#pwdAlert").append("
    Password not match
    "); valid = true; $("#pwdAlert").effect("shake"); } if(!valid){ $.getJSON("jsonDB/"+sessionStorage.getItem("username")+".json", function(obj){ var info = { "userID": obj.userID, "email": email, "fname": fname, "lname": lname, "pwd": pwdCheck, "user": obj.rule, "favorite":[] } $.each(obj.favorite, function(index, name){ info.favorite.push(name); }); console.log(info); $.ajax({ url: "jsonDB/update.php", type: "POST", async: false, cache: false, dataType: "json", data: {dataCus: JSON.stringify(info), dataEmail: sessionStorage.getItem("username"), fav: 1} }); $("#pwdAlert").html("
    Your Information updated.
    "); $("#pwdAlert").effect("slide"); $("#regPassword").val(""); $("#checkPassword").val(""); $("#oldPassword").val(""); }); } $("#regPassword").val(""); $("#checkPassword").val(""); $("#oldPassword").val(""); }); $("#btnAddCatalog").click(function(){ $("#menuCatAlert").html(""); var cataHidd = $("#catalogHidden").prop("checked"); var catalog = $("#catalog").val(); var cataAllDay = $("#catalogAllDay").prop("checked"); var invalid = true; if(!cataAllDay){ var startTime = $("#catalogTo").val(); var closeTime = $("#catalogCl").val(); }else{ var startTime = "NA"; var closeTime = "NA"; } if(catalog==""){ $("#menuCatAlert").append("
    Please input your catalog
    "); invalid=false; } if(!cataAllDay && startTime=="" && closeTime==""){ $("#menuCatAlert").append("
    Missing the Catalog Time
    "); invalid=false; } if(!invalid){ $("#secondStep i").addClass("red-text"); } if(invalid){ $("#catalogTable").append(""+catalog+""+cataAllDay+""+startTime+""+closeTime+""+cataHidd+"delete repeat"); $("#catalog").val(""); $("#secondStep i").removeClass("red-text"); $(".btnCataChange").click(function(){ var disVal = $(this).parents("tr").children("td:eq(4)").html(); if(disVal=="false"){ $(this).parents("tr").children("td:eq(4)").html("true") ; }else{ $(this).parents("tr").children("td:eq(4)").html("false") ; } }); $(".btnCataDelete").click(function(){ $(this).parents("tr").remove(); }); } }); $("#secondStep").click(function(){ $.checkRestaurantInf(); }); $("#adminAddUser").click(function(){ $("#adminReg").modal("open"); }); $("#filterApply").click(function(){ var filterArray = [] if($("#filterNoodles").prop("checked")){ filterArray.push($("#filterNoodles").val()); } if($("#filterKoeran").prop("checked")){ filterArray.push($("#filterKoeran").val()); } if($("#filterTaiwanese").prop("checked")){ filterArray.push($("#filterTaiwanese").val()); } if($("#filterRice").prop("checked")){ filterArray.push($("#filterRice").val()); } if($("#filterChinese").prop("checked")){ filterArray.push($("#filterChinese").val()); } if($("#filterWestern").prop("checked")){ filterArray.push($("#filterWestern").val()); } if($("#filterDimSum").prop("checked")){ filterArray.push($("#filterDimSum").val()); } if(filterArray.length>0){ var filterText = ":contains('"; for (var i = filterArray.length; i >0; i--) { filterText += filterArray.pop()+"')"; if(filterArray.length>0) filterText+=", :contains('"; } $(".searchRest").hide().filter(filterText).show(); }else{ $(".searchRest").show(); } }); $("#filterClear").click(function(){ var checkboxes = document.getElementsByTagName('input'); for (var i=0; i"+name.userID+""+name.email+""+name.rule+"delete restaurant"); else if(name.rule == "operator"){ $("#adminUserTable").append(""+name.userID+""+name.email+""+name.rule+"delete person"); }else if(name.rule == "admin"){ $("#adminUserTable").append(""+name.userID+""+name.email+""+name.rule+"delete"); } }); $(".btnAdminDelete").click(function(){ var valThis = $(this); $("#modalDelAlertContentMsg").html("

    Do you want to delete "+ valThis.parents("tr").children("td:eq(1)").text() +"

    ") $('#modalDelAlert').modal('open'); $(".modalDelconfirm").click(function(){ valThis.parents("tr").hide(); $("#adminWellcomMesg").html("
    Account deleted
    "); $("#adminWellcomMesg").effect("slide"); }); $(".modalDelClose").click(function(){ $('#modalDelAlert').modal('close'); }); }); $(".btnAdminRest").click(function(){ var value = $(this).parents().children("td:eq(2)").text(); if(value == "user"){ $(this).html("person"); $(this).removeClass("lighten-2"); $(this).removeClass("teal"); $(this).addClass("green"); $(this).addClass("lighten-3"); $(this).parents().children("td:eq(2)").html("operator"); $("#adminWellcomMesg").html("
    Updated the "+$(this).parents().children("td:eq(1)").text()+" to Operator.
    "); $("#adminWellcomMesg").effect("slide"); }else if(value== "operator"){ $(this).html("restaurant"); $(this).addClass("lighten-2"); $(this).addClass("teal"); $(this).removeClass("green"); $(this).removeClass("lighten-3"); $(this).parents().children("td:eq(2)").html("user"); $("#adminWellcomMesg").html("
    Updated the "+$(this).parents().children("td:eq(1)").text()+" to User.
    "); $("#adminWellcomMesg").effect("slide"); } }); $("#adminSearch").keyup(function(){ var adminSearch = $("#adminSearch").val(); $("tr:gt(0)").hide().filter(":contains('" + adminSearch + "')").show(); }); }); } } $.getUserInf = function(){ $.getJSON("jsonDB/"+sessionStorage.getItem("username")+".json", function(obj){ $("#regEmaillable").addClass("active"); $("#last_namelable").addClass("active"); $("#first_namelable").addClass("active"); $("#regEmail").val(obj.email); $("#first_name").val(obj.fname); $("#last_name").val(obj.lname); }); } function btnSave(){ $("#btnMenuSave").click(function(){ var name = $("#createRestaurantName").val(); var tel = $("#createRestaureantTel").val(); var address = $("#createRestaureantAdde").val(); var opTime = $("#createRestaureantOPTime").val(); var clTime = $("#createRestaureantCLTime").val(); var btnMenuSave = $("#btnMenuSave").text(); $("#menuMissing").html(""); console.log(btnMenuSave); var valid = true; if(name==""){ $("#menuMissing").append("Section 1: Restaurant name
    "); valid=false; } if(tel==""){ $("#menuMissing").append("Section 1: Restaurant Telphone
    "); } if(address==""){ $("#menuMissing").append("Section 1: Restaurant Address
    "); valid=false; } if(clTime==""||opTime==""){ $("#menuMissing").append("Section 1: Restaurant Open and close time
    "); valid=false; } if(address=="" || tel=="" || name=="" || clTime==""||opTime==""){ $("#firstStep").addClass("red-text"); } if($("#catalogTable tr").length<2){ $("#menuMissing").append("Section 2: The Restaurant catalog
    "); valid=false; $("#secondStep").addClass("red-text"); } if($("#resturantMenu tr").length<2){ $("#menuMissing").append("Section 3: The Restaurant food
    "); valid=false; $("#stepThrid").addClass("red-text"); } console.log(valid+" && " + btnMenuSave); if(valid && btnMenuSave=="Create"){ var restName = $("#createRestaurantName").val(); $("#restaurantMenu").append(""); time++; $('.dropdown-trigger').dropdown(); $("#menuAlert").html(""); $("#menuMissing").siblings().html("System Message:"); $("#menuMissing").html("
    Saved
    "); $("#stepOneAlert").html(""); $("#menuCatAlert").html(""); $("#secondStep").removeClass("red-text"); $("#firstStep").removeClass("red-text"); $("#stepThrid").removeClass("red-text"); $("#createRestaurantName").val(""); $("#createRestaureantTel").val(""); $("#createRestaureantAdde").val(""); $("#createRestaurantSelect").val(""); $("#createRestaureantOPTime").val(""); $("#createRestaureantCLTime").val(""); $("#menuFoodName").val(""); $("#menuFoodPrice").val(""); if( $("#menuMissing").text()=="Saved"){ $("#alertClose").click(function(){ $('.modal').modal('close'); }); } $("#menuCatalog").html(""); $("#catalogTable").html("Catalog NameAll DayStart TimeClose TimeHiddenAction"); $("#resturantMenu").html("Food NameCatalogPriceDisplayAction"); $(".restDel").click(function(){ var restDel = $(this).parents(".col"); $(this).addClass("modal-trigger"); $("#wraningAlert").html('Do you want to delete " '+$(this).parents(".card-content").children().first().text()+'", you cannot recovery deleted menu.'); $("#closeMenu").click(function(){ restDel.hide(); }); }); }else if(valid && btnMenuSave =="SAVE"){ $("#menuMissing").siblings().html("System Message:"); $("#menuMissing").html("
    Saved
    "); if( $("#menuMissing").text()=="Saved"){ $("#alertClose").click(function(){ $('#createRest').modal('close'); $("#alert").modal("close"); }); } } }); } function GetURLParameter(sParam) { var sPageURL = window.location.search.substring(1); var sURLVariables = sPageURL.split('&'); for (var i = 0; i < sURLVariables.length; i++) { var sParameterName = sURLVariables[i].split('='); if (sParameterName[0] == sParam) return sParameterName[1]; } } function IsEmail(email) { var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if(!regex.test(email)) { return false; }else{ return true; } } btnSave(); $.deleteFav(); $.clickFav(); $.windowsChecksize(); $('.chips-placeholder').chips({ placeholder: 'The Food tag', secondaryPlaceholder: '+Tag', }); $('.parallax').parallax(); $('.modal').modal(); $('.collapsible').collapsible(); $('select').formSelect(); $('.tabs').tabs(); $('#createRestaurantSelect').formSelect(); });