<commit_before>var eo_creation_url;

$(document).ready(function () {
    "use strict";

    $(document).foundation();

    $(".toolbox label input").each(function () {
        var $this = $(this);
        $this.parent().addClass("toolbox-option-{0}".format($this.val()));
    });

});

var app = window.angular.module(
    'labelingApp',
    ['ngResource', 'ngRoute', 'ngCookies']
).run(
    function ($http, $cookies) {
        $http.defaults.headers.post['X-CSRFToken'] = $cookies.csrftoken;
        // Add the following two lines
        $http.defaults.xsrfCookieName = 'csrftoken';
        $http.defaults.xsrfHeaderName = 'X-CSRFToken';
    }
);

app.factory('EntityOccurrence', ['$resource',
    function ($resource) {
        return $resource('/corpus/crud/entity_occurrence/', {'pk': '@pk'}, {});
    }
]);
app.factory('Entity', ['$resource',
    function ($resource) {
        return $resource('/corpus/crud/entity/', {'pk': '@pk'}, {});
    }
]);

app.directive('ngRightClick', function ($parse) {
    return function ($scope, element, attrs) {
        var fn = $parse(attrs.ngRightClick);
        element.bind('contextmenu', function (event) {
            $scope.$apply(function () {
                event.preventDefault();
                fn($scope, {$event: event});
            });
        });
    };
});

