<commit_before>$(document).ready(function() {

    var articleData = null,
        userData = null;

    $.getJSON("rest/user/current", function(data) {
        userData = data.user;
        if (userData.userName == null) {
            window.location.href="index.html";
            console.log('penis');
        }
        if (userData.admin === 0) {
            $("[data-tab=tab-3]").remove();
        } 
    });


    var $AddButton = $("#add-button");
    $AddButton.click(function() {
        var oArticleData = {
            article: {
                title: $("#article-title").val(),
                articleType: $('#category option:selected').text().replace(/ /g, ''),
                text: $("#article-body").val()
            }
        };

        if (!validate()) {
            return;
        }

        $.ajax({
                url: 'rest/article/add',
                type: "POST",
                contentType: "application/json",
                data: JSON.stringify(oArticleData)
            })
            .success(function() {
                alert("Added successfully!");
            })
            .fail(function() {
                alert("Failed to add article!");
            })
            .always(function() {
                $("#add-form").submit();
            });
    });

    $('#logout-button').click(function() {
        $.ajax({
            url: 'rest/user/logout',
            type: "GET",
            statusCode: {
                204: function() {
                    window.location.replace("index.html");
                }
            }
        });
    });

    $('body').on('click', '#deleteArticle', function() {
        var deleteID = $(this).attr('data-id');
        $.ajax({
            type: "DELETE",
            url: "rest/article/delete?id=" + deleteID
        })
        .fail(function() {
            alert("Article not removed!");
        })
        .always(function() {
            alert("Article removed!");
            location.reload();
        });
    });

    function validate() {
        var $articleTitle = $('#article-title').val(),
            $articleBody = $('#article-body').val();
<commit_msg>Added Approve article button and AJAX queries<commit_after>$(document).ready(function() {

    var articleData = null,
        userData = null;

    $.getJSON("rest/user/current", function(data) {
        userData = data.user;
        if (userData.userName == null) {
            window.location.href="index.html";
        }
        if (userData.admin === 0) {
            $("[data-tab=tab-3]").remove();
        } 
    });


    var $AddButton = $("#add-button");
    $AddButton.click(function() {
        var oArticleData = {
            article: {
                title: $("#article-title").val(),
                articleType: $('#category option:selected').text().replace(/ /g, ''),
                text: $("#article-body").val()
            }
        };

        if (!validate()) {
            return;
        }

        $.ajax({
                url: 'rest/article/add',
                type: "POST",
                contentType: "application/json",
                data: JSON.stringify(oArticleData)
            })
            .success(function() {
                alert("Added successfully! Now wait for approval!");
            })
            .fail(function() {
                alert("Failed to add article!");
            })
            .always(function() {
                $("#add-form").submit();
            });
    });

    $('#logout-button').click(function() {
        $.ajax({
            url: 'rest/user/logout',
            type: "GET",
            statusCode: {
                204: function() {
                    window.location.replace("index.html");
                }
            }
        });
    });

    $('body').on('click', '#approveArticle', function() {
        var approveID = $(this).attr('data-id');
        $.ajax({
            type: "PUT",
            url: "rest/article/update?id=" + approveID
        })
        .success(function() {
            alert("Added successfully!");
            location.reload();
        })
        .fail(function() {
            alert("Failed to add article!");
        });
    });

    $('body').on('click', '#deleteArticle', function() {
        var deleteID = $(this).attr('data-id');
        $.ajax({
            type: "DELETE",
            url: "rest/article/delete?id=" + deleteID
        })
        .success(function() {
            alert("Removed successfully!");
            location.reload();
        })
        .fail(function() {
            alert("Failed to remove article!");
        });
    });

    function validate() {
        var $articleTitle = $('#article-title').val(),
            $articleBody = $('#article-body').val();

{'fraction_non_alphanumeric': 0.17436005035669325, 'fraction_numerical': 0.00209819555182543, 'mean_word_length': 1.4124493927125505, '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': '1849781', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1225, 'n_words': 217}