/**
 * Created by Daniel on 9/12/2016.
 */
//Template events
Template.payslipActionCell.events({
    "click .send-email-button": function (event, temp) {
        Meteor.call("sendPayslip",$(event.currentTarget).attr("data-payslip-id"), function(err,res){
            if(!err){
                // Payslips.update({_id:res},{$set: { status: 'SENT' }});
                Payslips.remove({_id:res});
                FlashMessages.sendSuccess("The Payslip has been sent successfully.", {autoHide: true, hideDelay: 5000});
            }
        });        
    },
    "click .resend-email-button": function (event, temp) {
        Meteor.call("sendPayslip",$(event.currentTarget).attr("data-payslip-id"), function(err,res){
            if(!err){
                Payslips.remove({_id:res});
                FlashMessages.sendSuccess("The Payslip has been re-sent successfully.", {autoHide: true, hideDelay: 5000});
            }
        });        
    },
});

Template.payslipActionCell.helpers({
	payslip: function () {
        return this;
    },
    isNewPayslip: function(){
        return (this.status === 'NEW')?true:false;
    },
    onError: function () {
        return function (error) {
            alert("Error on deleting!");
            console.log(error);
        };
    },
    onSuccess: function () {
        return function (result) {
            alert("Deleted!");
        };
    },
    beforeRemove: function () {
        return function (collection, id) {
            var doc = collection.findOne(id);
            if (confirm('Really delete question "' + doc.name + '"?')) {
});
                this.remove();
            }
        };
    }