Skip to content

Custom Javascript Library for Libki Server

Kyle M Hall edited this page Mar 23, 2023 · 6 revisions

Administration Interface

Hide guest buttons

$(document).ready(function() {
    $("#reservations-tab").hide();
});

Hide reservations tab

$(document).ready(function() {
    $("#reservations-tab").hide();
});

Show a given username only one location's clients when logged in

$(document).ready(function() {
    $('#client-table').on('init.dt', function() {
        const mapping = {
            "username1": "Location 1",
            "username2": "Location 2",
            "username3": "Location 3"
        }

        const username = $("#libki-primary-navbar .fa-user").parent().text().replace(/\s/g, '');
        const label = $('a.nav-link:contains("Location:")');
        const location = mapping[username];

        if (location) {
            window.location_filter = location;
            const link = $(`a.nav-link:contains(${location})`);
            $('#primary-tabs a.nav-link').hide();
            label.show();
            link.show();
            setTimeout(function() {
                $("#client-table").dataTable().fnDraw(true);
            }, 500);
            setTimeout(function() {
                $("#client-table").dataTable().fnDraw(true);
            }, 1000);
            setTimeout(function() {
                $("#client-table").dataTable().fnDraw(true);
            }, 2000);
        }
    });
});

Hide "Shutdown All" if viewing all locations

$(document).ready(function() {
    $('.shutdown-button').hide();

    $('.nav-item').on('click', function() {
        if ($(this).children('a').first().html() === "All") {
            $('.shutdown-button').hide();
        } else {
            $('.shutdown-button').show();
        }
    });
});

Change background color for offline computers row in clients table

$(document).ready(function() {
    $('#client-table').on('draw.dt', function() {
        $('td:contains(Offline)').parent().css('background-color', 'red');
    });
});