From 29ddc544e5c27ba6c6fbc5f2f36524dfb4a1b759 Mon Sep 17 00:00:00 2001 From: Brian McGonagill Date: Fri, 26 Aug 2022 11:18:18 -0500 Subject: [PATCH] Added a delete confirmation modal to all views. --- .../AdminMgmt/CategoryMgMt/catMgmtForm.html | 9 ++--- client/AdminMgmt/CategoryMgMt/catMgmtTbl.html | 1 + client/AdminMgmt/CategoryMgMt/catMgmtTbl.js | 12 +++---- client/AdminMgmt/ListMgmt/listMgmtForm.js | 16 ++++----- client/AdminMgmt/ListMgmt/listMgmtTbl.html | 1 + client/AdminMgmt/ListMgmt/listMgmtTbl.js | 16 ++++----- .../AdminMgmt/LocationMgmt/locMgmtForm.html | 9 ++--- client/AdminMgmt/LocationMgmt/locMgmtTbl.html | 1 + client/AdminMgmt/LocationMgmt/locMgmtTbl.js | 12 +++---- client/AdminMgmt/ProductMgmt/prodMgmtTbl.html | 1 + client/AdminMgmt/ProductMgmt/prodMgmtTbl.js | 12 +++---- client/AdminMgmt/StoreMgmt/storeMgmtForm.html | 9 ++--- client/AdminMgmt/StoreMgmt/storeMgmtTbl.html | 1 + client/AdminMgmt/StoreMgmt/storeMgmtTbl.js | 12 +++---- .../deleteConfirmationModal.html | 18 ++++++++++ .../deleteConfirmationModal.js | 33 +++++++++++++++++++ client/General/headerBar.js | 4 +-- client/ListItems/listItemsTbl.html | 1 + client/ListItems/listItemsTbl.js | 19 +++++------ client/Lists/listsTbl.js | 2 +- imports/api/category.js | 9 +---- imports/api/listItems.js | 2 +- imports/api/lists.js | 9 +---- imports/api/location.js | 9 +---- imports/api/shopList.js | 15 +-------- imports/api/stores.js | 9 +---- server/publish.js | 2 +- 27 files changed, 117 insertions(+), 127 deletions(-) create mode 100644 client/General/DeleteConfModal/deleteConfirmationModal.html create mode 100644 client/General/DeleteConfModal/deleteConfirmationModal.js diff --git a/client/AdminMgmt/CategoryMgMt/catMgmtForm.html b/client/AdminMgmt/CategoryMgMt/catMgmtForm.html index 9eb21ec..bee5991 100644 --- a/client/AdminMgmt/CategoryMgMt/catMgmtForm.html +++ b/client/AdminMgmt/CategoryMgMt/catMgmtForm.html @@ -1,16 +1,11 @@ \ No newline at end of file diff --git a/client/AdminMgmt/CategoryMgMt/catMgmtTbl.js b/client/AdminMgmt/CategoryMgMt/catMgmtTbl.js index 352c92e..0d82838 100644 --- a/client/AdminMgmt/CategoryMgMt/catMgmtTbl.js +++ b/client/AdminMgmt/CategoryMgMt/catMgmtTbl.js @@ -19,13 +19,11 @@ Template.catMgmtTbl.helpers({ Template.catMgmtTbl.events({ 'click .deleteCategory' (event) { event.preventDefault(); - Meteor.call('delete.category', this._id, function(err, result) { - if (err) { - console.log(" ERROR deleting category: " + err); - } else { - console.log(" SUCCESS deleting the category."); - } - }); + Session.set("deleteId", this._id); + Session.set("method", "delete.category"); + Session.set("item", this.categoryName); + Session.set("view", "Categories"); + $('#modalDelete').modal('open'); }, 'click .editCategory' (event) { event.preventDefault(); diff --git a/client/AdminMgmt/ListMgmt/listMgmtForm.js b/client/AdminMgmt/ListMgmt/listMgmtForm.js index d15c1a2..ece9583 100644 --- a/client/AdminMgmt/ListMgmt/listMgmtForm.js +++ b/client/AdminMgmt/ListMgmt/listMgmtForm.js @@ -30,9 +30,9 @@ Template.listMgmtForm.events({ } else { Meteor.call('add.list', listName, shared, function(err, result) { if (err) { - console.log(" ERROR adding list name: " + err); + // console.log(" ERROR adding list name: " + err); } else { - console.log(" SUCCESS adding list name."); + // console.log(" SUCCESS adding list name."); $("#listNameInp").val(""); $("#isShared").prop("checked", false); } @@ -51,9 +51,9 @@ Template.listMgmtForm.events({ } else { Meteor.call('edit.list', listId, listName, shared, function(err, result) { if (err) { - console.log(" ERROR editing list name: " + err); + // console.log(" ERROR editing list name: " + err); } else { - console.log(" SUCCESS editing list name."); + // console.log(" SUCCESS editing list name."); $("#listNameInp").val(""); $("#isShared").prop("checked", false); Session.set("listNameEditMode", false); @@ -75,9 +75,9 @@ Template.listMgmtForm.events({ if (editMode == false) { Meteor.call('add.list', listName, shared, function(err, result) { if (err) { - console.log(" ERROR adding list name: " + err); + // console.log(" ERROR adding list name: " + err); } else { - console.log(" SUCCESS adding list name."); + // console.log(" SUCCESS adding list name."); $("#listNameInp").val(""); $("#isShared").prop("checked", false); } @@ -85,9 +85,9 @@ Template.listMgmtForm.events({ } else { Meteor.call('edit.list', listId, listName, shared, function(err, result) { if (err) { - console.log(" ERROR editing list name: " + err); + // console.log(" ERROR editing list name: " + err); } else { - console.log(" SUCCESS editing list name."); + // console.log(" SUCCESS editing list name."); $("#listNameInp").val(""); $("#isShared").prop("checked", false); Session.set("listNameEditMode", false); diff --git a/client/AdminMgmt/ListMgmt/listMgmtTbl.html b/client/AdminMgmt/ListMgmt/listMgmtTbl.html index 7724192..038c94d 100644 --- a/client/AdminMgmt/ListMgmt/listMgmtTbl.html +++ b/client/AdminMgmt/ListMgmt/listMgmtTbl.html @@ -13,4 +13,5 @@ + {{> deleteConfirmationModal}} \ No newline at end of file diff --git a/client/AdminMgmt/ListMgmt/listMgmtTbl.js b/client/AdminMgmt/ListMgmt/listMgmtTbl.js index c469f4d..0f75528 100644 --- a/client/AdminMgmt/ListMgmt/listMgmtTbl.js +++ b/client/AdminMgmt/ListMgmt/listMgmtTbl.js @@ -19,14 +19,12 @@ Template.listMgmtTbl.helpers({ Template.listMgmtTbl.events({ 'click .deleteListName' (event) { event.preventDefault(); + Session.set("deleteId", this._id); + Session.set("method", "delete.list"); + Session.set("item", this.listName); + Session.set("view", "Lists"); + $('#modalDelete').modal('open'); let listId = this._id; - Meteor.call('delete.list', listId, function(err, result) { - if (err) { - console.log(" ERROR deleting list: " + err); - } else { - console.log(" SUCCESS deleting list."); - } - }); }, 'click .editListName' (event) { event.preventDefault(); @@ -47,9 +45,9 @@ Template.listMgmtTbl.events({ let listId = this._id; Meteor.call('mark.complete', listId, function(err, result) { if (err) { - console.log(" ERROR marking complete: " + err); + // console.log(" ERROR marking complete: " + err); } else { - console.log(" SUCCESS marking complete."); + // console.log(" SUCCESS marking complete."); } }); } diff --git a/client/AdminMgmt/LocationMgmt/locMgmtForm.html b/client/AdminMgmt/LocationMgmt/locMgmtForm.html index fe725b7..c0a9d63 100644 --- a/client/AdminMgmt/LocationMgmt/locMgmtForm.html +++ b/client/AdminMgmt/LocationMgmt/locMgmtForm.html @@ -1,16 +1,11 @@ \ No newline at end of file diff --git a/client/AdminMgmt/LocationMgmt/locMgmtTbl.js b/client/AdminMgmt/LocationMgmt/locMgmtTbl.js index fcae297..66ebe25 100644 --- a/client/AdminMgmt/LocationMgmt/locMgmtTbl.js +++ b/client/AdminMgmt/LocationMgmt/locMgmtTbl.js @@ -19,13 +19,11 @@ Template.locMgmtTbl.helpers({ Template.locMgmtTbl.events({ 'click .deleteLocation' (event) { event.preventDefault(); - Meteor.call('delete.location', this._id, function(err, result) { - if (err) { - console.log(" ERROR deleting location: " + err); - } else { - console.log(" SUCCESS deleting the location."); - } - }); + Session.set("deleteId", this._id); + Session.set("method", "delete.location"); + Session.set("item", this.locationName); + Session.set("view", "Locations"); + $('#modalDelete').modal('open'); }, 'click .editLocation' (event) { event.preventDefault(); diff --git a/client/AdminMgmt/ProductMgmt/prodMgmtTbl.html b/client/AdminMgmt/ProductMgmt/prodMgmtTbl.html index 6e53a87..cbddd53 100644 --- a/client/AdminMgmt/ProductMgmt/prodMgmtTbl.html +++ b/client/AdminMgmt/ProductMgmt/prodMgmtTbl.html @@ -36,4 +36,5 @@ + {{> deleteConfirmationModal}} \ No newline at end of file diff --git a/client/AdminMgmt/ProductMgmt/prodMgmtTbl.js b/client/AdminMgmt/ProductMgmt/prodMgmtTbl.js index 00bd866..3a036d3 100644 --- a/client/AdminMgmt/ProductMgmt/prodMgmtTbl.js +++ b/client/AdminMgmt/ProductMgmt/prodMgmtTbl.js @@ -28,13 +28,11 @@ Template.prodMgmtTbl.helpers({ Template.prodMgmtTbl.events({ 'click .deleteProduct' (event) { event.preventDefault(); - Meteor.call('delete.product', this._id, function(err, result) { - if (err) { - console.log(" ERROR deleting product: " + err); - } else { - console.log(" SUCCESS deleting the product."); - } - }); + Session.set("deleteId", this._id); + Session.set("method", "delete.product"); + Session.set("item", this.prodName); + Session.set("view", "Products");; + $('#modalDelete').modal('open'); }, 'click .editProduct' (event) { event.preventDefault(); diff --git a/client/AdminMgmt/StoreMgmt/storeMgmtForm.html b/client/AdminMgmt/StoreMgmt/storeMgmtForm.html index 4b53e50..e8368c6 100644 --- a/client/AdminMgmt/StoreMgmt/storeMgmtForm.html +++ b/client/AdminMgmt/StoreMgmt/storeMgmtForm.html @@ -1,16 +1,11 @@ \ No newline at end of file diff --git a/client/AdminMgmt/StoreMgmt/storeMgmtTbl.js b/client/AdminMgmt/StoreMgmt/storeMgmtTbl.js index 8812666..883e3f4 100644 --- a/client/AdminMgmt/StoreMgmt/storeMgmtTbl.js +++ b/client/AdminMgmt/StoreMgmt/storeMgmtTbl.js @@ -19,13 +19,11 @@ Template.storeMgmtTbl.helpers({ Template.storeMgmtTbl.events({ 'click .deleteStore' (event) { event.preventDefault(); - Meteor.call('delete.store', this._id, function(err, result) { - if (err) { - console.log(" ERROR deleting store: " + err); - } else { - console.log(" SUCCESS deleting the store."); - } - }); + Session.set("deleteId", this._id); + Session.set("method", "delete.store"); + Session.set("item", this.storeName); + Session.set("view", "Stores"); + $('#modalDelete').modal('open'); }, 'click .editStore' (event) { event.preventDefault(); diff --git a/client/General/DeleteConfModal/deleteConfirmationModal.html b/client/General/DeleteConfModal/deleteConfirmationModal.html new file mode 100644 index 0000000..03b1d13 --- /dev/null +++ b/client/General/DeleteConfModal/deleteConfirmationModal.html @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/client/General/DeleteConfModal/deleteConfirmationModal.js b/client/General/DeleteConfModal/deleteConfirmationModal.js new file mode 100644 index 0000000..5bdbbb5 --- /dev/null +++ b/client/General/DeleteConfModal/deleteConfirmationModal.js @@ -0,0 +1,33 @@ +Template.deleteConfirmationModal.onCreated(function() { + +}); + +Template.deleteConfirmationModal.onRendered(function() { + $('.modal').modal(); +}); + +Template.deleteConfirmationModal.helpers({ + itemName: function() { + return Session.get("item"); + }, + viewName: function() { + return Session.get("view"); + } +}); + +Template.deleteConfirmationModal.events({ + 'click .confirmDelete' (event) { + event.preventDefault(); + let deleteId = Session.get("deleteId"); + let method = Session.get("method"); + + Meteor.call(method, deleteId, function(err, result) { + if (err) { + console.log(" ERROR deleting item from modal: " + err); + } else { + // console.log(" SUCCESSFULLY deleted."); + $('#modalDelete').modal('close'); + } + }); + }, +}); \ No newline at end of file diff --git a/client/General/headerBar.js b/client/General/headerBar.js index 0213d51..bdfd317 100644 --- a/client/General/headerBar.js +++ b/client/General/headerBar.js @@ -26,11 +26,11 @@ Template.headerBar.events({ 'click .navBtn' (event) { event.preventDefault(); var clickedTarget = event.target.id; - console.log("clicked " + clickedTarget); + // console.log("clicked " + clickedTarget); if (clickedTarget == 'mainMenu') { FlowRouter.go('/'); } else { - console.log("should be going to /" + clickedTarget); + // console.log("should be going to /" + clickedTarget); FlowRouter.go('/' + clickedTarget); } }, diff --git a/client/ListItems/listItemsTbl.html b/client/ListItems/listItemsTbl.html index 5c8780f..de728f8 100644 --- a/client/ListItems/listItemsTbl.html +++ b/client/ListItems/listItemsTbl.html @@ -18,4 +18,5 @@ + {{> deleteConfirmationModal}} \ No newline at end of file diff --git a/client/ListItems/listItemsTbl.js b/client/ListItems/listItemsTbl.js index 6114559..9824770 100644 --- a/client/ListItems/listItemsTbl.js +++ b/client/ListItems/listItemsTbl.js @@ -7,6 +7,7 @@ Template.listItemsTbl.onCreated(function() { }); Template.listItemsTbl.onRendered(function() { + $('.modal').modal(); Session.set("showReceivedItems", false); Session.set("searchVal", ""); }); @@ -40,7 +41,7 @@ Template.listItemsTbl.events({ if (err) { console.log(" ERROR setting this item as NOT ordered: " + err); } else { - console.log(" SUCCESS setting this item as NOT ordered."); + // console.log(" SUCCESS setting this item as NOT ordered."); } }); } else { @@ -48,7 +49,7 @@ Template.listItemsTbl.events({ if (err) { console.log(" ERROR marking item ordered: " + err); } else { - console.log(" SUCCESS marking this item ordered."); + // console.log(" SUCCESS marking this item ordered."); } }); } @@ -59,18 +60,16 @@ Template.listItemsTbl.events({ if (err) { console.log(" ERROR setting item as received: " + err); } else { - console.log(" SUCCESS setting item received."); + // console.log(" SUCCESS setting item received."); } }); }, 'click .deleteListItem' (event) { event.preventDefault(); - Meteor.call('delete.listItem', this._id, function(err, result) { - if (err) { - console.log(" ERROR deleting the list item: " + err); - } else { - console.log(" SUCCESS deleting the list item."); - } - }); + Session.set("deleteId", this._id); + Session.set("method", "delete.listItem"); + Session.set("item", this.itemName); + Session.set("view", "List Items"); + $('#modalDelete').modal('open'); }, }); \ No newline at end of file diff --git a/client/Lists/listsTbl.js b/client/Lists/listsTbl.js index eae5900..d0fa225 100644 --- a/client/Lists/listsTbl.js +++ b/client/Lists/listsTbl.js @@ -48,7 +48,7 @@ Template.listsTbl.events({ console.log(" ERROR marking list complete! " + err); showSnackbar("ERROR! List Not Makred Complete!", "red"); } else { - console.log(" SUCCESS marking list complete."); + // console.log(" SUCCESS marking list complete."); showSnackbar("List Marked Complete!", "green"); } }); diff --git a/imports/api/category.js b/imports/api/category.js index 7ddf416..eb8883b 100644 --- a/imports/api/category.js +++ b/imports/api/category.js @@ -45,13 +45,6 @@ Meteor.methods({ throw new Meteor.Error('You are not allowed to delete categories. Make sure you are logged in with valid user credentials.'); } - let categoryInfo = Categories.findOne({ _id: categoryId }); - let myId = this.userId; - if (myId == categoryInfo.owner) { - return Categories.remove({ _id: categoryId }); - } else { - console.log("User not allowed to delete this Category. Not the owner!"); - return("Not Allowed!"); - } + return Categories.remove({ _id: categoryId }); }, }); \ No newline at end of file diff --git a/imports/api/listItems.js b/imports/api/listItems.js index 383c299..50805cc 100644 --- a/imports/api/listItems.js +++ b/imports/api/listItems.js @@ -29,7 +29,7 @@ Meteor.methods({ if (err) { console.log(" ERROR adding item to products: " + err); } else { - console.log(" SUCCESS adding item to Products."); + // console.log(" SUCCESS adding item to Products."); return ListItems.insert({ itemName: itemName, listId: listId, diff --git a/imports/api/lists.js b/imports/api/lists.js index 7521bb8..14ec348 100644 --- a/imports/api/lists.js +++ b/imports/api/lists.js @@ -50,14 +50,7 @@ Meteor.methods({ throw new Meteor.Error('You are not allowed to delete lists. Make sure you are logged in with valid user credentials.'); } - let listInfo = Lists.findOne({ _id: listId }); - let myId = this.userId; - if (myId == listInfo.listOwner) { - return Lists.remove({ _id: listId }); - } else { - console.log("User not allowed to delete this list. Not the owner!"); - return("Not Allowed!"); - } + return Lists.remove({ _id: listId }); }, 'mark.complete' (listId) { check(listId, String); diff --git a/imports/api/location.js b/imports/api/location.js index d6b2001..05b0925 100644 --- a/imports/api/location.js +++ b/imports/api/location.js @@ -45,13 +45,6 @@ Meteor.methods({ throw new Meteor.Error('You are not allowed to delete locations. Make sure you are logged in with valid user credentials.'); } - let locationInfo = Locations.findOne({ _id: locationId }); - let myId = this.userId; - if (myId == locationInfo.owner) { - return Locations.remove({ _id: locationId }); - } else { - console.log("User not allowed to delete this location. Not the owner!"); - return("Not Allowed!"); - } + return Locations.remove({ _id: locationId }); }, }); \ No newline at end of file diff --git a/imports/api/shopList.js b/imports/api/shopList.js index 488c845..b013d50 100644 --- a/imports/api/shopList.js +++ b/imports/api/shopList.js @@ -23,9 +23,6 @@ Meteor.methods({ shopName: shopName, shopOwner: this.userId, }); - }, - 'add.shopListUsers' (userIds) { - }, 'edit.shopList' (shopId, shopName) { check(shopId, String); @@ -40,9 +37,6 @@ Meteor.methods({ shopName: shopName, } }); - }, - 'edit.shopListUsers' (shopId, userIds) { - }, 'delete.shopList' (shopId) { check(shopId, String); @@ -51,13 +45,6 @@ Meteor.methods({ throw new Meteor.Error('You are not allowed to delete shopping lists. Make sure you are logged in with valid user credentials.'); } - let shopInfo = ShopLists.findOne({ _id: shopId }); - let myId = this.userId; - if (myId == shopInfo.owner) { - return ShopLists.remove({ _id: shopId }); - } else { - console.log("User not allowed to delete this shopping list. Not the owner!"); - return("Not Allowed!"); - } + return ShopLists.remove({ _id: shopId }); }, }); \ No newline at end of file diff --git a/imports/api/stores.js b/imports/api/stores.js index 175ba5e..4638595 100644 --- a/imports/api/stores.js +++ b/imports/api/stores.js @@ -45,13 +45,6 @@ Meteor.methods({ throw new Meteor.Error('You are not allowed to delete stores. Make sure you are logged in with valid user credentials.'); } - let storeInfo = Stores.findOne({ _id: storeId }); - let myId = this.userId; - if (myId == storeInfo.owner) { - return Stores.remove({ _id: storeId }); - } else { - console.log("User not allowed to delete this store. Not the owner!"); - return("Not Allowed!"); - } + return Stores.remove({ _id: storeId }); }, }); \ No newline at end of file diff --git a/server/publish.js b/server/publish.js index 6011873..45cd22e 100644 --- a/server/publish.js +++ b/server/publish.js @@ -61,7 +61,7 @@ Meteor.publish("myLists", function() { Meteor.publish("myListItems", function(listId) { try { - console.log("List Id is: " + listId); + // console.log("List Id is: " + listId); return ListItems.find({ listId: listId }); } catch (error) { console.log(" ERROR pulling list items for this list: " + error);