<commit_before>

$(document).ready(function() {
    $("div.application").each(function(i, row) {
        $(row).find("button.approve").click(function() {
            approveApplication($(this).val(), row);
        });
        $(row).find("button.decline").click(function() {
            declineApplication($(this).val(), row);
        });
    });
    
    var approveApplication = function(application_id, row) {
        var utils = new Utils();
        $.ajax({
            method: 'POST',
            url: 'approve_application/',
            data: {'application_id': application_id, },
            success: function(response) {
                response = JSON.parse(response['responseText']);
                utils.setStatusMessage(response, 'alert-success');
                // TODO Make animation
                $(row).hide();
            },
            error: function(response) {
                if (response['status'] === 412) {
                    response = JSON.parse(response['responseText']);
                    utils.setStatusMessage(response['message'], 'alert-danger');
                }
                else {
                    utils.setStatusMessage('En uventet error ble oppdaget. Kontakt <EMAIL> for assistanse.', 'alert-danger');
                }
            },
            crossDomain: false
        });
    }

    var declineApplication = function(application_id, row) {
        
    }

});<commit_msg>Finished js for ajax calls on approval list.<commit_after>/* AJAX SETUP FOR CSRF */
$.ajaxSetup({
    crossDomain: false, // obviates need for sameOrigin test
    beforeSend: function(xhr, settings) {
        if (!csrfSafeMethod(settings.type)) {
            xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken'));
        }
    }
});
function csrfSafeMethod(method) {
    // these HTTP methods do not require CSRF protection
    return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
/* END AJAX SETUP */

$(document).ready(function() {
    $("div.application").each(function(i, row) {
        $(row).find("button.approve").click(function() {
            approveApplication($(this).val(), row);
        });
        $(row).find("button.decline").click(function() {
            that = $(this);
            // hide the first button
            $(this).prop('disabled', true);
            // show the row with message and confirmation
            confirmrow = $("#confirm" + $(this).val());
            $(confirmrow).show();
            // find the button that will actually send the decline and set some stuff on it
            $("button.sendDecline").click(function() {
                $(confirmrow).hide();
                message = $(confirmrow).find("textarea").val();
                declineApplication($(this).val(), message, row);
            });
            // cancel should hide the row and enable the first button again
            $("button.cancel").click(function() {
                $(that).prop('disabled', false);
                $(confirmrow).hide();
            });
        });
    });
    
    var approveApplication = function(application_id, row) {
        var utils = new Utils();
        $.ajax({
            method: 'POST',
            url: 'approve_application/',
            data: {'application_id': application_id, },
            success: function() {
                // TODO Make animation
                $(row).hide();
            },
            error: function(response) {
                if (response['status'] === 412) {
                    response = JSON.parse(response['responseText']);
                    utils.setStatusMessage(response['message'], 'alert-danger');
                }
                else {
                    utils.setStatusMessage('En uventet error ble oppdaget. Kontakt <EMAIL> for assistanse.', 'alert-danger');
                }
            },
            crossDomain: false
        });
    }

    var declineApplication = function(application_id, message, row) {
        var utils = new Utils();
        $.ajax({
            method: 'POST',
            url: 'decline_application/',
            data: {'application_id': application_id, 'message': message, },
            success: function() {
                // TODO Make animation
                $(row).hide();
            },
            error: function(response) {
                if (response['status'] === 412) {
                    response = JSON.parse(response['responseText']);
                    utils.setStatusMessage(response['message'], 'alert-danger');
                }
                else {
                    utils.setStatusMessage('En uventet error ble oppdaget. Kontakt <EMAIL> for assistanse.', 'alert-danger');
                }
            },
            crossDomain: false
        });
    }

});
{'fraction_non_alphanumeric': 0.14411764705882352, 'fraction_numerical': 0.0018907563025210084, 'mean_word_length': 1.7128205128205127, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '3597722', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1180, 'n_words': 258}