diff --git a/client/AdminMgmt/ProductMgmt/prodMgmtForm.html b/client/AdminMgmt/ProductMgmt/prodMgmtForm.html index fb1be33..357b19c 100644 --- a/client/AdminMgmt/ProductMgmt/prodMgmtForm.html +++ b/client/AdminMgmt/ProductMgmt/prodMgmtForm.html @@ -14,16 +14,17 @@ -
- {{#each stores}} {{/each}}
+
+ + Add Store +
{{#if $eq prodEditMode false}} Add diff --git a/client/AdminMgmt/ProductMgmt/prodMgmtForm.js b/client/AdminMgmt/ProductMgmt/prodMgmtForm.js index 6f096bb..d133fd8 100644 --- a/client/AdminMgmt/ProductMgmt/prodMgmtForm.js +++ b/client/AdminMgmt/ProductMgmt/prodMgmtForm.js @@ -32,36 +32,12 @@ Template.prodMgmtForm.helpers({ }); Template.prodMgmtForm.events({ - 'click .saveProdMgmt' (event) { - event.preventDefault(); + 'click .saveProdMgmt, click .editProdMgmt' (event) { let name = $("#prodName").val(); let store = $("#prodStore").val(); - if (store == null) { - store = ""; - } - - if (name == "" || name == null) { - Session.set("prodNameRed", true); - return; - } else { - Meteor.call('add.product', name, store, function(err, result) { - if (err) { - console.log(" ERROR: can't add product: " + err); - } else { - $("#prodName").val(""); - let elemse = document.querySelectorAll('select'); - let instancese = M.FormSelect.init(elemse, {}); - showSnackbar("Succesffuly Added Product!", "green"); - } - }); - } - }, - 'click .editProdMgmt' (event) { - event.preventDefault(); - let name = $("#prodName").val(); let prodId = Session.get("prodEditId"); - let store = $("#prodStore").val(); + let prodEditMode = Session.get("prodEditMode"); if (store == null) { store = ""; @@ -71,71 +47,27 @@ Template.prodMgmtForm.events({ Session.set("prodNameRed", true); return; } else { - Meteor.call('edit.product', prodId, name, store, function(err, result) { - if (err) { - // console.log(" ERROR: can't add product: " + err); - } else { - $("#prodName").val(""); - Session.set("prodEditMode", false); - showSnackbar("Product Edited Successfully!", "green"); - } - }); - } - }, - 'keypress form.prodInputForm' (event) { - // event.preventDefault(); - if (event.which === 13) { - let name = $("#prodName").val(); - let store = $("#prodStore").val(); - let prodId = Session.get("prodEditId"); - let prodEditMode = Session.get("prodEditMode"); - // console.log(" ---- got the submit event for products."); - - if (store == null) { - store = ""; - } - - if (name == "" || name == null) { - Session.set("prodNameRed", true); - return; + if (prodEditMode == true) { + Meteor.call('edit.product', prodId, name, store, function(err, result) { + if (err) { + console.log(" ERROR: can't add product: " + err); + } else { + $("#prodName").val(""); + showSnackbar("Successfully Edited Product!", "green"); + } + }); } else { - if (prodEditMode == true) { - Meteor.call('edit.product', prodId, name, store, function(err, result) { - if (err) { - console.log(" ERROR: can't add product: " + err); - } else { - $("#prodName").val(""); - showSnackbar("Successfully Edited Product!", "green"); - } - }); - } else { - Meteor.call('add.product', name, store, function(err, result) { - if (err) { - console.log(" ERROR: can't add product: " + err); - } else { - $("#prodName").val(""); - showSnackbar("Product Added Succssfully!", "green"); - } - }); - } + Meteor.call('add.product', name, store, function(err, result) { + if (err) { + console.log(" ERROR: can't add product: " + err); + } else { + $("#prodName").val(""); + showSnackbar("Product Added Succssfully!", "green"); + } + }); } } }, - 'change #prodStore' (event) { - // event.preventDefault(); - console.log("detected event"); - let val = $("#prodStore").val(); - console.log("Value detected: " + val); - - if (val == "addNewStore") { - console.log("got the request for modal."); - $("#prodStore").val(""); - // open modal to add a new store - let elemmm = document.getElementById('modalStore'); - let storeModal = M.Modal.getInstance(elemmm); - storeModal.open(); - } - }, 'click #showNoStoreSet' (event) { let noStoreSet = $("#showNoStoreSet").prop('checked'); console.log("Clicked: " + noStoreSet); diff --git a/imports/api/products.js b/imports/api/products.js index 4e81e00..965346e 100644 --- a/imports/api/products.js +++ b/imports/api/products.js @@ -14,7 +14,7 @@ Products.allow({ Meteor.methods({ 'add.product' (prodName, prodStore) { check(prodName, String); - check(prodStore, String); + check(prodStore, [String]); if (!this.userId) { throw new Meteor.Error('You are not allowed to add products. Make sure you are logged in with valid user credentials.'); @@ -29,7 +29,7 @@ Meteor.methods({ 'edit.product' (prodId, prodName, prodStore) { check(prodId, String); check(prodName, String); - check(prodStore, String); + check(prodStore, [String]); if (!this.userId) { throw new Meteor.Error('You are not allowed to edit products. Make sure you are logged in with valid user credentials.'); @@ -51,4 +51,4 @@ Meteor.methods({ return Products.remove({ _id: prodId }); } -}); \ No newline at end of file +}); diff --git a/server/main.js b/server/main.js index ce57672..76c1c6a 100644 --- a/server/main.js +++ b/server/main.js @@ -1,6 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { SysConfig } from '../imports/api/systemConfig'; import { MenuItems } from '../imports/api/menuItems'; +import { Products } from '../imports/api/products.js'; Meteor.startup(() => { // code to run on server at startup @@ -22,7 +23,7 @@ Meteor.startup(() => { // check if the isLInked item exists on menuitems, and if not, add it (data cleanup task) let itemInfoNoLink = MenuItems.find({ isLinked: { $exists: false } }).fetch(); - console.log("No Ites with isLinked not set: " + itemInfoNoLink.length); + // console.log("No Ites with isLinked not set: " + itemInfoNoLink.length); if (itemInfoNoLink.length > 0) { // console.log("found items with isLinked not set."); // console.dir(itemInfoNoLink); @@ -36,7 +37,33 @@ Meteor.startup(() => { } } else { // this will show if all items are found to have isLInked set. - // console.log("No itesm with isLinked not set."); + console.log("No itesm with isLinked not set."); } + // update Products to be able to have multiple stores in the document + let prodInfo = Products.find({}).fetch(); + let prodCount = prodInfo.length; + console.log("Updating Products to allow multiple store assocation for " + prodCount + " products."); + for (j = 0; j < prodCount; j++) { + if (typeof prodInfo[j].prodStore == 'object') { + // console.log(typeof prodInfo[j].prodStore); + // console.log("Is Array already"); + } else { + let prodStoreArray = []; + // console.log("---- ---- ----"); + // console.log(typeof prodInfo[j].prodStore); + // console.log("---- Is Not Array."); + let prodStore = prodInfo[j].prodStore; + + prodStoreArray.push(prodStore); + // console.dir(prodStoreArray); + Products.update({ _id: prodInfo[j]._id }, { + $set: { + prodStore: prodStoreArray, + } + }); + } + } + + });