<commit_before>/* global utility, loader, flashBag */

var ajax = new Ajax();

function Ajax() {
    // Vars
    var self = this;
    
    // Properties
    
    // Functions public
    self.send = function(loaderEnabled, messageHide, url, method, data, dataType, cache, callbackBefore, callbackSuccess, callbackError, callbackComplete) {
        if (loaderEnabled === true)
            loader.show();
        
        if (messageHide === true && window.session.userActivity === "")
            flashBag.hide();
        
        $.ajax({
            'url': url,
            'method': method,
            'data': data,
            'dataType': dataType,
            'cache': cache,
            beforeSend: function() {
                if (callbackBefore !== null)
                    callbackBefore();
            },
            success: function(xhr) {
                if (xhr.userActivity !== undefined && xhr.userActivity !== "") {
                    window.session.userActivity = xhr.userActivity;
                    
                    self.reply(xhr, "");
                    
                    return;
                }
                
                if (callbackSuccess !== null)
                    callbackSuccess(xhr);
                
                if (loaderEnabled === true)
                    loader.hide();
                
                flashBag.show();
            },
            error: function(xhr, status) {
                if (loaderEnabled === true)
                    loader.hide();
                
                flashBag.hide();
                
                if (xhr.status === 408 || status === "timeout")
                    self.send(loaderEnabled, messageHide, url, method, data, dataType, cache, callbackBefore, callbackSuccess, callbackError, callbackComplete);
                else {
                    if (callbackError !== null)
                        callbackError(xhr);
                }
            },
            complete: function() {
                if (callbackComplete !== null)
                    callbackComplete();
            }
        });
    };
    
    self.reply = function(xhr, tag) {
        var reply = "";
        
        if ($("#menu_root_navbar").hasClass("in") === true)
            $("#menu_root_nav_button").click();
        
        if ($(tag).length > 0)
            $(tag).find("*[required='required']").parents(".form-group").removeClass("has-error");

        if ($.isEmptyObject(xhr.response) === true) {
            $("#flashBag").prop({'class': "alert alert-danger"});
            
            reply = "<p>" + window.text.ajaxConnectionError + "</p>";
        }
        
        if (xhr.response === undefined) {
            $("#flashBag").prop({'class': "alert alert-danger"});

            reply = xhr;
        }
        else {
            if (xhr.response.messages !== undefined) {
                if (xhr.response.messages.error !== undefined) {
                    $("#flashBag").prop({'class': "alert alert-danger"});

                    reply = "<p>" + xhr.response.messages.error + "</p>";
                }
                else if (xhr.response.messages.info !== undefined) {
                    $("#flashBag").prop({'class': "alert alert-info"});

                    reply = "<p>" + xhr.response.messages.info + "</p>";
                }
                else if (xhr.response.messages.success !== undefined) {
                    $("#flashBag").prop({'class': "alert alert-success"});

                    reply = "<p>" + xhr.response.messages.success + "</p>";
                }
            }

            if (xhr.response.errors !== undefined) {
                $("#flashBag").prop({'class': "alert alert-danger"});

                var list = "<ul>";

                if (typeof(xhr.response.errors) !== "string") {
                    var errors = xhr.response.errors;

                    $.each(errors, function(key, value) {
                        if (typeof(value[0]) === "string" && $.isEmptyObject(value) === false && key !== "_token") {
                            var object = null;
                            
                            if ($(tag).length > 0)
                                object = $(tag).find("*[name*='"+ key + "']")[0];
                            
                            if (object !== undefined) {
                                $(object).parents(".form-group").addClass("has-error");

                                var icon = "";
                                var label = " - ";

                                if ($(object).parents(".form-group").find(".input-group-addon").length > 0)
                                    icon = $(object).parents(".form-group").find(".input-group-addon").html();
                                
                                if ($(object).parents(".form-group").find("label").html() !== undefined)
                                    label = $(object).parents(".form-group").find("label").html();
                                else if ($($(object).parents(".form-group").find("*[name*='"+ key + "']")).prop("placeholder") !== undefined)
                                    label = $($(object).parents(".form-group").find("*[name*='"+ key + "']")).prop("placeholder");
                                
                                list += "<li>" + icon + " <b>" + label + "</b>: " + value[0] + "</li>";
                            }
                        }
                    });
                }
                else
                    list += "<li>" + xhr.response.errors + "</li>";

                list += "</ul>";

                reply += list;
            }
            
            if (xhr.response.session !== undefined && xhr.response.session.userActivity !== undefined)
                window.session.userActivity = xhr.response.session.userActivity;
        }
        
        if (reply !== "")
            $("#flashBag").find(".content").html(reply);
        
        flashBag.sessionActivity();
        
        utility.linkPreventDefault();
    };
    
    // Functions private
}<commit_msg>Code - Fix<commit_after>/* global utility, loader, flashBag */

var ajax = new Ajax();

