2022-08-15 18:07:39 -05:00
|
|
|
import { Products } from '../../../imports/api/products.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");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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);
|
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");
|
|
|
|
|
|
|
|
|
|
if (searchProd == true) {
|
|
|
|
|
let searchVal = Session.get("searchVal");
|
|
|
|
|
if (typeof searchVal == 'undefined' || searchVal.length == 0) {
|
|
|
|
|
return Products.find({});
|
|
|
|
|
} else {
|
|
|
|
|
return Products.find({ prodName: { $regex: searchVal + '.*', $options: 'i' } });
|
|
|
|
|
}
|
|
|
|
|
} else if (searchStore == true) {
|
|
|
|
|
let searchVal = Session.get("searchStoreVal");
|
|
|
|
|
if (typeof searchVal == 'undefined' || searchVal.length == 0) {
|
|
|
|
|
return Products.find({});
|
|
|
|
|
} else {
|
|
|
|
|
return Products.find({ prodStore: { $regex: searchVal + '.*', $options: 'i' } });
|
|
|
|
|
}
|
2022-08-25 15:39:27 -05:00
|
|
|
} else {
|
2024-07-26 11:58:03 -05:00
|
|
|
return Products.find({});
|
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);
|
|
|
|
|
let prodInfo = Products.findOne({ _id: this._id });
|
|
|
|
|
$("#prodName").val(prodInfo.prodName);
|
|
|
|
|
$("#prodStore").val(prodInfo.prodStore);
|
2024-07-23 12:01:33 -05:00
|
|
|
// $('select').formSelect();
|
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
|
|
|
}
|
2022-08-15 18:07:39 -05:00
|
|
|
});
|