<commit_before>/*****************************************************************************/
/* EmployeePaymentDetailsDataModal: Event Handlers */
/*****************************************************************************/
Template.EmployeePaymentDetailsDataModal.events({
  'click #save-close': (e, tmpl) => {
    Modal.hide('EmployeePaymentDetailsDataModal');
  },
  'click #save': (e, tmpl) => {
    let user = Template.instance().getEditUser();
    console.log("User to update on server: \n" + JSON.stringify(user));

    Meteor.call('account/updatePaymentData', user, user._id, (err, res) => {
        if (res){
            Session.set('employeesList_selectedEmployee', user);
            swal({
                title: "Success",
                text: `Employee payment details updated`,
                confirmButtonClass: "btn-success",
                type: "success",
                confirmButtonText: "OK"
            });
            Modal.hide('EmployeePaymentDetailsDataModal');
        } else {
            console.log(err);
        }
    });
  },
  'blur [name=paymentMethod]': function (e, tmpl) {
    let user = Template.instance().getEditUser();
    let value = e.currentTarget.value;
    if (value && value.trim().length > 0) {
      user.employeeProfile = user.employeeProfile || {};
      user.employeeProfile.payment = user.employeeProfile.payment || {};
      user.employeeProfile.payment.paymentMethod = value;

      console.log("user payment paymentMethod changed to: " + value);
    }
    Template.instance().setEditUser(user);
  },
  'blur [name=bank]': function (e, tmpl) {
    let user = Template.instance().getEditUser();
    let value = e.currentTarget.value;
    if (value && value.trim().length > 0) {
      user.employeeProfile = user.employeeProfile || {};
      user.employeeProfile.payment = user.employeeProfile.payment || {};
      user.employeeProfile.payment.bank = value;

      console.log("user payment bank changed to: " + value);
    }
    Template.instance().setEditUser(user);
  },
  'blur [name=paymentDetailsAccountNumber]': function (e, tmpl) {
    let user = Template.instance().getEditUser();
    let value = e.currentTarget.value;
    if (value && value.trim().length > 0) {
      user.employeeProfile = user.employeeProfile || {};
      user.employeeProfile.payment = user.employeeProfile.payment || {};
      user.employeeProfile.payment.accountNumber = value;

      console.log("user payment accountNumber changed to: " + value);
    }
    Template.instance().setEditUser(user);
  },
  'blur [name=paymentDetailsAccountName]': function (e, tmpl) {
    let user = Template.instance().getEditUser();
    let value = e.currentTarget.value;
    if (value && value.trim().length > 0) {
      user.employeeProfile = user.employeeProfile || {};
      user.employeeProfile.payment = user.employeeProfile.payment || {};
      user.employeeProfile.payment.accountName = value;

      console.log("user payment accountName changed to: " + value);
    }
    Template.instance().setEditUser(user);
  },
  'blur [name=pensionmanager]': function (e, tmpl) {
    let user = Template.instance().getEditUser();
    let value = e.currentTarget.value;
    if (value && value.trim().length > 0) {
      user.employeeProfile = user.employeeProfile || {};
      user.employeeProfile.payment = user.employeeProfile.payment || {};
      user.employeeProfile.payment.pensionmanager = value;

      console.log("user payment pensionmanager changed to: " + value);
    }
    Template.instance().setEditUser(user);
  },
  'blur [name=paymentDetailsRSAPin]': function (e, tmpl) {
    let user = Template.instance().getEditUser();
    let value = e.currentTarget.value;
    if (value && value.trim().length > 0) {
      user.employeeProfile = user.employeeProfile || {};
      user.employeeProfile.payment = user.employeeProfile.payment || {};
      user.employeeProfile.payment.RSAPin = value;

      console.log("user payment RSAPin changed to: " + value);
    }
    Template.instance().setEditUser(user);
  }
});

/*****************************************************************************/
/* EmployeePaymentDetailsDataModal: Helpers */
/*****************************************************************************/
Template.EmployeePaymentDetailsDataModal.helpers({
    "selectedEmployee": function() {
        let selectedEmployee = Session.get('employeesList_selectedEmployee');
        return [selectedEmployee];
    },
    'pfas': function(){
      console.log("[PaymentDetails] Inside pfas");

      let allPfas = PensionManagers.find({});
      return allPfas;
    },
});

/*****************************************************************************/
/* EmployeePaymentDetailsDataModal: Lifecycle Hooks */
/*****************************************************************************/
Template.EmployeePaymentDetailsDataModal.onCreated(function () {
  let self = this;

  self.subscribe("pensionManagers", Session.get('context'));

  self.getEditUser = () => {
    return Session.get('employeeNextOfKinData');
  }

  self.setEditUser = (editUser) => {
    console.log("Inside setEditUser");
    Session.set('employeeNextOfKinData', editUser);
  }

  let selectedEmployee = Session.get('employeesList_selectedEmployee')
  self.setEditUser(selectedEmployee);
});

Template.EmployeePaymentDetailsDataModal.onRendered(function () {
});

