mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
Add list items from linked menu items
This commit is contained in:
parent
91150f03b2
commit
00a99e0393
11 changed files with 203 additions and 5 deletions
47
client/MenuItems/addProdToListModal.html
Normal file
47
client/MenuItems/addProdToListModal.html
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<template name="addProdToListModal">
|
||||
<div class="modal" id="addProdToList">
|
||||
<div class="modal-content">
|
||||
<h2>Add Items to List</h2>
|
||||
<form class="row" style="gap: 1em;">
|
||||
<div class="col s12 input-field outlined" id="chooseListDiv">
|
||||
<select name="chooseList" id="chooseList">
|
||||
{{#each setOfLists}}
|
||||
<option value="{{_id}}">{{listName}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col s12">
|
||||
<ul class="collection with-header">
|
||||
<li class="collection-header">
|
||||
<h4>Products to Add</h4>
|
||||
</li>
|
||||
{{#each productToChoose}}
|
||||
<li class="collection-item" id="{{prodId}}">
|
||||
<div>
|
||||
<p>
|
||||
<label>
|
||||
<input type="checkbox" class="productListing" id="{{prodId}}" />
|
||||
<span class="my-text">{{prodName}}</span>
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="row">
|
||||
<div class="col s12 m6 l6">
|
||||
<a class="left btn waves-effect waves-light orange white-text modal-close">Cancel</a>
|
||||
</div>
|
||||
<div class="col s12 m6 l6">
|
||||
<a class="btn waves-effect waves-light green white-text saveProdsToList" id="saveProdsToList">Save to List</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{{> snackbar}}
|
||||
</template>
|
||||
64
client/MenuItems/addProdToListModal.js
Normal file
64
client/MenuItems/addProdToListModal.js
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import { M } from '../lib/assets/materialize.js';
|
||||
import { MenuProdLinks } from '../../imports/api/menuProdLinks';
|
||||
import { Products } from '../../imports/api/products.js';
|
||||
import { Lists } from '../../imports/api/lists.js';
|
||||
import { ListItems } from '../../imports/api/listItems';
|
||||
|
||||
Template.addProdToListModal.onCreated(function() {
|
||||
this.subscribe("myProducts");
|
||||
this.subscribe("myLists");
|
||||
this.subscribe("myListItems");
|
||||
this.subscribe("menuProdLinkData");
|
||||
});
|
||||
|
||||
Template.addProdToListModal.onRendered(function() {
|
||||
var elems = document.querySelectorAll('select');
|
||||
var instances = M.FormSelect.init(elems, {});
|
||||
|
||||
Session.set("itemsSelected", []);
|
||||
});
|
||||
|
||||
Template.addProdToListModal.helpers({
|
||||
assocProds: function() {
|
||||
let menuItemId = Session.get("menuItemId");
|
||||
let assocProds = MenuProdLinks.find({ menuItemId: menuItemId });
|
||||
if (typeof assocProds != 'undefined' && assocProds != '' && assocProds != null) {
|
||||
return assocProds;
|
||||
}
|
||||
},
|
||||
setOfLists: function() {
|
||||
return Lists.find({});
|
||||
},
|
||||
productToChoose: function() {
|
||||
let prodLinkLIst = MenuProdLinks.find({ menuId: Session.get("menuItemId")});
|
||||
if (typeof prodLinkLIst != 'undefined' && prodLinkLIst != "" && prodLinkLIst != null) {
|
||||
return prodLinkLIst;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Template.addProdToListModal.events({
|
||||
'click .productListing' (event) {
|
||||
let itemId = event.currentTarget.id;
|
||||
let selected = Session.get("itemsSelected");
|
||||
console.log("Item clicked: " + itemId);
|
||||
selected.push(itemId);
|
||||
console.dir(selected);
|
||||
Session.set("itemsSelected", selected);
|
||||
},
|
||||
'click #saveProdsToList' (event) {
|
||||
event.preventDefault();
|
||||
let selectedItems = Session.get("itemsSelected");
|
||||
let listId = $("#chooseList").val();
|
||||
// console.log(" calling meteor method with items: ");
|
||||
// console.dir(selectedItems);
|
||||
// console.log(" and list id: "+ listId);
|
||||
Meteor.call('add.itemsFromMenuItem', selectedItems, listId, function(err, result) {
|
||||
if (err) {
|
||||
console.log(" ERROR adding menu components to list: " + err);
|
||||
} else {
|
||||
showSnackbar("Items Added to List!", "green");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
<tr>
|
||||
<th>Menu Item</th>
|
||||
<th>Date to Serve</th>
|
||||
<th>Has Product Links</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
@ -23,6 +24,9 @@
|
|||
<td>
|
||||
{{serveDate}}
|
||||
</td>
|
||||
<td>
|
||||
{{#if $eq isLinked true}}<a class="waves-effect waves-light blue darken-3 white-text btn addProdsToList modal-trigger" href="#addProdToList">+ Shopping List</a>{{/if}}
|
||||
</td>
|
||||
<td>
|
||||
<i class="material-icons tooltipped modal-trigger deleteMenuItem clickable" href="#modalDelete" data-position="top" data-tooltip-id="deleteMenuTip">delete</i>
|
||||
<i class="material-icons tooltipped modal-trigger linkToProducts clickable" href="#modalLinkProducts" data-position="top" data-tooltip-id="linkMenuTip">link</i>
|
||||
|
|
@ -36,4 +40,5 @@
|
|||
</div>
|
||||
{{> deleteConfirmationModal}}
|
||||
{{> modalLinkProducts}}
|
||||
{{> addProdToListModal}}
|
||||
</template>
|
||||
|
|
@ -37,5 +37,9 @@ Template.menuItemsTbl.events({
|
|||
'click .linkToProducts' (event) {
|
||||
event.preventDefault();
|
||||
Session.set("menuItemId", this._id);
|
||||
},
|
||||
'click .addProdsToList' (event) {
|
||||
event.preventDefault();
|
||||
Session.set("menuItemId", this._id);
|
||||
}
|
||||
});
|
||||
|
|
@ -43,7 +43,13 @@ Template.modalLinkProducts.events({
|
|||
if (err) {
|
||||
console.log(" ERROR adding product links to this menu item: " + err);
|
||||
} else {
|
||||
showSnackbar("Products added to Menu Item successfully!", "green");
|
||||
Meteor.call('update.menuItemLinked', menuItemId, true, function(err, result) {
|
||||
if (err) {
|
||||
console.log(" ERROR adding link exists to menu item: " + err);
|
||||
} else {
|
||||
showSnackbar("Products added to Menu Item successfully!", "green");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue