<commit_before>/*
 * Init login overlay
 */
$('document').ready(function () {
    $('#modaloverlay').click(function () {
        hideModal();
    });

    $('.modal_box').click(function (e) {
        e.stopPropagation();
    });

    $('#usermanagement').click(function () {
        showLogin();
    });

    $('#loginform').submit(function (e) {
        // Hide the error message 
        $('#login_error').hide();

        // Post the form 
        $.ajax({
            type: "POST",
            url: "/login/" + encodeURIComponent($('#loginform').find('input[name="email"]').val()),
            data: $('#loginform').serialize(),
            success: function () {
                // Reload page when logged in 
                location.reload();
            },
            error: function () {
                // Display error message 
                $('#login_error').html(i18n.__("ServiceNotReachableError"));
                $('#login_error').show();
            }
        });

        // Stop form submit via normal post
        e.preventDefault();
    });
});

/*
 * Log out a user from the system
 */
function logoutUser() {
    $.ajax({
        url: 'logout',
        success: function () {
            location.reload();
        }
    });
}

/*
 * Show the login modal 
 */
function showLogin() {
    // Clear the form 
    $('#login_error').hide();
    $('#loginform')[0].reset();

    // Show the login window 
    $('#yes_no_modal').hide();
    $('#general_modal').hide();
    $('#upload_modal').hide();
    $('#login_modal').show();
    $('#modaloverlay').show();
}

/*
 * Show the Yes and No modal with callback
 */
function showYesNoModal(body, callback) {
    // Hide the login window 
    $('#login_modal').hide();
    $('#general_modal').hide();
    $('#upload_modal').hide();
    $('#yes_no_modal').show();

    // Fill up the body
    $('#modal_title_body').html = body;

    // Show the modal
    $('#modaloverlay').show();

    $('#ynmodel-y-btn').click(function () {
        callback(true);
        hideModal();
    });

    $('#ynmodal-n-btn').click(function () {
        callback(false);
        hideModal();
    });
}

function showUploadModal()
{
    $('#login_modal').hide();
    $('#yes_no_modal').hide();
    $('#general_modal').hide();
    $('#upload_modal').show();

    $('#modaloverlay').show();
}

function showGeneralModal()
{
    $('#login_modal').hide();
    $('#yes_no_modal').hide();
    $('#upload_modal').hide();
    $('#general_modal').show();

    // Show the modal
    $('#modaloverlay').show();
}

function setGeneralModalTitle(title)
{
    $('#general_modal_title').html(title);
}

function setGeneralModalBody(body)
{
    $('#general_modal_body').html(body);
}

function getGeneralModalBody()
{
    return $('#general_modal_body').html();
}

function addGeneralModalButton(text, action)
{
    var button = document.createElement('button');
    $(button).addClass('btn btn-primary inline btn-extra-margin');
    $(button).click(function () {
        action();
    });
    $(button).html(text);
    $('#general_modal_buttons').append(button);
}

function resetGeneralModal()
{
    $('#general_modal_title').empty();
    $('#general_modal_body').empty();
    $('#general_modal_buttons').empty();
}

function hideModal() {
    $('#modaloverlay').hide();
}

$(document).ready(function () {
    $('#uploadformbtn').click(function () {
        // Get the form data. This serializes the entire form. pritty easy huh!
        var form = new FormData($('#uploadform')[0]);

        // Make the ajax call
        $.ajax({
            url: '/api/upload',
            type: 'POST',
            xhr: function () {
                var myXhr = $.ajaxSettings.xhr();
                if (myXhr.upload) {
                    myXhr.upload.addEventListener('progress', progress, false);
                }
                return myXhr;
            },
            //add beforesend handler to validate or something
            beforeSend: function () {
                $('progress').attr({value: 0, max: 100});                
                $('#upload-result').html('<span data-bind="text: progress">Progress</span>: <progress value="0" max="100" id="progressbar"></progress>');
            },
            success: function (res) {       
                $('#upload-result').html('<p><span data-bind="text: uploadedFiles">Uploaded files</span>:</p><div id="uploaded-files"></div>');

                $.each(res, function (index, elem) {
                    var div = document.createElement('div');
                    div.className += 'upimage';
                    $('#uploaded-files').append(div);
                    
                    var src = elem['link'];
                    
                    if(!elem['type'].startsWith('png')
                       || !elem['type'].startsWith('jpg')
                       || !elem['type'].startsWith('jpeg')){
                        src = '/img/file.png';
                    }

                    div.innerHTML += '<a href="' + elem['link'] + '" target="_blank"><img src="' + src + '" style="width: 100px;" /></a><br/>';
                    div.innerHTML += 'id: ' + elem['id'] + '<br/>';
                    div.innerHTML += 'type: ' + elem['type'] + '<br/>';
                    div.innerHTML += 'name: ' + elem['name'] + '<br/>';
                    div.innerHTML += 'size: ' + elem['size'] + '';
                });
            },
            //add error handler for when a error occurs if you want!
            error: function (xhr, status, error) {
                setGeneralModalTitle('Upload error');
                setGeneralModalBody(xhr.responseText);
                showGeneralModal();

            },
            data: form,
            // this is the important stuf you need to overide the usual post behavior
            cache: false,
            contentType: false,
            processData: false
        });
    });
});<commit_msg>updated upload to fit in dptcms<commit_after>/*
 * Init login overlay
 */
$('document').ready(function () {
    $('#modaloverlay').click(function () {
        hideModal();
    });

    $('.modal_box').click(function (e) {
        e.stopPropagation();
    });

    $('#usermanagement').click(function () {
        showLogin();
    });

    $('#loginform').submit(function (e) {
        // Hide the error message 
        $('#login_error').hide();

        // Post the form 
        $.ajax({
            type: "POST",
            url: "/login/" + encodeURIComponent($('#loginform').find('input[name="email"]').val()),
            data: $('#loginform').serialize(),
            success: function () {
                // Reload page when logged in 
                location.reload();
            },
            error: function () {
                // Display error message 
                $('#login_error').html(i18n.__("ServiceNotReachableError"));
                $('#login_error').show();
            }
        });

        // Stop form submit via normal post
        e.preventDefault();
    });
});

/*
 * Log out a user from the system
 */
function logoutUser() {
    $.ajax({
        url: 'logout',
        success: function () {
            location.reload();
        }
    });
}

/*
 * Show the login modal 
 */
function showLogin() {
    // Clear the form 
    $('#login_error').hide();
    $('#loginform')[0].reset();

    // Show the login window 
    $('#yes_no_modal').hide();
    $('#general_modal').hide();
    $('#upload_modal').hide();
    $('#login_modal').show();
    $('#modaloverlay').show();
}

/*
 * Show the Yes and No modal with callback
 */
function showYesNoModal(body, callback) {
    // Hide the login window 
    $('#login_modal').hide();
    $('#general_modal').hide();
    $('#upload_modal').hide();
    $('#yes_no_modal').show();

    // Fill up the body
    $('#modal_title_body').html = body;

    // Show the modal
    $('#modaloverlay').show();

    $('#ynmodel-y-btn').click(function () {
        callback(true);
        hideModal();
    });

    $('#ynmodal-n-btn').click(function () {
        callback(false);
        hideModal();
    });
}

function showUploadModal()
{
    $('#login_modal').hide();
    $('#yes_no_modal').hide();
    $('#general_modal').hide();
    $('#upload_modal').show();

    $('#modaloverlay').show();
}

function showGeneralModal()
{
    $('#login_modal').hide();
    $('#yes_no_modal').hide();
    $('#upload_modal').hide();
    $('#general_modal').show();

    // Show the modal
    $('#modaloverlay').show();
}

function setGeneralModalTitle(title)
{
    $('#general_modal_title').html(title);
}

function setGeneralModalBody(body)
{
    $('#general_modal_body').html(body);
}

function getGeneralModalBody()
{
    return $('#general_modal_body').html();
}

function addGeneralModalButton(text, action)
{
    var button = document.createElement('button');
    $(button).addClass('btn btn-primary inline btn-extra-margin');
    $(button).click(function () {
        action();
    });
    $(button).html(text);
    $('#general_modal_buttons').append(button);
}

function resetGeneralModal()
{
    $('#general_modal_title').empty();
    $('#general_modal_body').empty();
    $('#general_modal_buttons').empty();
}

function hideModal() {
    $('#modaloverlay').hide();
}

$(document).ready(function () {
    $('#uploadformbtn').click(function () {
        // Get the form data. This serializes the entire form. pritty easy huh!
        var form = new FormData($('#uploadform')[0]);

        // Make the ajax call
        $.ajax({
            url: '/api/upload',
            type: 'POST',
            xhr: function () {
                var myXhr = $.ajaxSettings.xhr();
                if (myXhr.upload) {
                    myXhr.upload.addEventListener('progress', progress, false);
                }
                return myXhr;
            },
            //add beforesend handler to validate or something
            beforeSend: function () {
                $('progress').attr({value: 0, max: 100});                
                $('#upload-result').html('<span data-bind="text: progress">Progress</span>: <progress value="0" max="100" id="progressbar"></progress>');
            },
            success: function (res) {       
                $('#upload-result').html('<p><span data-bind="text: uploadedFiles">Uploaded files</span>:</p><div id="uploaded-files"></div>');

                $.each(res, function (index, elem) {
                    var div = document.createElement('div');
                    div.className += 'upimage';
                    $('#uploaded-files').append(div);
                    
                    var src = elem['link'];
                    
                    if(!elem['type'] != 'png'
                       || !elem['type'] != 'jpg'
                       || !elem['type'] != 'jpeg'){
                        src = '/img/file.png';
                    }

                    div.innerHTML += '<a href="' + elem['link'] + '" target="_blank"><img src="' + src + '" style="width: 100px;" /></a><br/>';
                    div.innerHTML += 'id: ' + elem['id'] + '<br/>';
                    div.innerHTML += 'type: ' + elem['type'] + '<br/>';
                    div.innerHTML += 'name: ' + elem['name'] + '<br/>';
                    div.innerHTML += 'size: ' + elem['size'] + '';
                });
            },
            //add error handler for when a error occurs if you want!
            error: function (xhr, status, error) {
                setGeneralModalTitle('Upload error');
                setGeneralModalBody(xhr.responseText);
                showGeneralModal();

            },
            data: form,
            // this is the important stuf you need to overide the usual post behavior
            cache: false,
            contentType: false,
            processData: false
        });
    });
});
{'fraction_non_alphanumeric': 0.18731550982541958, 'fraction_numerical': 0.0025301509656742854, 'mean_word_length': 1.9315203955500617, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '4386393', 'n_tokens_mistral': 3284, 'n_tokens_neox': 3219, 'n_words': 652}