<commit_before>/*! Copyright 2016 - Ortus Solutions (Compiled: 23-03-2016) */
define([ "Backbone", "models/RelaxerHistory" ], function(Backbone, HistoryModel) {
    "use strict";
    var Relaxer = Backbone.View.extend({
        el: ".relaxer",
        events: {
            "click .dynamicAdd": "onAddDynamicItem",
            "click .dynamicRemove": "onRemoveDynamicItem",
            "click .btnSendRequest": "onRelaxerSend"
        },
        initialize: function(options) {
            var _this = this;
            if (_.isUndefined(rootAssetPath)) {
                _this.baseHref = "/modules/relax";
            } else {
                _this.baseHref = rootAssetPath;
            }
            if (!_.isUndefined(options)) {
                _.each(_.keys(options), function(optionKey) {
                    _this[optionKey] = options[optionKey];
                });
            }
            return this.setupDefaults().setupSelectors().render();
        },
        setupSelectors: function() {
            return this;
        },
        setupDefaults: function() {
            var _this = this;
            _this.HistoryModel = new HistoryModel();
            _this.relaxerFormTemplate = _.template($("#relaxer-form-template").html());
            _this.relaxerResponseTemplate = _.template($("#relaxer-response-template").html());
            return this;
        },
        render: function() {
            var _this = this;
            var relaxerFormData = _this.getRelaxerFormData();
            $(".relaxer-form", _this.el).html(_this.relaxerFormTemplate(relaxerFormData));
            _this.onRelaxerRendered();
            return _this.this;
        },
        renderRelaxerResponse: function(jqXHR, textStatus) {
            var _this = this;
            var $container = $(".relaxer-results", _this.$el);
            var responseEcho = JSON.parse(jqXHR.responseText);
            console.debug(responseEcho);
            var responseObject = {
                status: responseEcho.status_code,
                statusText: responseEcho.status_text,
                responseText: responseEcho.filecontent,
                getAllResponseHeaders: function() {
                    return responseEcho.responseheader;
                },
                getResponseHeader: function(headerName) {
                    return responseEcho.responseheader[headerName];
                }
            };
            $container.html(_this.relaxerResponseTemplate({
                response: responseObject
            }));
            _this.renderContainerUI($container);
        },
        getRelaxerFormData: function() {
            var _this = this;
            var relaxerData = {
                api: _this.APIDocument,
                relaxer: {
                    method: "",
                    endpoint: "",
                    extensionDetection: false
                }
            };
            return relaxerData;
        },
        onRelaxerRendered: function() {
            var _this = this;
            _this.$relaxerForm = $(".relaxerForm", _this.$el);
            _this.$resultsBox = $(".relaxerResults", _this.$el);
            _this.$relaxerHeader = $(".relaxerHeader", _this.$el);
        },
        onRelaxerSend: function(e) {
            var _this = this;
            var $btn = $(e.currentTarget);
            var btnDefaultHTML = $btn.html();
            $btn.find("i").removeClass("fa-paper-plane").addClass("fa-spin fa-spinner");
            if ($(".advancedSettings", _this.$el).hasClass("in")) $(".advancedSettings", _this.$el).removeClass("in");
            $(".relaxer-results", _this.$el).html(_this.loaderMsg);
            var _this = this;
            var relaxerRequest = _this.marshallRelaxerRequest();
            var relaxerOptions = {
                url: "/relax/relaxer/send",
                method: "POST",
                data: JSON.stringify(relaxerRequest),
                complete: function(jqXHR, textStatus) {
                    $btn.html(btnDefaultHTML);
                    _this.renderRelaxerResponse(jqXHR, textStatus);
                    _this.HistoryModel.attributes.history.push({
                        request: relaxerRequest,<commit_msg>Update relaxer.js<commit_after>/*! Copyright 2016 - Ortus Solutions (Compiled: 23-03-2016) */
define([ "Backbone", "models/RelaxerHistory" ], function(Backbone, HistoryModel) {
    "use strict";
    var Relaxer = Backbone.View.extend({
        el: ".relaxer",
        events: {
            "click .dynamicAdd": "onAddDynamicItem",
            "click .dynamicRemove": "onRemoveDynamicItem",
            "click .btnSendRequest": "onRelaxerSend"
        },
        initialize: function(options) {
            var _this = this;
            if (_.isUndefined(rootAssetPath)) {
                _this.baseHref = "/modules/relax";
            } else {
                _this.baseHref = rootAssetPath;
            }
            if (!_.isUndefined(options)) {
                _.each(_.keys(options), function(optionKey) {
                    _this[optionKey] = options[optionKey];
                });
            }
            return this.setupDefaults().setupSelectors().render();
        },
        setupSelectors: function() {
            return this;
        },
        setupDefaults: function() {
            var _this = this;
            _this.HistoryModel = new HistoryModel();
            _this.relaxerFormTemplate = _.template($("#relaxer-form-template").html());
            _this.relaxerResponseTemplate = _.template($("#relaxer-response-template").html());
            return this;
        },
        render: function() {
            var _this = this;
            var relaxerFormData = _this.getRelaxerFormData();
            $(".relaxer-form", _this.el).html(_this.relaxerFormTemplate(relaxerFormData));
            _this.onRelaxerRendered();
            return _this.this;
        },
        renderRelaxerResponse: function(jqXHR, textStatus) {
            var _this = this;
            var $container = $(".relaxer-results", _this.$el);
            var responseEcho = JSON.parse(jqXHR.responseText);
            console.debug(responseEcho);
            var responseObject = {
                status: responseEcho.Statuscode,
                statusText: responseEcho.Statuscode,
                responseText: responseEcho.Filecontent,
                getAllResponseHeaders: function() {
                    return responseEcho.Responseheader;
                },
                getResponseHeader: function(headerName) {
                    return responseEcho.Responseheader[headerName];
                }
            };
            $container.html(_this.relaxerResponseTemplate({
                response: responseObject
            }));
            _this.renderContainerUI($container);
        },
        getRelaxerFormData: function() {
            var _this = this;
            var relaxerData = {
                api: _this.APIDocument,
                relaxer: {
                    method: "",
                    endpoint: "",
                    extensionDetection: false
                }
            };
            return relaxerData;
        },
        onRelaxerRendered: function() {
            var _this = this;
            _this.$relaxerForm = $(".relaxerForm", _this.$el);
            _this.$resultsBox = $(".relaxerResults", _this.$el);
            _this.$relaxerHeader = $(".relaxerHeader", _this.$el);
        },
        onRelaxerSend: function(e) {
            var _this = this;
            var $btn = $(e.currentTarget);
            var btnDefaultHTML = $btn.html();
            $btn.find("i").removeClass("fa-paper-plane").addClass("fa-spin fa-spinner");
            if ($(".advancedSettings", _this.$el).hasClass("in")) $(".advancedSettings", _this.$el).removeClass("in");
            $(".relaxer-results", _this.$el).html(_this.loaderMsg);
            var _this = this;
            var relaxerRequest = _this.marshallRelaxerRequest();
            var relaxerOptions = {
                url: "/relax/relaxer/send",
                method: "POST",
                data: JSON.stringify(relaxerRequest),
                beforeSend: function(xhrObj){
                    xhrObj.setRequestHeader("Content-Type", "text/html");
                },
                complete: function(jqXHR, textStatus) {
                    $btn.html(btnDefaultHTML);
                    _this.renderRelaxerResponse(jqXHR, textStatus);
                    _this.HistoryModel.attributes.history.push({
                        request: relaxerRequest,
{'fraction_non_alphanumeric': 0.12007942997313398, 'fraction_numerical': 0.0028034108164934003, 'mean_word_length': 1.6598322460391426, 'pattern_counts': {'":': 6, '<': 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': '1556596', 'n_tokens_mistral': 2305, 'n_tokens_neox': 2173, 'n_words': 378}