import { Products } from '../../../imports/api/products.js'; import { Stores } from '../../../imports/api/stores.js'; import { Categories } from '../../../imports/api/category.js'; import { Locations } from '../../../imports/api/location.js'; Template.prodMgmtForm.onCreated(function() { this.subscribe("myProducts"); this.subscribe("storeInfo"); this.subscribe("myCategories"); this.subscribe("myLocations"); }); Template.prodMgmtForm.onRendered(function() { Meteor.setTimeout(function() { $('select').formSelect(); }, 200); $('select').formSelect(); $('.modal').modal(); }); Template.prodMgmtForm.helpers({ stores: function() { return Stores.find({}); }, prodNameErr: function() { return Session.get("prodNameRed"); }, category: function() { return Categories.find({}); }, locations: function() { return Locations.find({}); }, }); Template.prodMgmtForm.events({ 'click .saveProdMgmt' (event) { event.preventDefault(); let name=$("#prodName").val(); let cat = $("#prodCategory").val(); let store = $("#prodStore").val(); let location = $("#prodLocation").val(); if (cat == null) { cat = ""; } if (location == null) { location = ""; } if (store == null) { store = ""; } if (name == "" || name == null) { Session.set("prodNameRed", true); return; } else { Meteor.call('add.product', name, cat, store, location, function(err, result) { if (err) { // console.log(" ERROR: can't add product: " + err); } else { // console.log(" SUCCESS adding product."); $("#prodName").val(""); $("#prodCategory").val(""); $("#prodStore").val(""); $("#prodLocation").val(""); } }); } }, 'click .cancelProdMgmt' (event) { event.preventDefault(); $("#prodName").val(""); $("#prodCategory").val(""); $("#prodStore").val(""); $("#prodLocation").val(""); }, 'change #prodStore' (event) { event.preventDefault(); let val = $("#prodStore").val(); if (val == "addNewStore") { $("#prodStore").val(""); // open a modal to enter store information. $('#modalStore').modal('open'); } }, 'change #prodLocation' (event) { event.preventDefault(); let val = $("#prodLocation").val(); if (val == "addNewLocation") { $("#prodLocation").val(""); // open a modal to enter store information. $('#modalLocation').modal('open'); } }, 'change #prodCategory' (event) { event.preventDefault(); let val = $("#prodCategory").val(); if (val == "addNewCat") { $("#prodCategory").val(""); // open a modal to enter store information. $('#modalCategory').modal('open'); } }, 'click .modal-close' (event) { $('select').formSelect(); } });