var gridBuilder;
$(document).ready(function () {
    gridBuilder = $(".grid").gridBuilder();
    $("#cboLanguage").lookupBuilder().onChanged(async function () {
        await getDictionaryList();
    });
    closeLoading();
    $("#divMain").show();
    $("#addLanguage").on("click", function () {
        $("#modalAddLanguage").modal();
    });
});
async function getDictionaryList() {
    await ajax({
        gridBuilder: gridBuilder,
        url: "GeneralApi/GetDictionaryList",
        data: { languageCode: $("#cboLanguage").lookupBuilder().getSelectedValue() },
        success: function (result) {
            gridBuilder.loadData(result);
        }
    });
}
async function getEventLookupCombo($combo, search, code) {
    await ajax({
        url: "GeneralApi/GetLanguageList",
        success: function (result) {
            result.forEach(function (item) {
                item["Code"] = item.Name;
                item["Name"] = item.FullName;
            });
            $combo.lookupBuilder().bindData(result);
            $combo.lookupBuilder().setSelectedValue(result[0].Code);
        }
    });
}
function save() {
    var model = gridBuilder.getDataArray()["data"].filter(function (item) {
        return (item.Value !== null && item.Value.trim() !== "");
    });
    var languageCode = $("#cboLanguage").lookupBuilder().getSelectedValue();
    ajax({
        loading: true,
        url: "GeneralApi/InsertDictionary",
        data: { dictionaryItems: model, languageCode: languageCode },
        success: function (returnValue) {
            showMsgModal(2, window.top.savedSuccessfully + " " + returnValue.Result);
        }
    });
}
function insertLanguage() {
    ajax({
        url: "GeneralApi/InsertLanguage",
        loading: true,
        data: { name: $("#txtName").val(), fullName: $("#txtFullName").val() },
        success: function (result) {
            closeLoading();
        }
    });
}
