diff --git a/app/assets/javascripts/HomePage.js b/app/assets/javascripts/HomePage.js
index 95f769f9102322a61d93bfa2f3a5d165a499c6ad..a1bd08e0b15713de58b5ba04c4d4be56c9897757 100644
--- a/app/assets/javascripts/HomePage.js
+++ b/app/assets/javascripts/HomePage.js
@@ -1,13 +1,13 @@
-function removeList(id, elem) {
+function removeList(id, elem) { // Method for removing a list
getButton("/del_lst", "list_id", id);
elem.closest(".listCon").remove();
}
-function removeProd(id, elem) {
+function removeProd(id, elem) { // Method for removing a product
getButton("/del_prod", "product_id", id);
elem.closest(".prodCon").remove();
}
-function newListCheck(elem) {
- document.getElementById("newListSubmit").disabled = elem.value.length == 0;
+function newListCheck(elem) { // Method to disable the new list button depending on whether a text field is empty
+ $("#newListSubmit").disabled = elem.value.length === 0;
}
\ No newline at end of file
diff --git a/app/assets/javascripts/ListViewPage.js b/app/assets/javascripts/ListViewPage.js
index 2b138da6c5f60827d5020eb936fd725d1200dffb..bcbce5bf7ce847776e239b3b369a486f591832d5 100644
--- a/app/assets/javascripts/ListViewPage.js
+++ b/app/assets/javascripts/ListViewPage.js
@@ -5,7 +5,7 @@ let nextChangeNames = [];
let timer;
-function performUpdate(){
+function performUpdate() { // The request is made inside of this function
$.ajax({
url: "/change_prods",
data: {
@@ -25,14 +25,14 @@ function performUpdate(){
timer = null;
}
-function updateProduct(field, id, col){
- if(col === "name" && field.value.length === 0){
+function updateProduct(field, id, col){ // This method will allow the user to make multiple changes at once, without sending multiple requests
+ if(col === "name" && field.value.length === 0){ // If we are updating the name, but the user has emptied it, we do nothing
return;
- } else if(col === "quantity" && field.value < 1){
+ } else if(col === "quantity" && field.value < 1){ // If we are updating the quantity, but the user has set it to less than 1, we do nothing
return;
}
- let present = false;
+ let present = false; // Check to see if we have already updated the current product, if so, then update the relevant array with the new data
for(let i = 0; i < nextChangeIds.length; i++){
if(nextChangeIds[i] === id){
if(col === "quantity"){
@@ -48,7 +48,7 @@ function updateProduct(field, id, col){
}
}
- if(!present){
+ if(!present){ // If we did not already find the element in the sectino above, then create a new change
nextChangeIds.push(id);
if(col === "quantity"){
@@ -66,7 +66,7 @@ function updateProduct(field, id, col){
}
}
- if(!timer){
+ if(!timer){ // This timer makes sure that a request is not sent more than every so milliseconds
timer = setTimeout(performUpdate, 2000);
}
}
\ No newline at end of file
diff --git a/app/assets/javascripts/LoginPage.js b/app/assets/javascripts/LoginPage.js
index deb8b1c4c139cd7ddb84361970af5201601fdc18..0204d9503deb26d0629473d6fa5319b77aff823e 100644
--- a/app/assets/javascripts/LoginPage.js
+++ b/app/assets/javascripts/LoginPage.js
@@ -1,15 +1,9 @@
-function showLoginForm(){
- let loginForm = document.getElementById("loginForm");
- let createForm = document.getElementById("createForm");
-
- loginForm.style.display = "flex";
- createForm.style.display = "none";
+function showLoginForm() { // Hide the create form and show the login form
+ $("#loginForm").style.display = "flex";
+ $("#createForm").style.display = "none";
}
-function showCreateForm(){
- let loginForm = document.getElementById("loginForm");
- let createForm = document.getElementById("createForm");
-
- createForm.style.display = "flex";
- loginForm.style.display = "none";
+function showCreateForm() { // Hide the login form and show the create form
+ $("#loginForm").style.display = "none";
+ $("#createForm").style.display = "flex";
}
\ No newline at end of file
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 4751076e6986151b4ab5f9320d8c4afd862146af..c889188b94a0a03f3a22b81ba2529306ee311570 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -14,17 +14,15 @@
//= require activestorage
//= require turbolinks
//= require jquery
-////= require bootstrap-sprockets
//= require_tree .
-function getButton(url, name, value){
+function getButton(url, name, value){ // A function allowing a button to make a get request with a parameter
let dataHash = {};
dataHash[name] = value;
$.ajax({
url: url,
data: dataHash,
- type: "get",
- sucess: $("#lists").load(" #lists")
+ type: "get"
});
}