<commit_before>/** @jsx React.DOM */
(function(Perseus) {

require("../core.js");
var Util = require("../util.js");
require("../editor.jsx");
require("../renderer.jsx");
var InfoTip = require("../components/info-tip.jsx");

var Widgets = require("../widgets.js");
var Editor  = Perseus.Editor;


var Table = React.createClass({
    render: function() {
        var headers = this.props.headers;
        return <table className="perseus-widget-table-of-values non-markdown">
            <thead>
                <tr>{
                    _.map(headers, function(header) {
                        return <th>{Perseus.Renderer({content: header})}</th>;
                    })
                }
                </tr>
            </thead>
            <tbody>{
                _(this.props.rows).times(function(r) {
                    return <tr>{
                        _(this.props.columns).times(function(c) {
                            return <td>
                                <input
                                    ref={"answer" + r + "," + c}
                                    type="text"
                                />
                            </td>;
                        })
                    }</tr>;
                }.bind(this))
            }
            </tbody>
        </table>;
    },

    toJSON: function() {
        var self = this;
        return _.map(self.props.answers, function(answer, r) {
            return _.map(self.props.headers, function(header, c) {
                return self.refs["answer" + r + "," + c].getDOMNode().value;
            });
        });
    },

    simpleValidate: function(rubric) {
        return Table.validate(this.toJSON(), rubric);
    },

    focus: function() {
        this.refs["answer0,0"].getDOMNode().focus();
        return true;
    }
});

_.extend(Table, {
    validate: function(state, rubric) {
        var filterNonEmpty = function (table) {
            return _.filter(table, function (row) {

                // Check if row has a cell that is nonempty
                return _.some(row, _.identity);<commit_msg>Have table call onChange<commit_after>/** @jsx React.DOM */
(function(Perseus) {

require("../core.js");
var Util = require("../util.js");
require("../editor.jsx");
require("../renderer.jsx");
var InfoTip = require("../components/info-tip.jsx");

var Widgets = require("../widgets.js");
var Editor  = Perseus.Editor;


var Table = React.createClass({
    render: function() {
        var headers = this.props.headers;
        return <table className="perseus-widget-table-of-values non-markdown">
            <thead>
                <tr>{
                    _.map(headers, function(header) {
                        return <th>{Perseus.Renderer({content: header})}</th>;
                    })
                }
                </tr>
            </thead>
            <tbody>{
                _(this.props.rows).times(function(r) {
                    return <tr>{
                        _(this.props.columns).times((c) => {
                            return <td>
                                <input
                                    ref={"answer" + r + "," + c}
                                    type="text"
                                    onChange={this.handleChange}
                                />
                            </td>;
                        })
                    }</tr>;
                }.bind(this))
            }
            </tbody>
        </table>;
    },

    toJSON: function() {
        var self = this;
        return _.map(self.props.answers, function(answer, r) {
            return _.map(self.props.headers, function(header, c) {
                return self.refs["answer" + r + "," + c].getDOMNode().value;
            });
        });
    },

    handleChange: function() {
        // HACK: We need to know *that* the widget changed, but currently it's
        // not set up in a nice way to tell us *how* it changed
        this.props.onChange({});
    },

    simpleValidate: function(rubric) {
        return Table.validate(this.toJSON(), rubric);
    },

    focus: function() {
        this.refs["answer0,0"].getDOMNode().focus();
        return true;
    }
});

_.extend(Table, {
    validate: function(state, rubric) {
        var filterNonEmpty = function (table) {
            return _.filter(table, function (row) {

                // Check if row has a cell that is nonempty
                return _.some(row, _.identity);
{'fraction_non_alphanumeric': 0.14598214285714287, 'fraction_numerical': 0.0008928571428571428, 'mean_word_length': 1.2932446264073696, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '621641', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1170, 'n_words': 247}