Procházet zdrojové kódy

Remove frontend validator. Update the banner.

Lee Morgan před 5 roky
rodič
revize
20491fdfb4

+ 0 - 1
views/landingPage/landing.ejs

@@ -121,7 +121,6 @@
             let error = <%- JSON.stringify(error) %>;
             let isLoggedIn = <%- JSON.stringify(isLoggedIn) %>;
         </script>
-        <script src="../shared/validation.js"></script>
         <script src="/landingPage/public.js"></script>
         <script src="/landingPage/login.js"></script>
         <script src="/landingPage/register.js"></script>

+ 5 - 6
views/landingPage/register.js

@@ -20,6 +20,7 @@ let registerObj = {
 
     submit: function(){
         event.preventDefault();
+        console.log("something");
 
         let form = document.querySelector("#registerStrand form");
         let checkbox = document.getElementById("checkAgree");
@@ -37,12 +38,10 @@ let registerObj = {
         }
 
         if(checkbox.checked){
-            if(validator.isSanitary(document.getElementById("regName").value)){
-                document.getElementById("loaderContainer").style.display = "flex";
-                form.action = "merchant/create/none";
-                form.method = "post";
-                form.submit();
-            }
+            document.getElementById("loaderContainer").style.display = "flex";
+            form.action = "merchant/create/none";
+            form.method = "post";
+            form.submit();
         }else{
             banner.createError("Please agree to the Privacy Policy and Terms and Conditions to continue");
         }

+ 13 - 35
views/shared/banner.ejs

@@ -1,6 +1,4 @@
-<div class="banner">
-    <ul></ul>
-</div>
+<div id="banner" class="banner"></div>
 
 <script>
     let banner = {
@@ -8,49 +6,29 @@
         notificationList: [],
 
         createNotification: function(value){
-            this.notificationList.push(value);
+            let banner = document.getElementById("banner");
+            banner.style.display = "flex";
+            banner.innerText = value;
+            banner.classList.add("notification");
 
-            this.updateNotifications();
 
             setTimeout(()=>{
-                this.notificationList.splice(0, 1);
-                this.updateNotifications();
+                banner.style.display = "none";
+                banner.classList.remove("notification");
             }, 10000);
         },
 
         createError: function(value){
-            this.errorList.push(value);
+            let banner = document.getElementById("banner");
+            banner.style.display = "flex";
+            banner.innerText = value;
+            banner.classList.add("error");
 
-            this.updateNotifications();
 
             setTimeout(()=>{
-                this.errorList.splice(0, 1);
-                this.updateNotifications();
+                banner.style.display = "none";
+                banner.classList.remove("notification");
             }, 10000);
-        },
-
-        updateNotifications: function(){
-            let banner = document.querySelector(".banner");
-            let ul = document.querySelector(".banner ul");
-
-            while(ul.hasChildNodes()){
-                ul.removeChild(ul.firstChild);
-            }
-
-            for(let i = 0; i < this.notificationList.length; i++){
-                let li = document.createElement("li");                                                                       
-                                                                                                            
-                li.classList = "notification";
-                li.innerText = this.notificationList[i];
-                ul.appendChild(li);
-            }
-
-            for(let i = 0; i < this.errorList.length; i++){
-                let li = document.createElement("li");
-                li.classList = "error";
-                li.innerText = this.errorList[i];
-                ul.appendChild(li);
-            }
         }
     }
 </script>

+ 4 - 10
views/shared/shared.css

@@ -272,26 +272,20 @@ form{
 
 /* Banner partial */
 .banner{
+    justify-content: center;
     width: 100%;
-    text-align: center;
-    list-style-type: none;
     font-size: 20px;
     color: white;
-    z-index: -10;
     position: absolute;
-    border-radius: 5px;
+    padding: 5px;
 }
 
-    .banner .notification{
+    .notification{
         background: rgba(1, 140, 15, 0.75);
-        list-style-type: none;
-        padding: 5px;
     }
 
-    .banner .error{
+    .error{
         background: rgba(255, 0, 0, 0.75);
-        list-style-type: none;
-        padding: 5px;
     }
 
 /* Footer Partial */

+ 0 - 213
views/shared/validation.js

@@ -1,213 +0,0 @@
-let validator = {
-    /*
-    ingredient = {
-        ingredient: {
-            name: name of ingredient,
-            category: category of ingredient,
-            unit: unit measure for ingredient
-        },
-        quantity: quantity of ingredient for current merchant
-    }
-    */
-    ingredient: function(ingredient, createBanner = true){
-        let errors = [];
-        if(!this.isSanitary(ingredient.ingredient.name) ||
-        !this.isSanitary(ingredient.ingredient.category) ||
-        !this.isSanitary(ingredient.ingredient.unit)){
-            errors.push("Contains illegal characters");
-        }
-
-        if(isNaN(ingredient.quantity) || ingredient.quantity === ""){
-            errors.push("Must enter a valid number");
-        }
-
-        if(ingredient.quantity < 0){
-            banner.createError("Quantity cannot be a negative number");
-        }
-
-        if(errors.length > 0){
-            if(createBanner){
-                for(let i = 0; i < errors.length; i++){
-                    banner.createError(errors[i]);
-                }
-            }
-
-            return false;
-        }
-
-        return true;
-    },
-
-    ingredientQuantity: function(quantity, createBanner = true){
-        let errors = [];
-
-        if(isNaN(quantity) || quantity === ""){
-            errors.push("Must enter a valid number");
-        }
-
-        if(quantity < 0){
-            banner.createError("Quantity cannot be a negative number");
-        }
-
-        if(errors.length > 0){
-            if(createBanner){
-                for(let i = 0; i < errors.length; i++){
-                    banner.createError(errors[i]);
-                }
-            }
-
-            return false;
-        }
-
-        return true;
-    },
-
-    merchant: {
-        password: function(pass, confirmPass, createBanner = true){
-            if(pass !== confirmPass){
-                if(createBanner){
-                    banner.createError("Your passwords do not match");
-                }
-                return false;
-            }
-
-            if(pass.length < 15){
-                if(createBanner){
-                    banner.createError("Your password must contain at least 15 characters");
-                }
-                return false;
-            }
-
-            return true;
-        }
-    },
-
-    transaction: {
-        date: function(from, to = new Date(), createBanner = true){
-            let errors = [];
-            let today = new Date();
-
-            if(from > to){
-                errors.push("Starting date must be before ending date");
-            }
-
-            if(from > today || to > today.setDate(today.getDate() + 1)){
-                errors.push("Cannot choose a date in the future");
-            }
-
-            if(errors.length > 0){
-                if(createBanner){
-                    for(let i = 0; i < errors.length; i++){
-                        banner.createError(errors[i]);
-                    }
-
-                    return false;
-                }
-            }
-
-            return true;
-        }
-    },
-
-    recipe: function(newRecipe, createBanner = true){
-        let errors = [];
-
-        if(!validator.isSanitary(newRecipe.name)){
-            errors.push("Name contains invalid characters");
-        }
-
-        if(newRecipe.price < 0){
-            errors.push("Price must contain a non-negative number");
-        }
-
-        if(newRecipe.ingredients.length === 0){
-            errors.push("Must include at least one ingredient");
-        }
-
-        let checkSet = new Set();
-        for(let i = 0; i < newRecipe.ingredients.length; i++){
-            if(newRecipe.ingredients[i].quantity < 0){
-                errors.push("Quantity must contain a non-negative number");
-                break;
-            }
-
-            checkSet.add(newRecipe.ingredients[i].ingredient);
-        }
-
-        if(checkSet.size !== newRecipe.ingredients.length){
-            errors.push("Recipe contains duplicate ingredients");
-        }
-
-        if(isNaN(newRecipe.price) || newRecipe.price === "" || newRecipe.price< 0){
-            errors.push("Must enter a valid price");
-        }
-
-        if(errors.length > 0){
-            if(createBanner){
-                for(let i = 0; i < errors.length; i++){
-                    banner.createError(errors[i]);
-                }
-
-                return false;
-            }
-        }
-
-        return true;
-    },
-
-    order: function(order, createBanner = true){
-        let errors = [];
-
-        if(!validator.isSanitary(order.name, false)){
-            errors.push("Your string contains illegal characters");
-        }
-
-        let now = new Date()
-        if(order.date > now){
-            errors.push("Cannot have a date/time in the future");
-        }
-
-        for(let i = 0; i < order.ingredients.length; i++){
-            if(order.ingredients[i].quantity < 0){
-                errors.push("Quantity cannot be negative");
-                break;
-            }
-
-            if(order.ingredients[i].price < 0){
-                errors.push("Price cannot be negative");
-                break;
-            }
-
-            if(order.ingredients[i].price === "" || order.ingredients[i].quantity === ""){
-                errors.push("Incomplete information");
-            }
-        }
-
-        if(errors.length > 0){
-            if(createBanner){
-                for(let i = 0; i < errors.length; i++){
-                    banner.createError(errors[i]);
-                }
-            }
-
-            return false;
-        }
-
-        return true;
-    },
-
-    isSanitary: function(str, createBanner = true){
-        let disallowed = ["\\", "<", ">", "$", "{", "}", "(", ")"];
-
-        for(let i = 0; i < disallowed.length; i++){
-            if(str.includes(disallowed[i])){
-                if(createBanner){
-                    banner.createError("Your string contains illegal characters");
-                }
-                return false;
-            }
-        }
-
-        return true;
-    }
-}