app.controller('QuestionsController', ['$scope', 'EntityOccurrence', 'Entity',
function ($scope, EntityOccurrence, Entity) {
    "use strict";
    // ### Attributes ###

    $scope.eo_selected = undefined; // Id of the selected occurrence

    // Publish into the scope the variables defined globally
    $scope.eos = window.eos;
    $scope.forms = window.forms;
    $scope.relations = window.relations;
    $scope.current_tool = window.initial_tool;
    $scope.different_kind = window.different_kind;
    $scope.question_options = window.question_options;
    $scope.other_judges_labels = window.other_judges_labels;
    $scope.arrows = {};
    $scope.eo_edition_modal = {};
    $scope.eo_creation_modal = {};
    $scope.metadata_visible = "pos";
    $scope.interaction_activated = true;

    $(document).ready(function () {
        $scope.$segments = $(".segments");
        $scope.$svg = $("svg");
        $scope.svg = $scope.$svg[0];

        $(window).resize($scope.update_relations_arrows);
        $("body").keypress(function (event) {
            var $toolbox_options = $(".toolbox li input");
            var index = event.which - 49;
            if (index >= 0 && index <= 5) {
                $scope.current_tool = $scope.question_options[index];
                $($toolbox_options[index]).prop("checked", "checked");
            }
        });

        setTimeout($scope.update_relations_arrows, 300);

        $(".rich-token").on("click", function (event, stop) {
            stop = stop === undefined ? true : stop;

            if (stop) {
                event.preventDefault();
                event.stopPropagation();
            }
        });
        $(".eo-submenu").on("click", $scope.on_eo_submenu_click);
        $(".eo-submenu").mouseover($scope.highlight_eo_tokens);
        $(".eo-submenu").mouseout($scope.highlight_eo_tokens);

        $(".judge-answers-wrapper").change(function(){
            var $this = $(this);
            var selected = $this.val();
            if(selected === "me"){
                $scope.interaction_activated = true;
                $scope.update_relations_arrows();
            } else {
                $scope.interaction_activated = false;
                $scope.draw_judge_answers(selected);
            }
        });

        $(".entity-occurrence").mouseover(function () {
            var $eo = $(this);
            $scope.on_eo_mouseover($eo, false);
        });
        $(".entity-occurrence").mouseout(function () {
            var $eo = $(this);
            $scope.on_eo_mouseover($eo, true);
        });

        // EO Creation modal
        $scope.eo_creation_modal.elem = $('#eo-creation-modal');
        $scope.eo_creation_modal.elem.find('a.save').bind('click', function () {
            $scope.eo_creation_modal.submit();
        });
        $scope.eo_creation_modal.elem.find('a.cancel').bind('click', function () {
            $scope.eo_creation_modal.elem.foundation('reveal', 'close');
        });

        // EO Edition modal
        $scope.eo_edition_modal.elem = $('#eo-edition-modal');
        $scope.eo_edition_modal.elem.find('a.cancel').bind('click', function () {
            $scope.eo_edition_modal.elem.foundation('reveal', 'close');
        });
        $scope.eo_edition_modal.elem.find('a.save').bind('click', function () {
            $scope.eo_edition_modal.submit();
        });
        $scope.eo_edition_modal.elem.find('a.remove-eo-ask').bind(
            'click', $scope.eo_edition_modal.remove_eo_ask
        );
        $scope.eo_edition_modal.elem.find('a.remove-eo-confirm').bind(
            'click', $scope.eo_edition_modal.remove_eo_confirm
        );
        $scope.eo_edition_modal.elem.find('a.remove-eo-confirm-all').bind(
            'click', $scope.eo_edition_modal.remove_eo_confirm_all
        );
        $scope.eo_edition_modal.elem.find('a.remove-eo-cancel').bind(
            'click', $scope.eo_edition_modal.remove_eo_cancel
        );
    });

    // ### Methods ###

    $scope.clean_all_arrows = function () {
        // Remove all arrows before re-drawing
        $($scope.svg).find("path").each(function () {
            var $elem = $(this);
            if ($elem.parent("marker").length === 0) {
                $scope.svg.removeChild($elem[0]);
            }
        });

        $scope.arrows = {};
    };

    $scope.update_relations_arrows = function () {
        // Update width and height of the svg element
        $scope.$svg.attr("width", $scope.$segments.width());
        $scope.$svg.attr("height", $scope.$segments.height() + 100);

        $scope.clean_all_arrows();

        var data = [];
        for (var i in $scope.relations) {
            if ($scope.relations.hasOwnProperty(i)) {
                var rel_obj = $scope.relations[i];
                var path = $scope.calculate_arrow_string(
                    rel_obj.relation[0],
                    rel_obj.relation[1],
                    $scope.forms[rel_obj.form_id]
                );
                $scope.arrows[rel_obj.form_id] = path;
            }
        }
    };

    $scope.set_selectables = function (value) {
        // Sets the value for selectable on all entity occurrences
        for (var i in $scope.eos) {
            if ($scope.eos.hasOwnProperty(i)) {
                $scope.eos[i].selectable = value;
            }
        }
    };

    $scope.eo_click = function (ids) {
        // Handles only the case of 1 id, if it has
        // more than one, it shows the menu
        if (ids.length === 1) {
            var id = ids[0];
            $scope.handle_click_on_eo(id);
        }
    };

    $scope.on_eo_submenu_click = function (event) {
        event.preventDefault();

        var $this = $(this);
        var eo_id = $this.data("eo-id");
        $scope.handle_click_on_eo(eo_id);
        $scope.$apply();
    };
<commit_msg>simplified right click directive, eo_click handles left click only<commit_after>var eo_creation_url;

$(document).ready(function () {
    "use strict";

    $(document).foundation();

    $(".toolbox label input").each(function () {
        var $this = $(this);
        $this.parent().addClass("toolbox-option-{0}".format($this.val()));
    });

});

var app = window.angular.module(
    'labelingApp',
    ['ngResource', 'ngRoute', 'ngCookies']
).run(
    function ($http, $cookies) {
        $http.defaults.headers.post['X-CSRFToken'] = $cookies.csrftoken;
        // Add the following two lines
        $http.defaults.xsrfCookieName = 'csrftoken';
        $http.defaults.xsrfHeaderName = 'X-CSRFToken';
    }
);

app.factory('EntityOccurrence', ['$resource',
    function ($resource) {
        return $resource('/corpus/crud/entity_occurrence/', {'pk': '@pk'}, {});
    }
]);
app.factory('Entity', ['$resource',
    function ($resource) {
        return $resource('/corpus/crud/entity/', {'pk': '@pk'}, {});
    }
]);

app.directive('ngRightClick', function ($parse) {
    return function ($scope, element, attrs) {
        var fn = $parse(attrs.ngRightClick);
        element.bind('contextmenu', function (event) {
            event.preventDefault();
            fn($scope, {$event: event});
        });
    };
});

app.controller('QuestionsController', ['$scope', 'EntityOccurrence', 'Entity',
function ($scope, EntityOccurrence, Entity) {
    "use strict";
    // ### Attributes ###

    $scope.eo_selected = undefined; // Id of the selected occurrence

    // Publish into the scope the variables defined globally
    $scope.eos = window.eos;
    $scope.forms = window.forms;
    $scope.relations = window.relations;
    $scope.current_tool = window.initial_tool;
    $scope.different_kind = window.different_kind;
    $scope.question_options = window.question_options;
    $scope.other_judges_labels = window.other_judges_labels;
    $scope.arrows = {};
    $scope.eo_edition_modal = {};
    $scope.eo_creation_modal = {};
    $scope.metadata_visible = "pos";
    $scope.interaction_activated = true;

    $(document).ready(function () {
        $scope.$segments = $(".segments");
        $scope.$svg = $("svg");
        $scope.svg = $scope.$svg[0];

        $(window).resize($scope.update_relations_arrows);
        $("body").keypress(function (event) {
            var $toolbox_options = $(".toolbox li input");
            var index = event.which - 49;
            if (index >= 0 && index <= 5) {
                $scope.current_tool = $scope.question_options[index];
                $($toolbox_options[index]).prop("checked", "checked");
            }
        });

        setTimeout($scope.update_relations_arrows, 300);

        $(".rich-token").on("click", function (event, stop) {
            stop = stop === undefined ? true : stop;

            if (stop) {
                event.preventDefault();
                event.stopPropagation();
            }
        });
        $(".eo-submenu").on("click", $scope.on_eo_submenu_click);
        $(".eo-submenu").mouseover($scope.highlight_eo_tokens);
        $(".eo-submenu").mouseout($scope.highlight_eo_tokens);

        $(".judge-answers-wrapper").change(function(){
            var $this = $(this);
            var selected = $this.val();
            if(selected === "me"){
                $scope.interaction_activated = true;
                $scope.update_relations_arrows();
            } else {
                $scope.interaction_activated = false;
                $scope.draw_judge_answers(selected);
            }
        });

        $(".entity-occurrence").mouseover(function () {
            var $eo = $(this);
            $scope.on_eo_mouseover($eo, false);
        });
        $(".entity-occurrence").mouseout(function () {
            var $eo = $(this);
            $scope.on_eo_mouseover($eo, true);
        });

        // EO Creation modal
        $scope.eo_creation_modal.elem = $('#eo-creation-modal');
        $scope.eo_creation_modal.elem.find('a.save').bind('click', function () {
            $scope.eo_creation_modal.submit();
        });
        $scope.eo_creation_modal.elem.find('a.cancel').bind('click', function () {
            $scope.eo_creation_modal.elem.foundation('reveal', 'close');
        });

        // EO Edition modal
        $scope.eo_edition_modal.elem = $('#eo-edition-modal');
        $scope.eo_edition_modal.elem.find('a.cancel').bind('click', function () {
            $scope.eo_edition_modal.elem.foundation('reveal', 'close');
        });
        $scope.eo_edition_modal.elem.find('a.save').bind('click', function () {
            $scope.eo_edition_modal.submit();
        });
        $scope.eo_edition_modal.elem.find('a.remove-eo-ask').bind(
            'click', $scope.eo_edition_modal.remove_eo_ask
        );
        $scope.eo_edition_modal.elem.find('a.remove-eo-confirm').bind(
            'click', $scope.eo_edition_modal.remove_eo_confirm
        );
        $scope.eo_edition_modal.elem.find('a.remove-eo-confirm-all').bind(
            'click', $scope.eo_edition_modal.remove_eo_confirm_all
        );
        $scope.eo_edition_modal.elem.find('a.remove-eo-cancel').bind(
            'click', $scope.eo_edition_modal.remove_eo_cancel
        );
    });

    // ### Methods ###

    $scope.clean_all_arrows = function () {
        // Remove all arrows before re-drawing
        $($scope.svg).find("path").each(function () {
            var $elem = $(this);
            if ($elem.parent("marker").length === 0) {
                $scope.svg.removeChild($elem[0]);
            }
        });

        $scope.arrows = {};
    };

    $scope.update_relations_arrows = function () {
        // Update width and height of the svg element
        $scope.$svg.attr("width", $scope.$segments.width());
        $scope.$svg.attr("height", $scope.$segments.height() + 100);

        $scope.clean_all_arrows();

        var data = [];
        for (var i in $scope.relations) {
            if ($scope.relations.hasOwnProperty(i)) {
                var rel_obj = $scope.relations[i];
                var path = $scope.calculate_arrow_string(
                    rel_obj.relation[0],
                    rel_obj.relation[1],
                    $scope.forms[rel_obj.form_id]
                );
                $scope.arrows[rel_obj.form_id] = path;
            }
        }
    };

    $scope.set_selectables = function (value) {
        // Sets the value for selectable on all entity occurrences
        for (var i in $scope.eos) {
            if ($scope.eos.hasOwnProperty(i)) {
                $scope.eos[i].selectable = value;
            }
        }
    };

    $scope.eo_click = function (ids) {
        // Handles only left click
        if(event.button !== 0) { return; }

        // Handles only the case of 1 id, if it has
        // more than one, it shows the menu
        if (ids.length === 1) {
            var id = ids[0];
            $scope.handle_click_on_eo(id);
        }
    };

    $scope.on_eo_submenu_click = function (event) {
        event.preventDefault();

        var $this = $(this);
        var eo_id = $this.data("eo-id");
        $scope.handle_click_on_eo(eo_id);
        $scope.$apply();
    };

{'fraction_non_alphanumeric': 0.16416458159577427, 'fraction_numerical': 0.0027105921601334446, 'mean_word_length': 2.152026286966046, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7653104', 'n_tokens_mistral': 4593, 'n_tokens_neox': 4404, 'n_words': 696}