Template.EmployeePaymentDetailsDataModal.onDestroyed(function () {
});<commit_msg>Fix bug on payment details modal for showing user's current PFA<commit_after>/*****************************************************************************/
/* EmployeePaymentDetailsDataModal: Event Handlers */
/*****************************************************************************/
Template.EmployeePaymentDetailsDataModal.events({
  'click #save-close': (e, tmpl) => {
    Modal.hide('EmployeePaymentDetailsDataModal');
  },
  'click #save': (e, tmpl) => {
    let user = Template.instance().getEditUser();
    console.log("User to update on server: \n" + JSON.stringify(user));

    Meteor.call('account/updatePaymentData', user, user._id, (err, res) => {
        if (res){
            Session.set('employeesList_selectedEmployee', user);
            swal({
                title: "Success",
                text: `Employee payment details updated`,
                confirmButtonClass: "btn-success",
                type: "success",
                confirmButtonText: "OK"
            });
            Modal.hide('EmployeePaymentDetailsDataModal');
        } else {
            console.log(err);
        }
    });
  },
  'blur [name=paymentMethod]': function (e, tmpl) {
    let user = Template.instance().getEditUser();
    let value = e.currentTarget.value;
    if (value && value.trim().length > 0) {
      user.employeeProfile = user.employeeProfile || {};
      user.employeeProfile.payment = user.employeeProfile.payment || {};
      user.employeeProfile.payment.paymentMethod = value;

      console.log("user payment paymentMethod changed to: " + value);
    }
    Template.instance().setEditUser(user);
  },
  'blur [name=bank]': function (e, tmpl) {
    let user = Template.instance().getEditUser();
    let value = e.currentTarget.value;
    if (value && value.trim().length > 0) {
      user.employeeProfile = user.employeeProfile || {};
      user.employeeProfile.payment = user.employeeProfile.payment || {};
      user.employeeProfile.payment.bank = value;

      console.log("user payment bank changed to: " + value);
    }
    Template.instance().setEditUser(user);
  },
  'blur [name=paymentDetailsAccountNumber]': function (e, tmpl) {
    let user = Template.instance().getEditUser();
    let value = e.currentTarget.value;
    if (value && value.trim().length > 0) {
      user.employeeProfile = user.employeeProfile || {};
      user.employeeProfile.payment = user.employeeProfile.payment || {};
      user.employeeProfile.payment.accountNumber = value;

      console.log("user payment accountNumber changed to: " + value);
    }
    Template.instance().setEditUser(user);
  },
  'blur [name=paymentDetailsAccountName]': function (e, tmpl) {
    let user = Template.instance().getEditUser();
    let value = e.currentTarget.value;
    if (value && value.trim().length > 0) {
      user.employeeProfile = user.employeeProfile || {};
      user.employeeProfile.payment = user.employeeProfile.payment || {};
      user.employeeProfile.payment.accountName = value;

      console.log("user payment accountName changed to: " + value);
    }
    Template.instance().setEditUser(user);
  },
  'blur [name=pensionmanager]': function (e, tmpl) {
    let user = Template.instance().getEditUser();
    let value = e.currentTarget.value;
    if (value && value.trim().length > 0) {
      user.employeeProfile = user.employeeProfile || {};
      user.employeeProfile.payment = user.employeeProfile.payment || {};
      user.employeeProfile.payment.pensionmanager = value;

      console.log("user payment pensionmanager changed to: " + value);
    }
    Template.instance().setEditUser(user);
  },
  'blur [name=paymentDetailsRSAPin]': function (e, tmpl) {
    let user = Template.instance().getEditUser();
    let value = e.currentTarget.value;
    if (value && value.trim().length > 0) {
      user.employeeProfile = user.employeeProfile || {};
      user.employeeProfile.payment = user.employeeProfile.payment || {};
      user.employeeProfile.payment.RSAPin = value;

      console.log("user payment RSAPin changed to: " + value);
    }
    Template.instance().setEditUser(user);
  }
});

/*****************************************************************************/
/* EmployeePaymentDetailsDataModal: Helpers */
/*****************************************************************************/
Template.EmployeePaymentDetailsDataModal.helpers({
    "selectedEmployee": function() {
        let selectedEmployee = Session.get('employeesList_selectedEmployee');
        return [selectedEmployee];
    },
    'pfas': function(){
      console.log("[PaymentDetails] Inside pfas");

      let allPfas = PensionManagers.find({});
      return allPfas;
    },
});

/*****************************************************************************/
/* EmployeePaymentDetailsDataModal: Lifecycle Hooks */
/*****************************************************************************/
Template.EmployeePaymentDetailsDataModal.onCreated(function () {
  let self = this;

  self.subscribe("pensionManagers", Session.get('context'));

  self.getEditUser = () => {
    return Session.get('employeeNextOfKinData');
  }

  self.setEditUser = (editUser) => {
    console.log("Inside setEditUser");
    Session.set('employeeNextOfKinData', editUser);
  }

  let selectedEmployee = Session.get('employeesList_selectedEmployee')
  self.setEditUser(selectedEmployee);
});

Template.EmployeePaymentDetailsDataModal.onRendered(function () {
  let selectedEmployee = Session.get('employeesList_selectedEmployee')
  $('[name="pensionmanager"]').val(selectedEmployee.employeeProfile.payment.pensionmanager);
});

Template.EmployeePaymentDetailsDataModal.onDestroyed(function () {
});
{'fraction_non_alphanumeric': 0.21528525296017223, 'fraction_numerical': 0.001076426264800861, 'mean_word_length': 3.7870330613997423, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1470046', 'n_tokens_mistral': 3100, 'n_tokens_neox': 2869, 'n_words': 538}