$(function () {
    "use strict";
    if($('.tooltipster-top').length>0){
        $('.tooltipster-top').tooltipster({
            position: "top"
        });
    }
});

$(function () {
    "use strict";
    if($('#groupList').length>0){
        $('#groupList').dataTable({
            ordering: false,
            searching: false,
            paging: false,
            info: false,
            dom: '<f<t><"bottom"ilp>><"clear">',
            language: {
                url: language,
            }
        });
    }
});

$(function () {
    "use strict";
    if($('.countPagesGroups').length>0){
        var iloscGrup = $('.countPagesGroups').attr('date-pageGroups');
        for(var i=0; i<iloscGrup; i++){
            $('.pagesGroupTable'+i).DataTable(
                {
                    ordering: true,
                    searching: true,
                    paging: false,
                    info: false,
                    "order": [
                        [0, "asc"]
                    ],
                    "dom": '<f<t><"bottom"ilp>><"clear">',
                    language: {
                        url: language,
                    }
                }
            );
        }
        $('.searchThisGroup').on( 'keyup', function () {
            var table = $(this).attr('data-table');
            $('.'+table).DataTable().search( this.value ).draw();
        } );
        $('.collapseAll').on('click', function () {
            $('.boxPagesGroup').removeClass('collapsed-box');
            $('.collapseExpand').click();
        });
        $('.expandAll').on('click', function () {
            $('.collapsed-box .collapseExpand').click();
        });

    }
});

$(function () {
    "use strict";
    // wyświetlanie stron
    $('.selectCategory').change(function () {
        $('#selectCategoryForm').submit();
    });
    //wysyłanie formularza paginacji
    $('select[name=per_page]').change(function () {
        $(this).parent().submit();
    })
})


$(function () {
    "use strict";
    // usuwanie strony
    $('#deletePage').change(function () {
        if (this.checked) {
            $('#pagesDeleteInput').removeAttr('disabled');
        } else {
            $('#pagesDeleteInput').attr('disabled', 'disabled');
        }


    });

    // usuwanie kategorii newsów
    $('#deletePageGroup').change(function () {
        if(this.checked && $("#countPages").attr("wartosc")==0 && $("#countChildren").attr("wartosc")==0){
            $('#groupDeleteInput').removeAttr('disabled');
            $('#confirmDelete').css({opacity: "1", filter: "alpha(opacity=100)", "pointer-events": "all"});
        } else if(this.checked) {
            $('#confirmDelete').css({opacity: "1", filter: "alpha(opacity=100)", "pointer-events": "all"});
        } else {
            $('#confirmDelete').css({opacity: "0.3", filter: "alpha(opacity30)", "pointer-events": "none"});

        }
    });
    $('#deleteAll').change(function () {
        if(this.checked){
            $('#groupDeleteInput').removeAttr('disabled');
            $('#confirmDeleteSubcategories').css({opacity: "0.3", filter: "alpha(opacity=30)", "pointer-events": "none"});
            $('#selectGroup').css({opacity: "0.3", filter: "alpha(opacity=30)", "pointer-events": "none"});
        } else {
            $('#confirmDeleteSubcategories').css({opacity: "1", filter: "alpha(opacity=100)", "pointer-events": "all"});
            $('#selectGroup').css({opacity: "1", filter: "alpha(opacity=100)", "pointer-events": "all"});
            if($('#newPageGroup').val()){
                $('#groupDeleteInput').removeAttr('disabled');
            } else {
                $('#groupDeleteInput').attr('disabled', 'disabled');
            }
        }
    });
    $('#newPageGroup').change(function () {
        if($('#newPageGroup').val()){
            $('#groupDeleteInput').removeAttr('disabled');
        } else {
            $('#groupDeleteInput').attr('disabled', 'disabled');
        }
    });
});

// Chosen
$(function () {
    "use strict";
    // Włączenie chosen - dodawanie i edycja newsa - wybór kategorii
    if($('.chosenSelectGroup').length>0){
        $('.chosenSelectGroup').select2({
            width: 'resolve'
        });
    }
})

