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();
        Session.set("deleteId", this._id);
        Session.set("method", "delete.store");
        Session.set("item", this.storeName);
        Session.set("view", "Stores");
        $('#modalDelete').modal('open');
    },
    '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);
    },
});