<commit_before>// NOTE must be also eddited in specs.js
requirejs.config({
    baseUrl: "js",
    paths: {
        jquery:     "lib/jquery-1.11.2",
        underscore: "lib/underscore",
        react:      "lib/react",
        CAAT:       "lib/caat"
    },
    shim: {
        "underscore": {
            exports: function() {
                return this._.noConflict();
            }
        },
    },
    priority: ["jquery"]
});

require([
        "react",
        "client/client",
        "client/settings",
], function(react, Client, settings) {
    var client = new Client(new WebSocket(settings.websocketURL));

    var LoginForm = react.createFactory(react.createClass({
                getInitialState: function() {
                    return {name: ""};
                },

                handleSubmit: function(event) {
                    // Avoid default http post
                    event.preventDefault();

                    var name = this.refs.name.getDOMNode().value;
                    var password = this.refs.password.getDOMNode().value;

                    this.refs.name.getDOMNode().value = "";
                    this.refs.password.getDOMNode().value = "";

                    this.props.client.attemptLogin(name, password);
                },

                handleNameChange: function(event) {
                    this.setState({name: event.target.value});
                },

                render: function() {
                    var disabled = this.props.disabled;

                    var name = this.state.name;

                    var nameId = "name";
                    var passwordId = "password";

                    var loginForm = react.DOM.form({
                            onSubmit: this.handleSubmit,
                            id: "login",
                    },

                    react.DOM.div({},
                        react.DOM.label({
                                htmlFor: nameId,
                        }, "Actor Name"),

                        react.DOM.input({
                                id:  nameId,
                                ref: "name",

                                type:     "text",
                                required: true,
                                value:    name,
                                onChange: this.handleNameChange,
                                disabled: disabled
                        })
                    ),

                    react.DOM.div({},
                        react.DOM.label({
                                htmlFor: passwordId,
                        }, "Password"),

                        react.DOM.input({
                                id:  passwordId,
                                ref: "password",

                                type: "password",
                                required: true,
                                disabled: disabled
                        })
                    ),

                    react.DOM.div({},
                        react.DOM.input({
                                type: "submit",
                                value: "login",
                                disabled: disabled
                        })
                    ));

                    return loginForm;
                }
    }));

    react.render(new LoginForm({client: client, disabled: true}), document.body);

    client.on("connected", function() {
        console.log("connected to " + settings.websocketURL);

        react.render(new LoginForm({client: client, disabled: false}), document.body);
    });

    client.on("loginSuccess", function(name) {
        console.log(name + " login succeeded");

        react.render(new LoginForm({
                    client: client,
                    disabled: false
        }), document.body).setState({name: name});

        // TODO begin rendering the game here
    });
});<commit_msg>Utilize the WIP reimplementation of client connection<commit_after>// NOTE must be also eddited in specs.js
requirejs.config({
    baseUrl: "js",
    paths: {
        jquery:     "lib/jquery-1.11.2",
        underscore: "lib/underscore",
        react:      "lib/react",
        CAAT:       "lib/caat"
    },
    shim: {
        "underscore": {
            exports: function() {
                return this._.noConflict();
            }
        },
    },
    priority: ["jquery"]
});

require([
        "react",
        "client/conn",
        "client/settings",
], function(react, Conn, settings) {
    var conn = new Conn(new WebSocket(settings.websocketURL));

    var LoginForm = react.createFactory(react.createClass({
                getInitialState: function() {
                    return {name: ""};
                },

                handleSubmit: function(event) {
                    // Avoid default http post
                    event.preventDefault();

                    var name = this.refs.name.getDOMNode().value;
                    var password = this.refs.password.getDOMNode().value;

                    this.refs.name.getDOMNode().value = "";
                    this.refs.password.getDOMNode().value = "";

                    this.props.conn.attemptLogin(name, password);
                },

                handleNameChange: function(event) {
                    this.setState({name: event.target.value});
                },

                render: function() {
                    var disabled = this.props.disabled;

                    var name = this.state.name;

                    var nameId = "name";
                    var passwordId = "password";

                    var loginForm = react.DOM.form({
                            onSubmit: this.handleSubmit,
                            id: "login",
                    },

                    react.DOM.div({},
                        react.DOM.label({
                                htmlFor: nameId,
                        }, "Actor Name"),

                        react.DOM.input({
                                id:  nameId,
                                ref: "name",

                                type:     "text",
                                required: true,
                                value:    name,
                                onChange: this.handleNameChange,
                                disabled: disabled
                        })
                    ),

                    react.DOM.div({},
                        react.DOM.label({
                                htmlFor: passwordId,
                        }, "Password"),

                        react.DOM.input({
                                id:  passwordId,
                                ref: "password",

                                type: "password",
                                required: true,
                                disabled: disabled
                        })
                    ),

                    react.DOM.div({},
                        react.DOM.input({
                                type: "submit",
                                value: "login",
                                disabled: disabled
                        })
                    ));

                    return loginForm;
                }
    }));


    conn.on("connected", function() {
        console.log("connected to " + settings.websocketURL);

        react.render(new LoginForm({conn: conn, disabled: false}), document.body);
    });

    conn.on("loginSuccess", function(name) {
        console.log(name + " login succeeded");

        // TODO begin rendering the game here
        react.render(react.DOM.canvas({}), document.body);
    });

    conn.on("authFailed", function(name) {
        console.log("auth failed for", name);
        react.render(new LoginForm({
                    conn:     conn,
                    disabled: false
        }), document.body).setState({name: name});

    });
});
{'fraction_non_alphanumeric': 0.1072917983065841, 'fraction_numerical': 0.0010109945659042083, 'mean_word_length': 0.9397058823529412, 'pattern_counts': {'":': 2, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3457984', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1712, 'n_words': 352}