<commit_before>var ClassificationEditor = new function()
{
    var self = this;

    /**
     * Initialization of the window.
     */
    this.init = function( pid )
    {
        var content_div_id = 'classification_editor_widget';
        // Check if the classification system is set up correctly
        requestQueue.register(django_url + pid + '/classification/show',
            'GET', undefined, self.create_error_aware_callback(
                function(status, data, text) {
                    var e = $.parseJSON(data);
                    var container = document.getElementById(content_div_id);
                    container.innerHTML = e.content;

                    /* depending on the type of the page, some rewrites need to
                     * to be done. That is to make sure that replies on actions
                     * taken on the current page are also rendered in this
                     * CATMAID window.
                     */
                     if (e.page == 'new_graph')
                     {
                        self.overrideNewTreeSubmit(container, pid);
                     }
                     else if (e.page == 'show_graph')
                     {

                     }
                     else if (e.page == 'select_graph')
                     {

                     }
                }));
    };

    this.create_error_aware_callback = function( fx )
    {
        return function(status, data, text)
        {
            if (status !== 200) {
                alert("The server returned an unexpected status (" + status + ") " + "with error message:\n" + text);
            } else {
                fx(status, data, text);
            }
        }
    };

  this.overrideNewTreeSubmit = function(container, pid) {
    var form = $("#add-new-classification-form");
    var found = form.length !== 0;
    if (found) {
        form.submit(function(){
            $.ajax({
                type: "POST",
                url: form.attr('action'),
                data: form.serialize(),
                success: function(data, textStatus) {
                    container.innerHTML = "<p>" + data + "</p><p>Reloading in a few seconds.</p>";
                    setTimeout("ClassificationEditor.init(" + pid + ")", 1500);
                }
            });
            return false;
        });
    }

    return found;
  };
}<commit_msg>Classification editor: add JS overrides to use Django forms in WM<commit_after>var ClassificationEditor = new function()
{
    var self = this;

    /**
     * Initialization of the window.
     */
    this.init = function( pid )
    {
        var content_div_id = 'classification_editor_widget';
        // Check if the classification system is set up correctly
        requestQueue.register(django_url + pid + '/classification/show',
            'GET', undefined, self.create_error_aware_callback(
                function(status, data, text) {
                    var e = $.parseJSON(data);
                    var container = document.getElementById(content_div_id);
                    container.innerHTML = e.content;

                    /* depending on the type of the page, some rewrites need to
                     * to be done. That is to make sure that replies on actions
                     * taken on the current page are also rendered in this
                     * CATMAID window.
                     */
                     if (e.page == 'new_graph')
                     {
                        self.overrideNewTreeSubmit(container, pid);
                     }
                     else if (e.page == 'show_graph')
                     {

                     }
                     else if (e.page == 'select_graph')
                     {

                     }
                }));
    };

    this.create_error_aware_callback = function( fx )
    {
        return function(status, data, text)
        {
            if (status !== 200) {
                alert("The server returned an unexpected status (" + status + ") " + "with error message:\n" + text);
            } else {
                fx(status, data, text);
            }
        }
    };

  this.overrideNewTreeSubmit = function(container, pid) {
    var form = $("#add-new-classification-form");
    var found = form.length !== 0;
    if (found) {
        form.submit(function(){
            $.ajax({
                type: "POST",
                url: form.attr('action'),
                data: form.serialize(),
                success: function(data, textStatus) {
                    container.innerHTML = "<p>" + data + "</p><p>Reloading in a few seconds.</p>";
                    setTimeout("ClassificationEditor.init(" + pid + ")", 1500);
                }
            });
            return false;
        });
    }

    return found;
  };

  this.overrideRemoveTreeLink = function(container, pid) {
    var remove_link = $("#remove_classification_link");
    var found = remove_link.length !== 0;
    if (found) {
         remove_link.click(function(){
             if (confirm("Are you sure you want to remove the whole classification tree?")) {
                 $.ajax({
                     type: "POST",
                     url: remove_link.attr('href'),
                     success: function(data, textStatus) {
                         container.innerHTML = "<p>" + data + "</p><p>Reloading in a few seconds.</p>";
                         setTimeout("ClassificationEditor.init(" + pid + ")", 3000);
                     }
                 });
             }
             return false;
         });
    }

    return found;
  }

  this.overrideAddTreeLink = function(container, pid) {
    var remove_link = $("#add_classification_link");
    var found = remove_link.length !== 0;
    if (found) {
         remove_link.click(function(){
             $.ajax({
                 type: "POST",
                 url: remove_link.attr('href'),
                 success: function(data, textStatus) {
                     container.innerHTML = data;
                 }
             });
             return false;
         });
    }

    return found;
  }
}
{'fraction_non_alphanumeric': 0.11011565401531194, 'fraction_numerical': 0.003583645544877016, 'mean_word_length': 1.3222390317700454, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '1463714', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1454, 'n_words': 393}