mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-26 15:58:50 +00:00
91 lines
No EOL
2.6 KiB
JavaScript
91 lines
No EOL
2.6 KiB
JavaScript
import { Products } from '../../../imports/api/products.js';
|
|
import { Stores } from '../../../imports/api/stores.js';
|
|
import { M } from '../../lib/assets/materialize.js';
|
|
|
|
Template.prodMgmtForm.onCreated(function() {
|
|
this.subscribe("myProducts");
|
|
this.subscribe("storeInfo");
|
|
});
|
|
|
|
Template.prodMgmtForm.onRendered(function() {
|
|
setTimeout(function() {
|
|
var elems = document.querySelectorAll('select');
|
|
var instances = M.FormSelect.init(elems, {});
|
|
}, 200);
|
|
|
|
var elemm = document.querySelectorAll('.modal');
|
|
var instancem = M.Modal.init(elemm, {});
|
|
|
|
Session.set("prodEditMode", false);
|
|
});
|
|
|
|
Template.prodMgmtForm.helpers({
|
|
stores: function() {
|
|
return Stores.find({});
|
|
},
|
|
prodNameErr: function() {
|
|
return Session.get("prodNameRed");
|
|
},
|
|
prodEditMode: function() {
|
|
return Session.get("prodEditMode");
|
|
},
|
|
});
|
|
|
|
Template.prodMgmtForm.events({
|
|
'click .saveProdMgmt, click .editProdMgmt' (event) {
|
|
let name = $("#prodName").val();
|
|
let store = $("#prodStore").val();
|
|
let prodId = Session.get("prodEditId");
|
|
let prodEditMode = Session.get("prodEditMode");
|
|
if (store == null) {
|
|
store = "";
|
|
}
|
|
if (name == "" || name == null) {
|
|
Session.set("prodNameRed", true);
|
|
return;
|
|
} else {
|
|
if (prodEditMode == true) {
|
|
editProd(prodId, name, store);
|
|
} else {
|
|
newProd(name, store);
|
|
}
|
|
}
|
|
},
|
|
'click #showNoStoreSet' (event) {
|
|
let noStoreSet = $("#showNoStoreSet").prop('checked');
|
|
console.log("Clicked: " + noStoreSet);
|
|
if (noStoreSet == true) {
|
|
Session.set("noStoreSet", true);
|
|
} else {
|
|
Session.set("noStoreSet", false);
|
|
}
|
|
},
|
|
'submit .prodInputForm' (event) {
|
|
|
|
},
|
|
});
|
|
|
|
const newProd = async(name, store) => {
|
|
let result = await Meteor.callAsync('add.product', name, store);
|
|
try {
|
|
if (!result) {
|
|
console.log("No result when trying to add a new product.");
|
|
showSnackbar("Unable to add new product.");
|
|
} else {
|
|
$("#prodName").val("");
|
|
showSnackbar("New Product Added!", "green");
|
|
}
|
|
} catch(error) {
|
|
console.log(" ERROR - couldn't add product: " + error);
|
|
}
|
|
}
|
|
|
|
const editProd = async(prodId, name, store) => {
|
|
let result = await Meteor.callAsync('edit.product', prodId, name, store);
|
|
if (!result) {
|
|
console.log(" ERROR: can't add product: " + err);
|
|
} else {
|
|
$("#prodName").val("");
|
|
showSnackbar("Successfully Edited Product!", "green");
|
|
}
|
|
} |