$(document).ready(function () {
    getFundTypeList();
});
async function getFundTypeList() {
    await ajax({
        loading: true,
        url: "TreasuryApi/GetFunderTypeList",
        data: { pageNo: -1},
        success: function (result) {
            result.forEach(function (item) {
                var $div = $("#divTemplate").clone();
                $div.removeAttr("hidden");
                $div.find("[data-id='Name']").text(item.Name);
                $div.find("[data-id='edit']").attr("onclick", "openModal(" + item.Code + ")");
                $div.find("[data-id='delete']").attr("onclick", "deleteFundTypes(" + item.Code + ")");
                $("#divFundType").append($div);
            });
        }
    });
}
function openModal(code) {
    var title = code === -1 ? window.top.fundType : window.top.editFundType;
    var src = "Setting/FundTypesSave" + (code > 0 ? "?code=" + code : "");
    openInModal('', src, title, '450', '440');
}
function refresh() {
    $("#divFundType").empty();
    getFundTypeList();
}
function deleteFundTypes(value) {
    if (confirm(window.top.deleteConfirm)) {
        ajax({
            loading: true,
            url: "TreasuryApi/DeleteFunderType",
            data: { code: value },
            success: function () {
                showMsgModal(2, window.top.deletedSuccessfully);
                refresh();
            }
        });
    }
}