function initializeProductCategories() {
    $("#Keywords").attr('placeholder', $('#searchPlaceholder').val());

    var userCanAccessCategoryCud = $("#userCanAccessCategoryCud").val() === 'True';

    $dataTable = $('#mainGridCategories');
    $dataTable.DataTable({
        ajax: {
            url: $dataTable.attr('data-url'),
            data: function (d) {
                d.Keywords = $("#Keywords").val();
            }
        },
        columns: [
            { data: "Id", name: "AcClassif", filtertype: "text", render: $.fn.dataTable.render.link("Id") },
            { data: "Name", name: "AcName", filtertype: "text", render: $.fn.dataTable.render.link("Id") },
            {
                data: "Type", name: "AcType", filtertype: "text", render: function (data, type) {
                    switch (data) {
                        case "P":
                            return data + " - " + $("#primaryClassifText").val();
                        case "S":
                            return data + " - " + $("#secondaryClassifText").val();
                        case "O":
                            return data + " - " + $("#bothClassifText").val();
                    }

                    return data;
                }
            }
        ]
    });

    $("select").off("change.tableReload");
    $("select").on("change.tableReload", function () {
        $.fn.dataTable.reload($dataTable);
    });

    var typingTimer;
    var doneTypingInterval = 600;
    $('#Keywords').off('keyup');
    $('#Keywords').on('keyup', function () {
        clearTimeout(typingTimer);
        typingTimer = setTimeout(function () { $.fn.dataTable.reload($dataTable); }, doneTypingInterval);
    });
}

function initializeProductCategoriesEdit() {
    $('#Id').focus();

    var elems = Array.prototype.slice.call(document.querySelectorAll('#productClassifForm .js-switch'));
    elems.forEach(function (html) {
        var switchery = new Switchery(html, { size: 'small' });
    });

    $('.input-validation-error').parents('.form-group').addClass('has-error');
    $('.field-validation-error').addClass('text-danger');
}

function onDeleteProductClassif() {
    $().customModal({
        destroyOnClose: true,
        showCloseButton: true,
        type: "question",
        text: $("#ConfirmDeleteLoc").val(),
        buttons: [
            {
                icon: 'fa fa-times',
                text: $("#NoLoc").val(),
                closeOnAction: true,
                type: 'ghost'
            },
            {
                icon: 'fa fa-check',
                text: $("#YesLoc").val(),
                action: function () {
                    let productClassifId = $("#Id").val();
                    $.ajax({
                        url: $("#DeleteProductClassifUrl").val(),
                        type: 'POST',
                        headers: {
                            'Accept': 'application/json',
                            'Content-Type': 'application/json'
                        },
                        data: JSON.stringify({ id: productClassifId }),
                        success: function (response) {
                            if (response.IsDeleted)
                                window.location = $("#productClassifIndex").val();
                            else {
                                $().customModal({
                                    destroyOnClose: true,
                                    showCloseButton: true,
                                    type: "alert",
                                    text: $("#ItemAlreadyInUseLoc").val(),
                                    buttons: [
                                        {
                                            icon: 'fa fa-check',
                                            text: $("#ConfirmLoc").val(),
                                            closeOnAction: true,
                                            type: 'primary'
                                        }
                                    ]
                                });
                            }
                        },
                        error: function (error) {
                            console.error(error);
                        }
                    });
                },
                closeOnAction: true,
                type: 'primary'
            }
        ]
    });
}