Added a delete confirmation modal to all views.

This commit is contained in:
Brian McGonagill 2022-08-26 11:18:18 -05:00
parent 4d9d2acff6
commit 29ddc544e5
27 changed files with 117 additions and 127 deletions

View file

@ -1,16 +1,11 @@
<template name="catMgmtForm"> <template name="catMgmtForm">
<form action="submit" id="catInputForm"> <form action="submit" id="catInputForm">
<div class="row"> <div class="row">
<div class="col s12 m6 l6 input-field"> <div class="col s8 m10 l10 input-field">
<input type="text" class="catNameInp" id="catNameInp" style="{{#if $eq catNameErr true}}border: 2px solid red;{{/if}}" /> <input type="text" class="catNameInp" id="catNameInp" style="{{#if $eq catNameErr true}}border: 2px solid red;{{/if}}" />
<label for="catNameInp">Name*</label> <label for="catNameInp">Name*</label>
</div> </div>
</div> <div class="col s4 m2 l2 input-field">
<div class="row">
<div class="col s6 m6 l6">
<a class="waves-effect waves-light btn cancelCatMgmt orange">Cancel</a>
</div>
<div class="col s6 m6 l6">
{{#if $eq catEditMode false}} {{#if $eq catEditMode false}}
<a class="waves-effect waves-light btn saveCatMgmt green right">Add</a> <a class="waves-effect waves-light btn saveCatMgmt green right">Add</a>
{{else}} {{else}}

View file

@ -12,4 +12,5 @@
</ul> </ul>
</div> </div>
</div> </div>
{{> deleteConfirmationModal}}
</template> </template>

View file

@ -19,13 +19,11 @@ Template.catMgmtTbl.helpers({
Template.catMgmtTbl.events({ Template.catMgmtTbl.events({
'click .deleteCategory' (event) { 'click .deleteCategory' (event) {
event.preventDefault(); event.preventDefault();
Meteor.call('delete.category', this._id, function(err, result) { Session.set("deleteId", this._id);
if (err) { Session.set("method", "delete.category");
console.log(" ERROR deleting category: " + err); Session.set("item", this.categoryName);
} else { Session.set("view", "Categories");
console.log(" SUCCESS deleting the category."); $('#modalDelete').modal('open');
}
});
}, },
'click .editCategory' (event) { 'click .editCategory' (event) {
event.preventDefault(); event.preventDefault();

View file

@ -30,9 +30,9 @@ Template.listMgmtForm.events({
} else { } else {
Meteor.call('add.list', listName, shared, function(err, result) { Meteor.call('add.list', listName, shared, function(err, result) {
if (err) { if (err) {
console.log(" ERROR adding list name: " + err); // console.log(" ERROR adding list name: " + err);
} else { } else {
console.log(" SUCCESS adding list name."); // console.log(" SUCCESS adding list name.");
$("#listNameInp").val(""); $("#listNameInp").val("");
$("#isShared").prop("checked", false); $("#isShared").prop("checked", false);
} }
@ -51,9 +51,9 @@ Template.listMgmtForm.events({
} else { } else {
Meteor.call('edit.list', listId, listName, shared, function(err, result) { Meteor.call('edit.list', listId, listName, shared, function(err, result) {
if (err) { if (err) {
console.log(" ERROR editing list name: " + err); // console.log(" ERROR editing list name: " + err);
} else { } else {
console.log(" SUCCESS editing list name."); // console.log(" SUCCESS editing list name.");
$("#listNameInp").val(""); $("#listNameInp").val("");
$("#isShared").prop("checked", false); $("#isShared").prop("checked", false);
Session.set("listNameEditMode", false); Session.set("listNameEditMode", false);
@ -75,9 +75,9 @@ Template.listMgmtForm.events({
if (editMode == false) { if (editMode == false) {
Meteor.call('add.list', listName, shared, function(err, result) { Meteor.call('add.list', listName, shared, function(err, result) {
if (err) { if (err) {
console.log(" ERROR adding list name: " + err); // console.log(" ERROR adding list name: " + err);
} else { } else {
console.log(" SUCCESS adding list name."); // console.log(" SUCCESS adding list name.");
$("#listNameInp").val(""); $("#listNameInp").val("");
$("#isShared").prop("checked", false); $("#isShared").prop("checked", false);
} }
@ -85,9 +85,9 @@ Template.listMgmtForm.events({
} else { } else {
Meteor.call('edit.list', listId, listName, shared, function(err, result) { Meteor.call('edit.list', listId, listName, shared, function(err, result) {
if (err) { if (err) {
console.log(" ERROR editing list name: " + err); // console.log(" ERROR editing list name: " + err);
} else { } else {
console.log(" SUCCESS editing list name."); // console.log(" SUCCESS editing list name.");
$("#listNameInp").val(""); $("#listNameInp").val("");
$("#isShared").prop("checked", false); $("#isShared").prop("checked", false);
Session.set("listNameEditMode", false); Session.set("listNameEditMode", false);

View file

@ -13,4 +13,5 @@
</ul> </ul>
</div> </div>
</div> </div>
{{> deleteConfirmationModal}}
</template> </template>

View file

@ -19,14 +19,12 @@ Template.listMgmtTbl.helpers({
Template.listMgmtTbl.events({ Template.listMgmtTbl.events({
'click .deleteListName' (event) { 'click .deleteListName' (event) {
event.preventDefault(); 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; 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) { 'click .editListName' (event) {
event.preventDefault(); event.preventDefault();
@ -47,9 +45,9 @@ Template.listMgmtTbl.events({
let listId = this._id; let listId = this._id;
Meteor.call('mark.complete', listId, function(err, result) { Meteor.call('mark.complete', listId, function(err, result) {
if (err) { if (err) {
console.log(" ERROR marking complete: " + err); // console.log(" ERROR marking complete: " + err);
} else { } else {
console.log(" SUCCESS marking complete."); // console.log(" SUCCESS marking complete.");
} }
}); });
} }

View file

@ -1,16 +1,11 @@
<template name="locMgmtForm"> <template name="locMgmtForm">
<form action="" id="locInputForm"> <form action="" id="locInputForm">
<div class="row"> <div class="row">
<div class="col s12 m6 l6 input-field"> <div class="col s8 m10 l10 input-field">
<input type="text" class="locNameInp" id="locNameInp" style="{{#if $eq locNameErr true}}border: 2px solid red;{{/if}}" /> <input type="text" class="locNameInp" id="locNameInp" style="{{#if $eq locNameErr true}}border: 2px solid red;{{/if}}" />
<label for="locNameInp">Name*</label> <label for="locNameInp">Name*</label>
</div> </div>
</div> <div class="col s4 m2 l2 input-field">
<div class="row">
<div class="col s6 m6 l6">
<a class="waves-effect waves-light btn cancelLocMgmt orange">Cancel</a>
</div>
<div class="col s6 m6 l6">
{{#if $eq locEditMode false}} {{#if $eq locEditMode false}}
<a class="waves-effect waves-light btn saveLocMgmt green right">Add</a> <a class="waves-effect waves-light btn saveLocMgmt green right">Add</a>
{{else}} {{else}}

View file

@ -12,4 +12,5 @@
</ul> </ul>
</div> </div>
</div> </div>
{{> deleteConfirmationModal}}
</template> </template>

View file

@ -19,13 +19,11 @@ Template.locMgmtTbl.helpers({
Template.locMgmtTbl.events({ Template.locMgmtTbl.events({
'click .deleteLocation' (event) { 'click .deleteLocation' (event) {
event.preventDefault(); event.preventDefault();
Meteor.call('delete.location', this._id, function(err, result) { Session.set("deleteId", this._id);
if (err) { Session.set("method", "delete.location");
console.log(" ERROR deleting location: " + err); Session.set("item", this.locationName);
} else { Session.set("view", "Locations");
console.log(" SUCCESS deleting the location."); $('#modalDelete').modal('open');
}
});
}, },
'click .editLocation' (event) { 'click .editLocation' (event) {
event.preventDefault(); event.preventDefault();

View file

@ -36,4 +36,5 @@
</table> </table>
</div> </div>
</div> </div>
{{> deleteConfirmationModal}}
</template> </template>

View file

@ -28,13 +28,11 @@ Template.prodMgmtTbl.helpers({
Template.prodMgmtTbl.events({ Template.prodMgmtTbl.events({
'click .deleteProduct' (event) { 'click .deleteProduct' (event) {
event.preventDefault(); event.preventDefault();
Meteor.call('delete.product', this._id, function(err, result) { Session.set("deleteId", this._id);
if (err) { Session.set("method", "delete.product");
console.log(" ERROR deleting product: " + err); Session.set("item", this.prodName);
} else { Session.set("view", "Products");;
console.log(" SUCCESS deleting the product."); $('#modalDelete').modal('open');
}
});
}, },
'click .editProduct' (event) { 'click .editProduct' (event) {
event.preventDefault(); event.preventDefault();

View file

@ -1,16 +1,11 @@
<template name="storeMgmtForm"> <template name="storeMgmtForm">
<form id="storeForm" action="submit"> <form id="storeForm" action="submit">
<div class="row"> <div class="row">
<div class="col s12 input-field"> <div class="col s8 m10 l10 input-field">
<input type="text" class="storeName" id="storeName" /> <input type="text" class="storeName" id="storeName" />
<label for="storeName">Name</label> <label for="storeName">Name</label>
</div> </div>
</div> <div class="col s4 m2 l2 input-field">
<div class="row">
<div class="col s6 m6 l6">
<a class="waves-effect waves-light btn cancelStoreMgmt orange">Cancel</a>
</div>
<div class="col s6 m6 l6">
{{#if $eq editModeStore false}} {{#if $eq editModeStore false}}
<a class="waves-effect waves-light btn saveStoreMgmt green right">Add</a> <a class="waves-effect waves-light btn saveStoreMgmt green right">Add</a>
{{else}} {{else}}

View file

@ -12,4 +12,5 @@
</ul> </ul>
</div> </div>
</div> </div>
{{> deleteConfirmationModal}}
</template> </template>

View file

@ -19,13 +19,11 @@ Template.storeMgmtTbl.helpers({
Template.storeMgmtTbl.events({ Template.storeMgmtTbl.events({
'click .deleteStore' (event) { 'click .deleteStore' (event) {
event.preventDefault(); event.preventDefault();
Meteor.call('delete.store', this._id, function(err, result) { Session.set("deleteId", this._id);
if (err) { Session.set("method", "delete.store");
console.log(" ERROR deleting store: " + err); Session.set("item", this.storeName);
} else { Session.set("view", "Stores");
console.log(" SUCCESS deleting the store."); $('#modalDelete').modal('open');
}
});
}, },
'click .editStore' (event) { 'click .editStore' (event) {
event.preventDefault(); event.preventDefault();

View file

@ -0,0 +1,18 @@
<template name="deleteConfirmationModal">
<div id="modalDelete" class="modal">
<div class="modal-content">
<h4>Delete Confirmation</h4>
You are about to permanently delete {{itemName}} from the {{viewName}} list. Are you sure?
</div>
<div class="modal-footer">
<div class="row">
<div class="col s6 m6 l6">
<a class="modal-close waves-effect waves-light btn left cancelDelete orange">Cancel</a>
</div>
<div class="col s6 m6 l6">
<a class="waves-effect waves-light btn confirmDelete red right">Delete</a>
</div>
</div>
</div>
</div>
</template>

View file

@ -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');
}
});
},
});

View file

@ -26,11 +26,11 @@ Template.headerBar.events({
'click .navBtn' (event) { 'click .navBtn' (event) {
event.preventDefault(); event.preventDefault();
var clickedTarget = event.target.id; var clickedTarget = event.target.id;
console.log("clicked " + clickedTarget); // console.log("clicked " + clickedTarget);
if (clickedTarget == 'mainMenu') { if (clickedTarget == 'mainMenu') {
FlowRouter.go('/'); FlowRouter.go('/');
} else { } else {
console.log("should be going to /" + clickedTarget); // console.log("should be going to /" + clickedTarget);
FlowRouter.go('/' + clickedTarget); FlowRouter.go('/' + clickedTarget);
} }
}, },

View file

@ -18,4 +18,5 @@
</ul> </ul>
</div> </div>
</div> </div>
{{> deleteConfirmationModal}}
</template> </template>

View file

@ -7,6 +7,7 @@ Template.listItemsTbl.onCreated(function() {
}); });
Template.listItemsTbl.onRendered(function() { Template.listItemsTbl.onRendered(function() {
$('.modal').modal();
Session.set("showReceivedItems", false); Session.set("showReceivedItems", false);
Session.set("searchVal", ""); Session.set("searchVal", "");
}); });
@ -40,7 +41,7 @@ Template.listItemsTbl.events({
if (err) { if (err) {
console.log(" ERROR setting this item as NOT ordered: " + err); console.log(" ERROR setting this item as NOT ordered: " + err);
} else { } else {
console.log(" SUCCESS setting this item as NOT ordered."); // console.log(" SUCCESS setting this item as NOT ordered.");
} }
}); });
} else { } else {
@ -48,7 +49,7 @@ Template.listItemsTbl.events({
if (err) { if (err) {
console.log(" ERROR marking item ordered: " + err); console.log(" ERROR marking item ordered: " + err);
} else { } else {
console.log(" SUCCESS marking this item ordered."); // console.log(" SUCCESS marking this item ordered.");
} }
}); });
} }
@ -59,18 +60,16 @@ Template.listItemsTbl.events({
if (err) { if (err) {
console.log(" ERROR setting item as received: " + err); console.log(" ERROR setting item as received: " + err);
} else { } else {
console.log(" SUCCESS setting item received."); // console.log(" SUCCESS setting item received.");
} }
}); });
}, },
'click .deleteListItem' (event) { 'click .deleteListItem' (event) {
event.preventDefault(); event.preventDefault();
Meteor.call('delete.listItem', this._id, function(err, result) { Session.set("deleteId", this._id);
if (err) { Session.set("method", "delete.listItem");
console.log(" ERROR deleting the list item: " + err); Session.set("item", this.itemName);
} else { Session.set("view", "List Items");
console.log(" SUCCESS deleting the list item."); $('#modalDelete').modal('open');
}
});
}, },
}); });

View file

@ -48,7 +48,7 @@ Template.listsTbl.events({
console.log(" ERROR marking list complete! " + err); console.log(" ERROR marking list complete! " + err);
showSnackbar("ERROR! List Not Makred Complete!", "red"); showSnackbar("ERROR! List Not Makred Complete!", "red");
} else { } else {
console.log(" SUCCESS marking list complete."); // console.log(" SUCCESS marking list complete.");
showSnackbar("List Marked Complete!", "green"); showSnackbar("List Marked Complete!", "green");
} }
}); });

View file

@ -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.'); 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 }); return Categories.remove({ _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!");
}
}, },
}); });

View file

@ -29,7 +29,7 @@ Meteor.methods({
if (err) { if (err) {
console.log(" ERROR adding item to products: " + err); console.log(" ERROR adding item to products: " + err);
} else { } else {
console.log(" SUCCESS adding item to Products."); // console.log(" SUCCESS adding item to Products.");
return ListItems.insert({ return ListItems.insert({
itemName: itemName, itemName: itemName,
listId: listId, listId: listId,

View file

@ -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.'); 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 }); return Lists.remove({ _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!");
}
}, },
'mark.complete' (listId) { 'mark.complete' (listId) {
check(listId, String); check(listId, String);

View file

@ -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.'); 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 }); return Locations.remove({ _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!");
}
}, },
}); });

View file

@ -23,9 +23,6 @@ Meteor.methods({
shopName: shopName, shopName: shopName,
shopOwner: this.userId, shopOwner: this.userId,
}); });
},
'add.shopListUsers' (userIds) {
}, },
'edit.shopList' (shopId, shopName) { 'edit.shopList' (shopId, shopName) {
check(shopId, String); check(shopId, String);
@ -40,9 +37,6 @@ Meteor.methods({
shopName: shopName, shopName: shopName,
} }
}); });
},
'edit.shopListUsers' (shopId, userIds) {
}, },
'delete.shopList' (shopId) { 'delete.shopList' (shopId) {
check(shopId, String); 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.'); 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 }); return ShopLists.remove({ _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!");
}
}, },
}); });

View file

@ -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.'); 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 }); return Stores.remove({ _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!");
}
}, },
}); });

View file

@ -61,7 +61,7 @@ Meteor.publish("myLists", function() {
Meteor.publish("myListItems", function(listId) { Meteor.publish("myListItems", function(listId) {
try { try {
console.log("List Id is: " + listId); // console.log("List Id is: " + listId);
return ListItems.find({ listId: listId }); return ListItems.find({ listId: listId });
} catch (error) { } catch (error) {
console.log(" ERROR pulling list items for this list: " + error); console.log(" ERROR pulling list items for this list: " + error);