<commit_before>/*
* -*- mode: text; coding: utf-8; -*-


   This file is part of Indico.
   Copyright (C) 2002 - 2013 European Organization for Nuclear Research (CERN).

   Indico is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 3 of the
   License, or (at your option) any later version.

   Indico is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Indico; if not, see <http://www.gnu.org/licenses/>.
*/

(function($) {
    $.widget("ui.fieldarea", {

        options: {
            fields_caption: "field"
        },

        _create: function() {
            var self = this;

            self.info = {};
            self.info["next_index"] = 2;

            self.table = $("<table></table>");
            self.element.addClass("field-area scrollable");
            self.element.append(self.table);

            self._handleEvents();
            self._drawTable();
        },

        _handleEvents: function() {
            var self = this;

            self.element.on("focusout", "input", function(e) {
                self._updateField(this);
            });

            self.element.on("click", "a", function(e) {
                e.preventDefault();
                self._deleteRow($(this).closest("tr"));
            });

            self.element.on("keyup propertychange paste", "input", function(e) {
                // Enter
                if (e.type == "keyup" && e.which == 13) {
                    $(this).blur();
                }

                if ($(this).val() === "") {
                    self._deleteInput($(this).closest("tr"));
                }

                self._drawInput();
            });

            self.element.on("keydown", "input", function(e) {
                // ESC
                if (e.which == 27) {
                    e.stopPropagation();
                    value = self.info[$(this).data("id")];
                    $(this).val(value);
                    $(this).blur();
                }
            });
        },

        _drawTable: function() {
            var self = this;
            var table = self.table;

            table.find("tr").each(function() {
                $(this).remove();
            });

            for (var key in self.info) {
                if (!isNaN(key)) {
                    table.append(self._row(key));
                }
            }

            self._drawInput();
        },

        _drawInput: function() {
            // if (this.new_row === undefined || this.new_row.data("removed") || this.new_row.find("input").val() !== "") {
            if (this.new_row === undefined || this.new_row.find("input").val() !== "") {
                this.new_row = this._row();
                this.table.append(this.new_row);
                this.element.scrollTop(this.element[0].scrollHeight);
            }
        },

        _deleteInput: function(row) {
            if (row.next()[0] == this.new_row[0]) {
                this._fixIndex();
                this.new_row.remove();
                this.new_row = row;
            }
        },

        destroy: function() {
            // TODO: destroy
        },

        _deleteRow: function(row) {
            if (row[0] != this.new_row[0]) {
                var id = $(this).closest("tr").find("input").data("id");
                delete this.info[id];
                row.remove();
            }
        },

        _fixIndex: function() {<commit_msg>[IMP] Field area widget destroy method added<commit_after>/*
* -*- mode: text; coding: utf-8; -*-


   This file is part of Indico.
   Copyright (C) 2002 - 2013 European Organization for Nuclear Research (CERN).

   Indico is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 3 of the
   License, or (at your option) any later version.

   Indico is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Indico; if not, see <http://www.gnu.org/licenses/>.
*/

(function($) {
    $.widget("ui.fieldarea", {

        options: {
            fields_caption: "field"
        },

        _create: function() {
            var self = this;

            self.info = {};
            self.info["next_index"] = 2;

            self.table = $("<table></table>");
            self.element.addClass("field-area scrollable");
            self.element.append(self.table);

            self._handleEvents();
            self._drawTable();
        },

        _handleEvents: function() {
            var self = this;

            self.element.on("focusout", "input", function(e) {
                self._updateField(this);
            });

            self.element.on("click", "a", function(e) {
                e.preventDefault();
                self._deleteRow($(this).closest("tr"));
            });

            self.element.on("keyup propertychange paste", "input", function(e) {
                // Enter
                if (e.type == "keyup" && e.which == 13) {
                    $(this).blur();
                }

                if ($(this).val() === "") {
                    self._deleteInput($(this).closest("tr"));
                }

                self._drawInput();
            });

            self.element.on("keydown", "input", function(e) {
                // ESC
                if (e.which == 27) {
                    e.stopPropagation();
                    value = self.info[$(this).data("id")];
                    $(this).val(value);
                    $(this).blur();
                }
            });
        },

        _drawTable: function() {
            var self = this;
            var table = self.table;

            table.find("tr").each(function() {
                $(this).remove();
            });

            for (var key in self.info) {
                if (!isNaN(key)) {
                    table.append(self._row(key));
                }
            }

            self._drawInput();
        },

        _drawInput: function() {
            // if (this.new_row === undefined || this.new_row.data("removed") || this.new_row.find("input").val() !== "") {
            if (this.new_row === undefined || this.new_row.find("input").val() !== "") {
                this.new_row = this._row();
                this.table.append(this.new_row);
                this.element.scrollTop(this.element[0].scrollHeight);
            }
        },

        _deleteInput: function(row) {
            if (row.next()[0] == this.new_row[0]) {
                this._fixIndex();
                this.new_row.remove();
                this.new_row = row;
            }
        },

        destroy: function() {
            this.element.off("focusout click keyup propertychange paste");
            this.element.removeClass("field-area scrollable");
            this.table.remove();
        },

        _deleteRow: function(row) {
            if (row[0] != this.new_row[0]) {
                var id = $(this).closest("tr").find("input").data("id");
                delete this.info[id];
                row.remove();
            }
        },

        _fixIndex: function() {
{'fraction_non_alphanumeric': 0.14042113422038496, 'fraction_numerical': 0.00516729104766826, 'mean_word_length': 1.4601207499205593, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4930872', 'n_tokens_mistral': 2144, 'n_tokens_neox': 1999, 'n_words': 490}