<commit_before>// The procedure here in is adjusted from the plugin https://github.com/Abban/jQuery-Ajax-File-Upload
// available under MIT License
// description on: http://abandon.ie/notebook/simple-file-uploads-using-jquery-ajax

// Upload files on change of file selector
$('#project-fileupload').on('change', startProjectFileUpload);

var dialogTemplate = '<div class="alert <%= type %> alert-dismissable" role="alert" style="margin-top: 10px;">';
dialogTemplate += '<button type="button" class="close" data-dismiss="alert" aria-label="Close">';
dialogTemplate += '<span aria-hidden="true">&times;</span>';
dialogTemplate += '</button>';
dialogTemplate += '<%= message %>';
dialogTemplate += '</div>';
dialogTemplate = _.template(dialogTemplate);
$('#project-upload-message-area').append(dialogTemplate({type: 'alert-success', message: 'bla bla bla'}));
$('#project-upload-message-area').append(dialogTemplate({type: 'alert-warning', message: 'bla bla bla'}));
$('#project-upload-message-area').append(dialogTemplate({type: 'alert-danger', message: 'bla bla bla'}));
$('#project-upload-message-area').append(dialogTemplate({type: 'alert-info', message: 'bla bla bla'}));

// Grab the files and set them to our variable
function startProjectFileUpload(event)
{
    // START LOADING SPINNER
    var files = event.target.files;
    var data = new FormData();
    $.each(files, function(key, value)
    {
        data.append(key, value);
    });

    $.ajax({
        url: WebRoot+'/ajax/upload/Project?dbversion='+DbVersion,
        type: 'POST',
        data: data,
        cache: false,
        dataType: 'json',
        processData: false, // Don't process the files
        contentType: false, // Set content type to false as jQuery will tell the server its a query string request
        success: function(data, textStatus, jqXHR)
        {
            console.log(data);
            // STOP LOADING SPINNER
        },
        error: function(jqXHR, textStatus, errorThrown)
        {
            // Handle errors here
            console.log('ERRORS: ' + textStatus);
            // STOP LOADING SPINNER
        }
    });
}<commit_msg>Move dialog functionality into a function<commit_after>// The procedure here in is adjusted from the plugin https://github.com/Abban/jQuery-Ajax-File-Upload
// available under MIT License
// description on: http://abandon.ie/notebook/simple-file-uploads-using-jquery-ajax

// Upload files on change of file selector
$('#project-fileupload').on('change', startProjectFileUpload);

// Grab the files and set them to our variable
function startProjectFileUpload(event)
{
    // START LOADING SPINNER
    var files = event.target.files;
    var data = new FormData();
    $.each(files, function(key, value)
    {
        data.append(key, value);
    });

    $.ajax({
        url: WebRoot+'/ajax/upload/Project?dbversion='+DbVersion,
        type: 'POST',
        data: data,
        cache: false,
        dataType: 'json',
        processData: false, // Don't process the files
        contentType: false, // Set content type to false as jQuery will tell the server its a query string request
        success: function(data, textStatus, jqXHR)
        {
            console.log(data);
            // STOP LOADING SPINNER
        },
        error: function(jqXHR, textStatus, errorThrown)
        {
            // Handle errors here
            console.log('ERRORS: ' + textStatus);
            // STOP LOADING SPINNER
        }
    });
}

/**
 * This function appends a bootstrap dialog to the project message area with the given message and type
 * @param {type} message - The text that should be shown in the dialog
 * @param {type} type - The type (color) of the dialog. Possible values: alert-success, alert-warning, alert-danger, alert-info (default)
 * @returns {void}
 */
function showProjectUploadDialog(message, type){
    var knownTypes = ['alert-success', 'alert-warning', 'alert-danger', 'alert-info'];
    if(knownTypes.indexOf(type) === -1){
        type = 'alert-info';
    }
    var dialogTemplate = '<div class="alert <%= type %> alert-dismissable" role="alert" style="margin-top: 10px;">';
    dialogTemplate += '<button type="button" class="close" data-dismiss="alert" aria-label="Close">';
    dialogTemplate += '<span aria-hidden="true">&times;</span>';
    dialogTemplate += '</button>';
    dialogTemplate += '<%= message %>';
    dialogTemplate += '</div>';
    dialogTemplate = _.template(dialogTemplate);
    $('#project-upload-message-area').append(dialogTemplate({type: type, message: message}));
}
{'fraction_non_alphanumeric': 0.14826982041173895, 'fraction_numerical': 0.0010950503723171265, 'mean_word_length': 3.2444237918215615, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '103094', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1281, 'n_words': 361}