<commit_before>$(function () {
    var dialog = $('#editEntryDialog').modal({show:false});
    var link = null;

    function swapPrimary(newKey) {
        var oldButton = $(".btn-group").find(".btn-primary");
        oldButton.removeClass("btn-primary");
        oldButton.find("i").removeClass("icon-check");
        oldButton.find("i").removeClass("icon-white");
        oldButton.find("i").addClass("icon-ok");

        var newButtons = $("[data-key-name='" + newKey + "']").find(".btn-group");
        newButtons.find("button").addClass("btn-primary");
        newButtons.find("i").removeClass("icon-ok");
        newButtons.find("i").addClass("icon-check icon-white");
    }

    var toggleDefaultKey = function () {
        var link = $(this);
        var row = link.parents("tr");
        var keyName = row.data("key-name");
        $.ajax({
            url:getContextPath() + "/system/keys/default.json",
            type:'PUT',
            data:JSON.stringify({name:keyName}),
            contentType:'application/json',
            success:function (data, status, xhr) {
                swapPrimary(data.name);
            },
            error:function (xhr, status, error) {
                alert("An error has occurred while removing the role. Please check the log for more details.");
            }
        });
        return false;
    };

    var onSaveHandler = function (entry) {
        var row = link.parents("tr");
        row.fadeOut('slow', function () {
            row.children(".key-description").text(entry.description);
            row.children(".key-name").text(entry.name);
        });
        row.fadeIn('slow');
    };



    var deleteEntry = function () {
        link = $(this);
        var button = link.parents("button");
        if (button.hasClass("btn-primary")) {
            alert("Cannot delete default key");
            return false;
        }
        var id = link.parents("tr").data("key-name");
        $.ajax({
            url:getContextPath() + '/system/keys/' + encodeURI(id) + ".json",
            type:'DELETE',
            success:function (data, status, xhr) {
                onDeleteHandler();
            },
            error:function (xhr, status, error) {
                alert("An error has occurred while deleting the record. Please check the log for more details.");
            }
        });
    };

    var onDeleteHandler = function () {
        var row = link.parents("tr");
        row.fadeOut('slow', function () {
            row.remove();
        });
    };

    var showEditDialog = function () {
        link = $(this);
        var id = link.parents("tr").data("key-name");
        $('#editEntryDialog').modal('show');
        $('#editEntryForm').jsonForm('loadResourceById', id);
    };

    var toggleShowPassword = function () {
        var link = $(this);
        link.toggleClass("btn-danger");
        link.find("i").toggleClass("icon-white");
        var password = link.prev("input");
        // do a little dance around browser security
        var copy = password.clone();
        copy.attr("type", password.attr("type") == "password" ? "text" : "password");
        copy.insertBefore(password);
        password.remove();<commit_msg>work on getting rid of native javascript pop-up alerts<commit_after>$(function () {
    var dialog = $('#editEntryDialog').modal({show:false});
    var link = null;

    function swapPrimary(newKey) {
        var oldButton = $(".btn-group").find(".btn-primary");
        oldButton.removeClass("btn-primary");
        oldButton.find("i").removeClass("icon-check");
        oldButton.find("i").removeClass("icon-white");
        oldButton.find("i").addClass("icon-ok");

        var newButtons = $("[data-key-name='" + newKey + "']").find(".btn-group");
        newButtons.find("button").addClass("btn-primary");
        newButtons.find("i").removeClass("icon-ok");
        newButtons.find("i").addClass("icon-check icon-white");
    }

    var toggleDefaultKey = function () {
        var link = $(this);
        var row = link.parents("tr");
        var keyName = row.data("key-name");
        $.ajax({
            url:getContextPath() + "/system/keys/default.json",
            type:'PUT',
            data:JSON.stringify({name:keyName}),
            contentType:'application/json',
            success:function (data, status, xhr) {
                swapPrimary(data.name);
            },
            error:function (xhr, status, error) {
                showAlert("An error has occurred while setting the default key. Please check the log for more details.");
            }
        });
        return false;
    };

    var onSaveHandler = function (entry) {
        var row = link.parents("tr");
        row.fadeOut('slow', function () {
            row.children(".key-description").text(entry.description);
            row.children(".key-name").text(entry.name);
        });
        row.fadeIn('slow');
    };



    var deleteEntry = function () {
        link = $(this);
        var button = link.parents("button");
        if (button.hasClass("btn-primary")) {
            showAlert("Cannot delete default key");
            return false;
        }
        var id = link.parents("tr").data("key-name");
        $.ajax({
            url:getContextPath() + '/system/keys/' + encodeURI(id) + ".json",
            type:'DELETE',
            success:function (data, status, xhr) {
                onDeleteHandler();
            },
            error:function (xhr, status, error) {
                showAlert("An error has occurred while deleting the record. Please check the log for more details.");
            }
        });
    };

    var onDeleteHandler = function () {
        var row = link.parents("tr");
        row.fadeOut('slow', function () {
            row.remove();
        });
    };

    var showEditDialog = function () {
        link = $(this);
        var id = link.parents("tr").data("key-name");
        $('#editEntryDialog').modal('show');
        $('#editEntryForm').jsonForm('loadResourceById', id);
    };

    var toggleShowPassword = function () {
        var link = $(this);
        link.toggleClass("btn-danger");
        link.find("i").toggleClass("icon-white");
        var password = link.prev("input");
        // do a little dance around browser security
        var copy = password.clone();
        copy.attr("type", password.attr("type") == "password" ? "text" : "password");
        copy.insertBefore(password);
        password.remove();
{'fraction_non_alphanumeric': 0.16648698598490683, 'fraction_numerical': 0.0, 'mean_word_length': 2.1116435074269284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6954162', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1736, 'n_words': 364}