Explorar o código

Update controller functions everywhere that they are used

Lee Morgan %!s(int64=6) %!d(string=hai) anos
pai
achega
bf2cc29fa2

+ 9 - 22
views/dashboardPage/bundle.js

@@ -606,7 +606,7 @@ module.exports = {
         }
 
         document.getElementById("addIngredientsBtn").onclick = ()=>{this.submit()};
-        document.getElementById("openNewIngredient").onclick = ()=>{AbortController.openSidebar("newIngredient")};
+        document.getElementById("openNewIngredient").onclick = ()=>{controller.openSidebar("newIngredient")};
     },
 
     toggleAddIngredient: function(categoryElement){
@@ -897,13 +897,13 @@ controller = {
     openMenu: function(){
         document.getElementById("menu").style.display = "flex";
         document.querySelector(".contentBlock").style.display = "none";
-        document.getElementById("mobileMenuSelector").onclick = ()=>{closeMenu()};
+        document.getElementById("mobileMenuSelector").onclick = ()=>{this.closeMenu()};
     },
 
     closeMenu: function(){
         document.getElementById("menu").style.display = "none";
         document.querySelector(".contentBlock").style.display = "flex";
-        document.getElementById("mobileMenuSelector").onclick = ()=>{openMenu()};
+        document.getElementById("mobileMenuSelector").onclick = ()=>{this.openMenu()};
     },
 
     convertToMain: function(unit, quantity){
@@ -971,7 +971,7 @@ controller = {
 }
 
 if(window.screen.availWidth > 1000 && window.screen.availWidth <= 1400){
-    changeMenu();
+    this.changeMenu();
     document.getElementById("menuShifter2").style.display = "none";
 }
 
@@ -1522,8 +1522,6 @@ module.exports = {
 },{}],10:[function(require,module,exports){
 module.exports = {
     display: function(){
-        openSidebar(document.querySelector("#newIngredient"));
-
         document.querySelector("#newIngName").value = "";
         document.querySelector("#newIngCategory").value = "";
         document.querySelector("#newIngQuantity").value = 0;
@@ -1541,7 +1539,7 @@ module.exports = {
                 category: document.getElementById("newIngCategory").value,
                 unitType: options[unitSelector.selectedIndex].getAttribute("type"),
             },
-            quantity: convertToMain(unit, document.querySelector("#newIngQuantity").value),
+            quantity: controller.convertToMain(unit, document.querySelector("#newIngQuantity").value),
             defaultUnit: unit
         }
 
@@ -1619,8 +1617,6 @@ module.exports = {
 
             this.isPopulated = true;
         }
-
-        openSidebar(document.querySelector("#newOrder"));
     },
 
     addOne: function(ingredientDiv, container){
@@ -1676,7 +1672,7 @@ module.exports = {
             if(quantity !== ""  && price !== ""){
                 ingredients.push({
                     ingredient: categoriesList.children[i].ingredient.id,
-                    quantity: convertToMain(categoriesList.children[i].ingredient.unit, parseFloat(quantity)),
+                    quantity: controller.convertToMain(categoriesList.children[i].ingredient.unit, parseFloat(quantity)),
                     price: categoriesList.children[i].ingredient.convert(parseInt(price * 100))
                 });
             }
@@ -1748,8 +1744,6 @@ module.exports = {
                 optgroup.appendChild(option);
             }
         }
-
-        openSidebar(document.querySelector("#addRecipe"));
     },
 
     //Updates the number of ingredient inputs displayed for new recipes
@@ -1793,7 +1787,7 @@ module.exports = {
                 if(merchant.ingredients[j].ingredient.id === inputs[i].children[1].children[0].value){
                     newRecipe.ingredients.push({
                         ingredient: inputs[i].children[1].children[0].value,
-                        quantity: convertToMain(merchant.ingredients[j].ingredient.unit, inputs[i].children[2].children[0].value)
+                        quantity: controller.convertToMain(merchant.ingredients[j].ingredient.unit, inputs[i].children[2].children[0].value)
                     });
 
                     break;
@@ -1857,8 +1851,6 @@ module.exports = {
 
             recipeDiv.children[0].innerText = merchant.recipes[i].name;
         }
-
-        openSidebar(document.getElementById("newTransaction"));
     },
 
     submit: function(){
@@ -1926,8 +1918,6 @@ module.exports = {
 },{}],14:[function(require,module,exports){
 module.exports = {
     display: function(order){
-        openSidebar(document.querySelector("#orderDetails"));
-
         document.querySelector("#removeOrderBtn").onclick = ()=>{this.remove(order)};
 
         document.getElementById("orderDetailName").innerText = order.name;
@@ -2285,7 +2275,6 @@ module.exports = {
 
     display: function(recipe){
         this.recipe = recipe;
-        openSidebar(document.querySelector("#recipeDetails"));
 
         document.querySelector("#recipeName").style.display = "block";
         document.querySelector("#recipeNameIn").style.display = "none";
@@ -2359,12 +2348,12 @@ module.exports = {
                 let select = divs[i].children[0];
                 this.recipe.ingredients.push({
                     ingredient: select.options[select.selectedIndex].ingredient,
-                    quantity: convertToMain(select.options[select.selectedIndex].ingredient.unit, divs[i].children[1].value)
+                    quantity: controller.convertToMain(select.options[select.selectedIndex].ingredient.unit, divs[i].children[1].value)
                 });
             }else{
                 this.recipe.ingredients.push({
                     ingredient: divs[i].ingredient,
-                    quantity: convertToMain(divs[i].ingredient.unit, divs[i].children[1].value)
+                    quantity: controller.convertToMain(divs[i].ingredient.unit, divs[i].children[1].value)
                 });
             }
         }
@@ -2486,8 +2475,6 @@ module.exports = {
         document.getElementById("transactionTime").innerText = transaction.date.toLocaleTimeString();
         document.getElementById("totalRecipes").innerText = `${totalRecipes} recipes`;
         document.getElementById("totalPrice").innerText = `$${(totalPrice / 100).toFixed(2)}`;
-
-        openSidebar(document.getElementById("transactionDetails"));
     },
 
     remove: function(){

+ 4 - 4
views/dashboardPage/dashboard.ejs

@@ -18,7 +18,7 @@
                     <p>THE SUBLINE</p>
                 </a>
         
-                <button class="menuShifter" onclick="changeMenu()">&#8801;</button>
+                <button class="menuShifter" onclick="controller.changeMenu()">&#8801;</button>
             </div>
         
             <div id="min" class="menuHead menuHeadMin">
@@ -26,7 +26,7 @@
                     <img class="menuLogoMin" src="/shared/images/logo.png" alt="The Subline">
                 </a>
         
-                <button id="menuShifter2" onclick="changeMenu()">&#8801;</button>
+                <button id="menuShifter2" onclick="controller.changeMenu()">&#8801;</button>
             </div>
         
             <button class="menuButton active" id="homeBtn" class="active" onclick="controller.openStrand('home')">
@@ -81,8 +81,8 @@
             </a>
         </div>
 
-        <div id="mobileMenuSelector" class="mobileMenuSelector" onclick="openMenu()">&#8801;</div>
-        <button id="sidebarCloser" style="display: none;" onclick="closeSidebar()">
+        <div id="mobileMenuSelector" class="mobileMenuSelector" onclick="controller.openMenu()">&#8801;</div>
+        <button id="sidebarCloser" style="display: none;" onclick="controller.closeSidebar()">
             <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                 <line x1="18" y1="6" x2="6" y2="18"></line>
                 <line x1="6" y1="6" x2="18" y2="18"></line>

+ 1 - 1
views/dashboardPage/js/addIngredients.js

@@ -84,7 +84,7 @@ module.exports = {
         }
 
         document.getElementById("addIngredientsBtn").onclick = ()=>{this.submit()};
-        document.getElementById("openNewIngredient").onclick = ()=>{AbortController.openSidebar("newIngredient")};
+        document.getElementById("openNewIngredient").onclick = ()=>{controller.openSidebar("newIngredient")};
     },
 
     toggleAddIngredient: function(categoryElement){

+ 3 - 3
views/dashboardPage/js/dashboard.js

@@ -144,13 +144,13 @@ controller = {
     openMenu: function(){
         document.getElementById("menu").style.display = "flex";
         document.querySelector(".contentBlock").style.display = "none";
-        document.getElementById("mobileMenuSelector").onclick = ()=>{closeMenu()};
+        document.getElementById("mobileMenuSelector").onclick = ()=>{this.closeMenu()};
     },
 
     closeMenu: function(){
         document.getElementById("menu").style.display = "none";
         document.querySelector(".contentBlock").style.display = "flex";
-        document.getElementById("mobileMenuSelector").onclick = ()=>{openMenu()};
+        document.getElementById("mobileMenuSelector").onclick = ()=>{this.openMenu()};
     },
 
     convertToMain: function(unit, quantity){
@@ -218,7 +218,7 @@ controller = {
 }
 
 if(window.screen.availWidth > 1000 && window.screen.availWidth <= 1400){
-    changeMenu();
+    this.changeMenu();
     document.getElementById("menuShifter2").style.display = "none";
 }
 

+ 1 - 3
views/dashboardPage/js/newIngredient.js

@@ -1,7 +1,5 @@
 module.exports = {
     display: function(){
-        openSidebar(document.querySelector("#newIngredient"));
-
         document.querySelector("#newIngName").value = "";
         document.querySelector("#newIngCategory").value = "";
         document.querySelector("#newIngQuantity").value = 0;
@@ -19,7 +17,7 @@ module.exports = {
                 category: document.getElementById("newIngCategory").value,
                 unitType: options[unitSelector.selectedIndex].getAttribute("type"),
             },
-            quantity: convertToMain(unit, document.querySelector("#newIngQuantity").value),
+            quantity: controller.convertToMain(unit, document.querySelector("#newIngQuantity").value),
             defaultUnit: unit
         }
 

+ 1 - 3
views/dashboardPage/js/newOrder.js

@@ -33,8 +33,6 @@ module.exports = {
 
             this.isPopulated = true;
         }
-
-        openSidebar(document.querySelector("#newOrder"));
     },
 
     addOne: function(ingredientDiv, container){
@@ -90,7 +88,7 @@ module.exports = {
             if(quantity !== ""  && price !== ""){
                 ingredients.push({
                     ingredient: categoriesList.children[i].ingredient.id,
-                    quantity: convertToMain(categoriesList.children[i].ingredient.unit, parseFloat(quantity)),
+                    quantity: controller.convertToMain(categoriesList.children[i].ingredient.unit, parseFloat(quantity)),
                     price: categoriesList.children[i].ingredient.convert(parseInt(price * 100))
                 });
             }

+ 1 - 3
views/dashboardPage/js/newRecipe.js

@@ -19,8 +19,6 @@ module.exports = {
                 optgroup.appendChild(option);
             }
         }
-
-        openSidebar(document.querySelector("#addRecipe"));
     },
 
     //Updates the number of ingredient inputs displayed for new recipes
@@ -64,7 +62,7 @@ module.exports = {
                 if(merchant.ingredients[j].ingredient.id === inputs[i].children[1].children[0].value){
                     newRecipe.ingredients.push({
                         ingredient: inputs[i].children[1].children[0].value,
-                        quantity: convertToMain(merchant.ingredients[j].ingredient.unit, inputs[i].children[2].children[0].value)
+                        quantity: controller.convertToMain(merchant.ingredients[j].ingredient.unit, inputs[i].children[2].children[0].value)
                     });
 
                     break;

+ 0 - 2
views/dashboardPage/js/newTransaction.js

@@ -14,8 +14,6 @@ module.exports = {
 
             recipeDiv.children[0].innerText = merchant.recipes[i].name;
         }
-
-        openSidebar(document.getElementById("newTransaction"));
     },
 
     submit: function(){

+ 0 - 2
views/dashboardPage/js/orderDetails.js

@@ -1,7 +1,5 @@
 module.exports = {
     display: function(order){
-        openSidebar(document.querySelector("#orderDetails"));
-
         document.querySelector("#removeOrderBtn").onclick = ()=>{this.remove(order)};
 
         document.getElementById("orderDetailName").innerText = order.name;

+ 2 - 3
views/dashboardPage/js/recipeDetails.js

@@ -3,7 +3,6 @@ module.exports = {
 
     display: function(recipe){
         this.recipe = recipe;
-        openSidebar(document.querySelector("#recipeDetails"));
 
         document.querySelector("#recipeName").style.display = "block";
         document.querySelector("#recipeNameIn").style.display = "none";
@@ -77,12 +76,12 @@ module.exports = {
                 let select = divs[i].children[0];
                 this.recipe.ingredients.push({
                     ingredient: select.options[select.selectedIndex].ingredient,
-                    quantity: convertToMain(select.options[select.selectedIndex].ingredient.unit, divs[i].children[1].value)
+                    quantity: controller.convertToMain(select.options[select.selectedIndex].ingredient.unit, divs[i].children[1].value)
                 });
             }else{
                 this.recipe.ingredients.push({
                     ingredient: divs[i].ingredient,
-                    quantity: convertToMain(divs[i].ingredient.unit, divs[i].children[1].value)
+                    quantity: controller.convertToMain(divs[i].ingredient.unit, divs[i].children[1].value)
                 });
             }
         }

+ 0 - 2
views/dashboardPage/js/transactionDetails.js

@@ -34,8 +34,6 @@ module.exports = {
         document.getElementById("transactionTime").innerText = transaction.date.toLocaleTimeString();
         document.getElementById("totalRecipes").innerText = `${totalRecipes} recipes`;
         document.getElementById("totalPrice").innerText = `$${(totalPrice / 100).toFixed(2)}`;
-
-        openSidebar(document.getElementById("transactionDetails"));
     },
 
     remove: function(){

+ 1 - 1
views/dashboardPage/sidebars/addIngredients.ejs

@@ -1,6 +1,6 @@
 <div id="addIngredients">
     <div class="sidebarIconButtons">
-        <button class="iconButton" onclick="closeSidebar()">
+        <button class="iconButton" onclick="controller.closeSidebar()">
             <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                 <line x1="5" y1="12" x2="19" y2="12"></line>
                 <polyline points="12 5 19 12 12 19"></polyline>

+ 1 - 1
views/dashboardPage/sidebars/addRecipe.ejs

@@ -1,6 +1,6 @@
 <div id="addRecipe">
     <div class="sidebarIconButtons">
-        <button class="iconButton" onclick="closeSidebar()">
+        <button class="iconButton" onclick="controller.closeSidebar()">
             <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                 <line x1="5" y1="12" x2="19" y2="12"></line>
                 <polyline points="12 5 19 12 12 19"></polyline>

+ 1 - 1
views/dashboardPage/sidebars/newIngredient.ejs

@@ -1,6 +1,6 @@
 <div id="newIngredient">
     <div class="sidebarIconButtons">
-        <button class="iconButton" onclick="closeSidebar()">
+        <button class="iconButton" onclick="controller.closeSidebar()">
             <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                 <line x1="5" y1="12" x2="19" y2="12"></line>
                 <polyline points="12 5 19 12 12 19"></polyline>

+ 1 - 1
views/dashboardPage/sidebars/newOrder.ejs

@@ -1,6 +1,6 @@
 <div id="newOrder">
     <div class="sidebarIconButtons">
-        <button class="iconButton" onclick="closeSidebar()">
+        <button class="iconButton" onclick="controller.closeSidebar()">
             <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                 <line x1="5" y1="12" x2="19" y2="12"></line>
                 <polyline points="12 5 19 12 12 19"></polyline>

+ 1 - 1
views/dashboardPage/sidebars/newTransaction.ejs

@@ -1,6 +1,6 @@
 <div id="newTransaction" class="newTransaction">
     <div class="sidebarIconButtons">
-        <button class="iconButton" onclick="closeSidebar()">
+        <button class="iconButton" onclick="controller.closeSidebar()">
             <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                 <line x1="5" y1="12" x2="19" y2="12"></line>
                 <polyline points="12 5 19 12 12 19"></polyline>

+ 1 - 1
views/dashboardPage/sidebars/orderDetails.ejs

@@ -1,6 +1,6 @@
 <div id="orderDetails">
     <div class="sidebarIconButtons">
-        <button class="iconButton" onclick="closeSidebar()">
+        <button class="iconButton" onclick="controller.closeSidebar()">
             <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                 <line x1="5" y1="12" x2="19" y2="12"></line>
                 <polyline points="12 5 19 12 12 19"></polyline>

+ 1 - 1
views/dashboardPage/sidebars/recipeDetails.ejs

@@ -1,6 +1,6 @@
 <div id="recipeDetails">
     <div class="sidebarIconButtons">
-        <button class="iconButton" onclick="closeSidebar()">
+        <button class="iconButton" onclick="controller.closeSidebar()">
             <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                 <line x1="5" y1="12" x2="19" y2="12"></line>
                 <polyline points="12 5 19 12 12 19"></polyline>

+ 1 - 1
views/dashboardPage/sidebars/transactionDetails.ejs

@@ -1,6 +1,6 @@
 <div id="transactionDetails" class="transactionDetails">
     <div class="sidebarIconButtons">
-        <button class="iconButton" onclick="closeSidebar()">
+        <button class="iconButton" onclick="controller.closeSidebar()">
             <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                 <line x1="5" y1="12" x2="19" y2="12"></line>
                 <polyline points="12 5 19 12 12 19"></polyline>