<commit_before>pp.views.Register = Backbone.View.extend({
    events: {
       'click .submit': 'doRegister',
    },

    template: _.template($('script#template-register').text()),

    initialize: function () {
        this.model = pp.app.user;

        this.model.on('change', this.checkUser, this);

        this.model.fetch();
    },

    checkUser: function () {
        // you can't see the registration form if you're already registered
        // or if you're not authentificated yet
        if (this.model.get("registered") || !this.model.get("twitter")) {
            this.remove();
            pp.app.router.navigate("/", { trigger: true });
            return;
        }
        this.render();
    },

    render: function () {
        this.$el.html(this.template);
    },

    doRegister: function () {
        var login = this.$('[name=login]').val();
        // TODO - what should we do if login is empty?
        $.post('/api/register', { login: login })
            .success(function () {
                pp.app.user.fetch();
                pp.app.router.navigate("/", { trigger: true });
            })
            .error(function () {
                alert("registration failed");
            });
    }<commit_msg>submit on enter - issue #60<commit_after>pp.views.Register = Backbone.View.extend({
    events: {
       'click .submit': 'doRegister',
       'keydown [name=login]': 'checkEnter'
    },

    template: _.template($('script#template-register').text()),

    initialize: function () {
        this.model = pp.app.user;

        this.model.on('change', this.checkUser, this);
        _.bindAll(this, 'checkEnter', 'doRegister');

        this.model.fetch();
    },

    checkUser: function () {
        // you can't see the registration form if you're already registered
        // or if you're not authentificated yet
        if (this.model.get("registered") || !this.model.get("twitter")) {
            this.remove();
            pp.app.router.navigate("/", { trigger: true });
            return;
        }
        this.render();
    },

    render: function () {
        this.$el.html(this.template);
    },

    checkEnter: function (e) {
        if (e.keyCode == 13) {
          this.doRegister();
        }
    },

    doRegister: function () {
        var login = this.$('[name=login]').val();
        // TODO - what should we do if login is empty?
        $.post('/api/register', { login: login })
            .success(function () {
                pp.app.user.fetch();
                pp.app.router.navigate("/", { trigger: true });
            })
            .error(function () {
                alert("registration failed");
            });
    }
{'fraction_non_alphanumeric': 0.16468401486988848, 'fraction_numerical': 0.001486988847583643, 'mean_word_length': 1.7972972972972974, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2060183', 'n_tokens_mistral': 775, 'n_tokens_neox': 741, 'n_words': 159}