Many chcanges, but version 0.1.0 is ready to be cut.

This commit is contained in:
Brian McGonagill 2022-08-23 13:41:21 -05:00
parent 42643a37f5
commit 6e37ae8c74
46 changed files with 1038 additions and 273 deletions

View file

@ -1,6 +1,8 @@
<template name="catMgmt">
<h4>Category Management</h4>
{{> catMgmtForm}}
<hr>
{{> catMgmtTbl}}
<div class="container">
<h4>Category Management</h4>
{{> catMgmtForm}}
<hr>
{{> catMgmtTbl}}
</div>
</template>

View file

@ -1,16 +1,22 @@
<template name="catMgmtForm">
<div class="row">
<div class="col s12 m6 l6 input-field">
<input type="text" class="catNameInp" id="catNameInp" style="{{#if $eq catNameErr true}}border: 2px solid red;{{/if}}" />
<label for="catNameInp">Name*</label>
<form action="submit" id="catInputForm">
<div class="row">
<div class="col s12 m6 l6 input-field">
<input type="text" class="catNameInp" id="catNameInp" style="{{#if $eq catNameErr true}}border: 2px solid red;{{/if}}" />
<label for="catNameInp">Name*</label>
</div>
</div>
</div>
<div class="row">
<div class="col s6 m6 l6">
<a class="waves-effect waves-light btn cancelCatMgmt orange">Cancel</a>
<div class="row">
<div class="col s6 m6 l6">
<a class="waves-effect waves-light btn cancelCatMgmt orange">Cancel</a>
</div>
<div class="col s6 m6 l6">
{{#if $eq catEditMode false}}
<a class="waves-effect waves-light btn saveCatMgmt green right">Add</a>
{{else}}
<a class="waves-effect waves-light btn editCatMgmt blue right">Rename</a>
{{/if}}
</div>
</div>
<div class="col s6 m6 l6">
<a class="waves-effect waves-light btn saveCatMgmt green right">Add</a>
</div>
</div>
</form>
</template>

View file

@ -6,12 +6,16 @@ Template.catMgmtForm.onCreated(function() {
Template.catMgmtForm.onRendered(function() {
Session.set("catNameMiss", false);
Session.set("catEditMode", false);
});
Template.catMgmtForm.helpers({
catNameErr: function() {
return Session.get("catNameMiss");
},
catEditMode: function() {
return Session.get("catEditMode");
}
});
Template.catMgmtForm.events({
@ -32,8 +36,60 @@ Template.catMgmtForm.events({
});
}
},
'click .editCatMgmt' (event) {
event.preventDefault();
let catName = $("#catNameInp").val();
let catId = this._id;
if (catName == null || catName == "") {
Session.set("catNameMiss", true);
return;
} else {
let catId = Session.get("categoryEditId");
Meteor.call('edit.category', catId, catName, function(err, result) {
if (err) {
// console.log(" ERROR: Can't edit category: " + err);
} else {
// console.log(" SUCCESS editing category.");
$("#catNameInp").val("");
Session.set("catEditMode", false);
}
});
}
},
'submit #catInputForm' (event) {
event.preventDefault();
let catName = $("#catNameInp").val();
let editMode = Session.get("catEditMode");
if (catName == null || catName == "") {
Session.set("catNameMiss", true);
return;
} else {
if (editMode == false) {
Meteor.call('add.category', catName, function(err, result) {
if (err) {
// console.log(" ERROR: Can't add category: " + err);
} else {
// console.log(" SUCCESS adding category.");
$("#catNameInp").val("");
}
});
} else {
let catId = Session.get("categoryEditId");
Meteor.call('edit.category', catId, catName, function(err, result) {
if (err) {
// console.log(" ERROR: Can't edit category: " + err);
} else {
// console.log(" SUCCESS editing category.");
$("#catNameInp").val("");
Session.set("catEditMode", false);
}
});
}
}
},
'click .cancelCatMgmt' (event) {
event.preventDefault();
$("#catNameInp").val("");
Session.set("catEditMode", false);
}
});

View file

@ -5,8 +5,8 @@
{{#each cats}}
<li class="collection-item">
{{categoryName}}
<i class="material-icons clickable deleteCategory right">delete</i>
<i class="material-icons clickable editCategory right">edit</i>
<i class="material-icons clickable deleteCategory right tooltipped" data-position="top" data-tooltip="Delete Category">delete</i>
<i class="material-icons clickable editCategory right tooltipped" data-position="top" data-tooltip="Edit Category">edit</i>
</li>
{{/each}}
</ul>

View file

@ -5,7 +5,9 @@ Template.catMgmtTbl.onCreated(function() {
});
Template.catMgmtTbl.onRendered(function() {
Meteor.setTimeout(function() {
$('.tooltipped').tooltip();
}, 150);
});
Template.catMgmtTbl.helpers({
@ -15,5 +17,21 @@ Template.catMgmtTbl.helpers({
});
Template.catMgmtTbl.events({
'click .deleteCategory' (event) {
event.preventDefault();
Meteor.call('delete.category', this._id, function(err, result) {
if (err) {
console.log(" ERROR deleting category: " + err);
} else {
console.log(" SUCCESS deleting the category.");
}
});
},
'click .editCategory' (event) {
event.preventDefault();
Session.set("categoryEditId", this._id);
Session.set("catEditMode", true);
let catInfo = Categories.findOne({ _id: this._id });
$("#catNameInp").val(catInfo.categoryName);
}
});