function Ajax() {
    // Vars
    var self = this;
    
    // Properties
    
    // Functions public
    self.send = function(loaderEnabled, messageHide, url, method, data, dataType, cache, callbackBefore, callbackSuccess, callbackError, callbackComplete) {
        if (loaderEnabled === true)
            loader.show();
        
        if (messageHide === true && window.session.userActivity === "")
            flashBag.hide();
        
        $.ajax({
            'url': url,
            'method': method,
            'data': data,
            'dataType': dataType,
            'cache': cache,
            beforeSend: function() {
                if (callbackBefore !== null)
                    callbackBefore();
            },
            success: function(xhr) {
                if (xhr.userActivity !== undefined && xhr.userActivity !== "") {
                    window.session.userActivity = xhr.userActivity;
                    
                    self.reply(xhr, "");
                    
                    return;
                }
                
                if (callbackSuccess !== null)
                    callbackSuccess(xhr);
                
                if (loaderEnabled === true)
                    loader.hide();
                
                flashBag.show();
            },
            error: function(xhr, status) {
                if (loaderEnabled === true)
                    loader.hide();
                
                flashBag.hide();
                
                if (xhr.status === 408 || status === "timeout")
                    self.send(loaderEnabled, messageHide, url, method, data, dataType, cache, callbackBefore, callbackSuccess, callbackError, callbackComplete);
                else {
                    if (callbackError !== null)
                        callbackError(xhr);
                }
            },
            complete: function() {
                if (callbackComplete !== null)
                    callbackComplete();
            }
        });
    };
    
    self.reply = function(xhr, tag) {
        var reply = "";
        
        if ($("#menu_root_navbar").hasClass("in") === true)
            $("#menu_root_nav_button").click();
        
        if ($(tag).length > 0)
            $(tag).find("*[required='required']").parents(".form-group").removeClass("has-error");

        if ($.isEmptyObject(xhr.response) === true) {
            $("#flashBag").prop({'class': "alert alert-danger"});
            
            reply = "<p>" + window.text.ajaxConnectionError + "</p>";
        }
        
        if (xhr.response === undefined) {
            $("#flashBag").prop({'class': "alert alert-danger"});

            reply = xhr;
        }
        else {
            if (xhr.response.messages !== undefined) {
                if (xhr.response.messages.error !== undefined) {
                    $("#flashBag").prop({'class': "alert alert-danger"});

                    reply = "<p>" + xhr.response.messages.error + "</p>";
                }
                else if (xhr.response.messages.info !== undefined) {
                    $("#flashBag").prop({'class': "alert alert-info"});

                    reply = "<p>" + xhr.response.messages.info + "</p>";
                }
                else if (xhr.response.messages.success !== undefined) {
                    $("#flashBag").prop({'class': "alert alert-success"});

                    reply = "<p>" + xhr.response.messages.success + "</p>";
                }
            }

            if (xhr.response.errors !== undefined) {
                $("#flashBag").prop({'class': "alert alert-danger"});

                var list = "<ul>";

                if (typeof(xhr.response.errors) !== "string") {
                    var errors = xhr.response.errors;

                    $.each(errors, function(key, value) {
                        if (typeof(value[0]) === "string" && $.isEmptyObject(value) === false && key !== "_token") {
                            var object = null;
                            
                            if ($(tag).length > 0)
                                object = $(tag).find("*[name*='"+ key + "']")[0];
                            
                            if (object !== undefined) {
                                $(object).parents(".form-group").addClass("has-error");

                                var icon = "";
                                var label = " - ";

                                if ($(object).parents(".form-group").find(".input-group-addon").length > 0)
                                    icon = $(object).parents(".form-group").find(".input-group-addon").html();
                                
                                if ($(object).parents(".form-group").find("label").html() !== undefined)
                                    label = $(object).parents(".form-group").find("label").html();
                                else if ($($(object).parents(".form-group").find("*[name*='"+ key + "']")).prop("placeholder") !== undefined)
                                    label = $($(object).parents(".form-group").find("*[name*='"+ key + "']")).prop("placeholder");
                                
                                if (Array.isArray(value) === true)
                                    list += "<li>" + icon + " <b>" + label + "</b>: " + value[0] + "</li>";
                                else
                                    list += "<li>" + icon + " <b>" + label + "</b>: " + value + "</li>";
                            }
                        }
                    });
                }
                else
                    list += "<li>" + xhr.response.errors + "</li>";

                list += "</ul>";

                reply += list;
            }
            
            if (xhr.response.session !== undefined && xhr.response.session.userActivity !== undefined)
                window.session.userActivity = xhr.response.session.userActivity;
        }
        
        if (reply !== "")
            $("#flashBag").find(".content").html(reply);
        
        flashBag.sessionActivity();
        
        utility.linkPreventDefault();
    };
    
    // Functions private
}
{'fraction_non_alphanumeric': 0.1567632850241546, 'fraction_numerical': 0.0014492753623188406, 'mean_word_length': 1.1658238884045335, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 23, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7664343', 'n_tokens_mistral': 3074, 'n_tokens_neox': 2888, 'n_words': 555}