{"size": 3979, "ext": "js", "max_stars_repo_path": "public/javascripts/application.js", "max_stars_repo_name": "francois/family_budget", "max_stars_repo_stars_event_min_datetime": "2016-05-08T06:07:44.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-25T19:05:08.000Z", "max_issues_repo_path": "public/javascripts/application.js", "max_issues_repo_name": "francois/family_budget", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/javascripts/application.js", "max_forks_repo_name": "francois/family_budget", "max_forks_repo_forks_event_min_datetime": "2021-07-13T06:53:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-13T19:16:58.000Z"}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 39.0098039216, "max_line_length": 149, "alphanum_fraction": 0.6187484293}
$(document).ready(function() {
  $("#flash").slideDown("slow").click(function() {
    $("#flash").slideUp();
  });

  var insecureProcess = function(data) { eval(data); };
  var handleTransfer = function(e, ui) {
    // this == droppable, ui.draggable == draggable
    var sourceBankTransactionId = $(ui.draggable).attr("id").replace("bank_transaction_", "");
    var targetBankTransactionId = $(this).attr("id").replace("bank_transaction_", "");
    jQuery.post("/transfers.js", {"transfer[bank_transaction_id][]": [sourceBankTransactionId, targetBankTransactionId]}, insecureProcess);
  };

  $("#bank_transactions tr.bank_transaction").draggable({revert: true, helper: 'clone', opacity: 0.7, scroll: true, handle: ".handle"});
  $("#bank_transactions tr.bank_transaction").droppable({accept: "#bank_transactions .handle", drop: handleTransfer});

  $("#bank_transactions a.ignore").click(function() {
    var id = this.getAttribute("id").replace("ignore_bank_transaction_", "");
    jQuery.post("/bank_transactions/" + id + ".js", {"_method": "delete"}, insecureProcess);
    return false;
  });

  $("#bank_transactions td.actions input[type=submit]").bind("click", function() {
    if (this.getAttribute("class").match(/process/)) {
      if ($("input.regroup[checked]").length > 1) {
        var ids = [];
        $("input.regroup[checked]").each(function(index, elem) {
          ids.push(elem.getAttribute("id").replace("regroup_bank_transaction_", ""));
        });
        jQuery.post("/transfers.js", {"transfer[bank_transaction_id][]": ids}, insecureProcess);
      } else {
        var bankTransactionId = this.id.replace("bank_transaction_", "").replace("_process", "");
        var accountId = $("#account_selector input[checked]").val();
        jQuery.post("/transfers.js", {"transfer[bank_transaction_id]": bankTransactionId, "transfer[debit_account_id]": accountId}, insecureProcess);
      }
    } else if (this.getAttribute("class").match(/cancel/)) {
      var bankTransactionId = this.id.replace("bank_transaction_", "").replace("_cancel", "");
      var transferId = $("#bank_transactions #bank_transaction_" + bankTransactionId + " input.transfer_id").val();
      if (transferId) {
        jQuery.post("/transfers/" + transferId + ".js", {"_method": "delete"}, insecureProcess);
      } else {
        jQuery.post("/bank_transactions/" + bankTransactionId + ".js", {"_method": "put", "bank_transaction[ignored_at]": ""}, insecureProcess);
      }
    } else {
      alert("Programming error:  don't know how to process '" + this.getAttribute("class") + "'");
    }
  });

  $("#clear_groupings").click(function() {
    $("input.regroup").attr("checked", false);
    return false;
  });

  // Split amounts page (splits/:id/edit)
  (function() {
    
    function getOriginalAmount() {
      return parseFloat($("#splits #original-amount").html());
    }

    function getTotal() {
      var total = 0.0;
      $("#splits input.amount").each(function() {
        if ($(this).val() != "") {
          total += parseFloat($(this).val());
        }
      });

      return total;
    }

    function getBalanceAmount() {
      return Math.abs(getOriginalAmount()) - Math.abs(getTotal());
    }

    function updateBalanceFields() {
      $("#splits #split-amount").html(getTotal().toString());
      $("#splits #balance-amount").html(getBalanceAmount().toString());
    }

    $("#splits .destroy").bind("click", function() {
      $(this).parents("tr").remove();
      updateBalanceFields();
      return false;
    });

    $("#splits #add-another").bind("click", function() {
      var clones = $("#splits #template").clone(true);
      clones.insertBefore("#splits tbody tr#add-line");
      clones.removeAttr("id");

      clones.find("input.amount").val(getBalanceAmount().toString());
      updateBalanceFields();
      return false;
    });

    $("#splits input.amount").bind("change", function() {
      updateBalanceFields();
    });
  })();
});
