From f2065e38f1768f3fa933a10a1bbac6a3c546c729 Mon Sep 17 00:00:00 2001 From: Radmer van der Heyde Date: Thu, 3 Mar 2016 17:06:25 -0500 Subject: [PATCH] finished grading --- .../ZG_burgerApp/public/javascripts/ingredients.js | 7 +++++-- lessons/05-client-jquery-ajax/ZG_burgerApp/routes/index.js | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lessons/05-client-jquery-ajax/ZG_burgerApp/public/javascripts/ingredients.js b/lessons/05-client-jquery-ajax/ZG_burgerApp/public/javascripts/ingredients.js index 13ad3a8a..724d89b1 100644 --- a/lessons/05-client-jquery-ajax/ZG_burgerApp/public/javascripts/ingredients.js +++ b/lessons/05-client-jquery-ajax/ZG_burgerApp/public/javascripts/ingredients.js @@ -23,6 +23,7 @@ $ingredientForm.submit(function(event) { var name = $ingredientForm.find("[name='name']").val(); var price = $ingredientForm.find("[name='price']").val(); + //might want to check that name and price are not empty. $.post("postIngredient", { name: name, @@ -33,7 +34,9 @@ $ingredientForm.submit(function(event) { }); //runs when the user clicks the out of stock button for an ingredient +//You can also use .click it is the same thing. $("body").on("click", ".outOfStock", function(){ //had to use .on() method for dynamically added ingredients + //you take advantage of html classes here also, but this works. var isDisabled = !($(this).html() === 'Out of Stock'); //I really want to know a better way of doing this than looking at //the raw html but I looked into adding my own attributes by modifying the doctype html and I found this one easier if (isDisabled){ //if the ingredient was already disabled and they click the button, enable the ingredient @@ -47,7 +50,7 @@ $("body").on("click", ".outOfStock", function(){ //had to use .on() method for $.post("postStock", { //sends a post request to the server with the isDisabled boolean to determine what to set, and the id isDisabled: isDisabled, ingredientId: $(this).parent().attr("id") - }) + }) //generally good to do things when the request returns, so that the user doesn't think something happened when it actually errored. .done() //do nothing on client side when done, could have also had the css changes happen in on success. don't know which is best practice .error(onError); }); @@ -66,7 +69,7 @@ $("body").on("click", ".Edit", function(){ var newName = window.prompt("Please enter the new ingredient name: ", $(this).siblings("#name").html().slice(12)); if (newName !== ""){ var newPrice = window.prompt("Please enter the new price for " + newName, $(this).siblings("#price").html().slice(7)); - if (newPrice !== ""){} + if (newPrice !== ""){ var ingredientId = $(this).parent().attr("id"); $.post("postEdit", { newName: newName, diff --git a/lessons/05-client-jquery-ajax/ZG_burgerApp/routes/index.js b/lessons/05-client-jquery-ajax/ZG_burgerApp/routes/index.js index 3ab75362..10c2fb84 100644 --- a/lessons/05-client-jquery-ajax/ZG_burgerApp/routes/index.js +++ b/lessons/05-client-jquery-ajax/ZG_burgerApp/routes/index.js @@ -1,3 +1,5 @@ +//you probably want to separate this into multiple files. + var Ingredient = require('../models/ingredientModel.js'); var Order = require('../models/orderModel.js'); var mongoose = require('mongoose'); @@ -9,7 +11,7 @@ var ingredients = function(req, res){ //with all of the ingredients Ingredient.find({}, function(err, ingredients){ if (err){ - res.sendStatus(500); //sends status to browser if error + res.status(500).send(err); //sends status to browser if error console.log("Error: ", err); } else { var data = {ingredients: ingredients};