2022-08-15 18:07:39 -05:00
|
|
|
import { Products } from '../../../imports/api/products.js';
|
2025-08-09 07:21:46 -05:00
|
|
|
import { ListItems } from '../../../imports/api/listItems.js';
|
2024-07-23 12:01:33 -05:00
|
|
|
import { M } from '../../lib/assets/materialize.js';
|
2022-08-15 18:07:39 -05:00
|
|
|
|
|
|
|
|
Template.prodMgmtTbl.onCreated(function() {
|
|
|
|
|
this.subscribe("myProducts");
|
2025-08-09 07:21:46 -05:00
|
|
|
this.subscribe("allListItems");
|
2022-08-15 18:07:39 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Template.prodMgmtTbl.onRendered(function() {
|
2022-08-25 15:39:27 -05:00
|
|
|
Session.set("searchProds", false);
|
2024-07-26 11:58:03 -05:00
|
|
|
Session.set("searchStore", false);
|
2024-08-09 12:03:49 -05:00
|
|
|
Session.set("noStoreSet", false);
|
2025-08-09 07:21:46 -05:00
|
|
|
Session.set("noListUsed", false);
|
2022-08-15 18:07:39 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Template.prodMgmtTbl.helpers({
|
|
|
|
|
products: function() {
|
2024-07-26 11:58:03 -05:00
|
|
|
let searchProd = Session.get("searchProds");
|
|
|
|
|
let searchStore = Session.get("searchStore");
|
2024-08-09 12:03:49 -05:00
|
|
|
let noStoreSet = Session.get("noStoreSet");
|
2025-08-09 07:21:46 -05:00
|
|
|
let noListUsed = Session.get("noListUsed");
|
2024-07-26 11:58:03 -05:00
|
|
|
|
|
|
|
|
if (searchProd == true) {
|
|
|
|
|
let searchVal = Session.get("searchVal");
|
|
|
|
|
if (typeof searchVal == 'undefined' || searchVal.length == 0) {
|
|
|
|
|
return Products.find({});
|
|
|
|
|
} else {
|
2024-08-18 09:59:58 -05:00
|
|
|
return Products.find({ prodName: { $regex: searchVal + '.*', $options: 'i' } }, { sort: { prodName: 1 }});
|
2024-07-26 11:58:03 -05:00
|
|
|
}
|
|
|
|
|
} else if (searchStore == true) {
|
|
|
|
|
let searchVal = Session.get("searchStoreVal");
|
|
|
|
|
if (typeof searchVal == 'undefined' || searchVal.length == 0) {
|
|
|
|
|
return Products.find({});
|
|
|
|
|
} else {
|
2024-08-18 09:59:58 -05:00
|
|
|
return Products.find({ prodStore: { $regex: searchVal + '.*', $options: 'i' } }, { sort: { prodName: 1 }});
|
2024-07-26 11:58:03 -05:00
|
|
|
}
|
2024-08-09 12:03:49 -05:00
|
|
|
} else if (noStoreSet == true) {
|
2024-08-18 09:59:58 -05:00
|
|
|
return Products.find({ prodStore: '' }, { sort: { prodName: 1 }});
|
2025-08-09 07:21:46 -05:00
|
|
|
} else if (noListUsed == true) {
|
|
|
|
|
let i;
|
|
|
|
|
let idList = [];
|
|
|
|
|
let idsInLists = ListItems.find({}).fetch();
|
|
|
|
|
for (i=0; i < idsInLists.length; i++) {
|
|
|
|
|
idList.push(idsInLists[i].prodId);
|
|
|
|
|
}
|
|
|
|
|
if (i > idsInLists.length - 1) {
|
|
|
|
|
let noProdsNot = Products.find({ _id: { $nin: idList }}).count();
|
|
|
|
|
return Products.find({ _id: { $nin: idList }}, { sort: { prodName: 1 }});
|
|
|
|
|
}
|
2022-08-25 15:39:27 -05:00
|
|
|
} else {
|
2024-08-18 09:59:58 -05:00
|
|
|
return Products.find({}, { sort: { prodName: 1 }});
|
2022-08-25 15:39:27 -05:00
|
|
|
}
|
2022-08-15 18:07:39 -05:00
|
|
|
},
|
2022-08-25 15:39:27 -05:00
|
|
|
searchProd: function() {
|
|
|
|
|
return Session.get("searchProds");
|
2024-07-26 11:58:03 -05:00
|
|
|
},
|
|
|
|
|
searchStore: function() {
|
|
|
|
|
return Session.get("searchStore");
|
|
|
|
|
},
|
2022-08-15 18:07:39 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Template.prodMgmtTbl.events({
|
2022-08-23 13:41:21 -05:00
|
|
|
'click .deleteProduct' (event) {
|
|
|
|
|
event.preventDefault();
|
2022-08-26 11:18:18 -05:00
|
|
|
Session.set("deleteId", this._id);
|
|
|
|
|
Session.set("method", "delete.product");
|
|
|
|
|
Session.set("item", this.prodName);
|
|
|
|
|
Session.set("view", "Products");;
|
2022-08-23 13:41:21 -05:00
|
|
|
},
|
|
|
|
|
'click .editProduct' (event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
Session.set("prodEditMode", true);
|
|
|
|
|
Session.set("prodEditId", this._id);
|
2025-06-21 07:28:59 -05:00
|
|
|
const getProds = async() => {
|
|
|
|
|
let prodInfo = await Products.findOneAsync({ _id: this._id });
|
|
|
|
|
if (!prodInfo) {
|
2025-07-23 19:44:24 -05:00
|
|
|
// console.log("No Product Returned.");
|
2025-06-21 07:28:59 -05:00
|
|
|
} else {
|
|
|
|
|
$("#prodName").val(prodInfo.prodName);
|
|
|
|
|
$("#prodStore").val(prodInfo.prodStore);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
getProds();
|
|
|
|
|
|
2022-08-25 15:39:27 -05:00
|
|
|
},
|
|
|
|
|
'click #filterProds' (event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
Session.set("searchProds", true);
|
|
|
|
|
},
|
|
|
|
|
'click #closeFilter' (event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
Session.set("searchProds", false);
|
|
|
|
|
},
|
|
|
|
|
"keyup #searchProds" (event) {
|
|
|
|
|
if (event.which !== 13) {
|
|
|
|
|
let searchVal = $("#searchProds").val();
|
|
|
|
|
Session.set("searchVal", searchVal);
|
|
|
|
|
}
|
2024-07-26 11:58:03 -05:00
|
|
|
},
|
|
|
|
|
'click #filterStore' (event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
Session.set("searchStore", true);
|
|
|
|
|
},
|
|
|
|
|
'click #closeStoreFilter' (event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
Session.set("searchStore", false);
|
|
|
|
|
},
|
|
|
|
|
'keyup #searchStore' (event) {
|
|
|
|
|
if (event.which !== 13) {
|
|
|
|
|
let searchVal = $("#searchStore").val();
|
|
|
|
|
Session.set("searchStoreVal", searchVal);
|
|
|
|
|
}
|
2022-08-23 13:41:21 -05:00
|
|
|
}
|
2024-08-09 12:03:49 -05:00
|
|
|
});
|