mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
Updaated Products to have multiple associated stores.
- Products will be updated on first start of server to make sure the store attribute is set as an Array of values. - You can edit Products to add more associated stores - Products will list all associated stores on the product table view - Cut down method calls to single event trigger for adding / editing products info
This commit is contained in:
parent
a7a9c48e01
commit
3f6618d906
4 changed files with 56 additions and 96 deletions
|
|
@ -14,16 +14,17 @@
|
|||
<input type="text" class="prodName" style="{{#if $eq prodNameErr true}}border: 2px solid red;{{/if}}" id="prodName" />
|
||||
<label for="prodName">Name*</label>
|
||||
</div>
|
||||
<div class="col s12 m6 l6 input-field outlined">
|
||||
<select name="prodStore" id="prodStore">
|
||||
<option value="" disabled selected></option>
|
||||
<option id="addNewStore" value="addNewStore" class="modal-trigger" data-target="modalStore">+ Add New Store</option>
|
||||
<div class="col s12 m4 l4 input-field outlined">
|
||||
<select name="prodStore" id="prodStore" multiple>
|
||||
{{#each stores}}
|
||||
<option value="{{storeName}}">{{storeName}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
<label for="prodStore">Store</label>
|
||||
</div>
|
||||
<div class="col s12 m2 l2">
|
||||
<a class="btn waves-light waves-effect blue white-text modal-trigger" id="addNewStore" href="#modalStore">+ Add Store</a>
|
||||
</div>
|
||||
<div class="col s12 m12 l12">
|
||||
{{#if $eq prodEditMode false}}
|
||||
<a class="waves-effect waves-light btn saveProdMgmt green white-text right">Add</a>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue