diff --git a/client/AdminMgmt/ProductMgmt/prodMgmtTbl.html b/client/AdminMgmt/ProductMgmt/prodMgmtTbl.html index e5db47c..80fc2d2 100644 --- a/client/AdminMgmt/ProductMgmt/prodMgmtTbl.html +++ b/client/AdminMgmt/ProductMgmt/prodMgmtTbl.html @@ -13,7 +13,15 @@ {{/if}} - Store + + {{#if $eq searchStore false}} + Store search + {{else}} +
+ close +
+ {{/if}} + Actions diff --git a/client/AdminMgmt/ProductMgmt/prodMgmtTbl.js b/client/AdminMgmt/ProductMgmt/prodMgmtTbl.js index d5cfcf1..1c98c8c 100644 --- a/client/AdminMgmt/ProductMgmt/prodMgmtTbl.js +++ b/client/AdminMgmt/ProductMgmt/prodMgmtTbl.js @@ -7,20 +7,38 @@ Template.prodMgmtTbl.onCreated(function() { Template.prodMgmtTbl.onRendered(function() { Session.set("searchProds", false); + Session.set("searchStore", false); }); Template.prodMgmtTbl.helpers({ products: function() { - let searchVal = Session.get("searchVal"); - if (typeof searchVal == 'undefined' || searchVal.length == 0) { - return Products.find({}); + 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' } }); + } } else { - return Products.find({ prodName: { $regex: searchVal + '.*', $options: 'i' } }); + return Products.find({}); } }, searchProd: function() { return Session.get("searchProds"); - } + }, + searchStore: function() { + return Session.get("searchStore"); + }, }); Template.prodMgmtTbl.events({ @@ -53,5 +71,19 @@ Template.prodMgmtTbl.events({ let searchVal = $("#searchProds").val(); Session.set("searchVal", searchVal); } + }, + '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); + } } }); \ No newline at end of file