import { Categories } from '../../../imports/api/category.js';

Template.catMgmtTbl.onCreated(function() {
    this.subscribe("myCategories");
});

Template.catMgmtTbl.onRendered(function() {
    Meteor.setTimeout(function() {
        $('.tooltipped').tooltip();
    }, 150);
});

Template.catMgmtTbl.helpers({
    cats: function() {
        return Categories.find({});
    }
});

Template.catMgmtTbl.events({
    'click .deleteCategory' (event) {
        event.preventDefault();
        Session.set("deleteId", this._id);
        Session.set("method", "delete.category");
        Session.set("item", this.categoryName);
        Session.set("view", "Categories");
        $('#modalDelete').modal('open');
    },
    '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);
    }
});