import { Stores } from '../../../imports/api/stores';

Template.storeMgmtTbl.onCreated(function() {
    this.subscribe("storeInfo");
});

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

Template.storeMgmtTbl.helpers({
    mgmtStoreInfo: function() {
        return Stores.find({});
    },
});

Template.storeMgmtTbl.events({
    'click .deleteStore' (event) {
        event.preventDefault();
        Meteor.call('delete.store', this._id, function(err, result) {
            if (err) {
                console.log("    ERROR deleting store: " + err);
            } else {
                console.log("    SUCCESS deleting the store.");
            }
        });
    },
    'click .editStore' (event) {
        event.preventDefault();
        Session.set("storeIdEdit", this._id);
        let storeInfo = Stores.findOne({ _id: this._id });
        $("#storeName").val(storeInfo.storeName);
        Session.set("editModeStore", true);
    },
});