<commit_before>window.UserView = Backbone.View.extend({

    id: 'admin-user',

    events: {
        "click a.save": "onSubmitClick"
    },

    render: function () {
        var user = {}, 
            own_data = false;

        if (!_.isUndefined(this.model) && !_.isNull(this.model))
            user = this.model.toJSON();

        if (!_.isUndefined(this.options.parent) && this.model === window.app.user)
            own_data = true;

        $(this.el).html(templates.userView({user: user, own_data: own_data}));

        var that = this;
        this.validator = this.$('form').validate({
            rules: {
                firstname: "required",
                lastname: "required",
                password: {
                    minlength: 5
                },
                email: {
                    required: true,
                    email: true
                }
            },
            messages: {
                firstname: $._('Please enter a firstname'),
                lastname: $._('Please enter a lastname'),
                password: {
                    minlength: $._('Enter at least 5 characters')
                },
                email: {
                    required: $._('Please enter a valid email address'),
                    email: $._('Please enter a valid email address')
                }
            },
            showErrors: function (errorMap, errorList) {
                for (var obj in errorList) {
                    $(errorList[obj].element).addClass('error')
                        .removeClass('valid')
                        .attr('rel', 'popover')
                        .attr('data-content', errorList[obj].message)
                        .attr('data-original-title', $._("Error!"))
                        .popover();
                }
                this.defaultShowErrors();
            },
            errorPlacement: function () {},
            highlight: function () {},
            unhighlight: function (elem, error, valid) {
                $(elem).addClass('valid')
                    .removeClass('error')
                    .attr('rel', null)
                    .attr('data-content', null)
                    .attr('data-original-title', null);
            },
            submitHandler: _.bind(that.onSubmit, that),
            invalidHandler: function () {
                that.$('.error-correct').show();
            }
        });

        return this;
    },

    remove: function () {
        if ($(this.el).modal(true).isShown)
            $(this.el).modal('hide');
        if (_.isFunction(this.options.remove))
            this.options.remove();
        $(this.el).remove();
        window.app.navigate('');
    },

    onSubmitClick: function () {
        this.$('form').submit();
        return false;
    },

    onSubmit: function () {
        var loading = new LoadingView($._("Sending data")).render();
        this.$('.error-correct').hide();

        var new_user = false;
        if (_.isUndefined(this.model) || _.isNull(this.model)) {
            new_user = true;
            this.model = new User();
        }

        var user = this.model;
        user.set({
            firstname: this.$('#firstname').val(),
            lastname: this.$('#lastname').val(),
            address: this.$('#address').val(),
            email: this.$('#email').val(),
            active: this.$('#active').is(':checked') ? "verified" : "needs verification",
            admin: this.$('#administrator').is(':checked')
        });
        if (!_.isEmpty(this.$('#password').val()))<commit_msg>fix #104 - maybe this time corrext xD<commit_after>window.UserView = Backbone.View.extend({

    id: 'admin-user',

    events: {
        "click a.save": "onSubmitClick"
    },

    render: function () {
        var user = {}, 
            own_data = false;

        if (!_.isUndefined(this.model) && !_.isNull(this.model))
            user = this.model.toJSON();

        if (!_.isUndefined(this.options.parent) && this.model === window.app.user)
            own_data = true;

        $(this.el).html(templates.userView({user: user, own_data: own_data}));

        var that = this;
        this.validator = this.$('form').validate({
            rules: {
                firstname: "required",
                lastname: "required",
                password: {
                    minlength: 5
                },
                email: {
                    required: true,
                    email: true
                }
            },
            messages: {
                firstname: $._('Please enter a firstname'),
                lastname: $._('Please enter a lastname'),
                password: {
                    minlength: $._('Enter at least 5 characters')
                },
                email: {
                    required: $._('Please enter a valid email address'),
                    email: $._('Please enter a valid email address')
                }
            },
            showErrors: function (errorMap, errorList) {
                for (var obj in errorList) {
                    $(errorList[obj].element).addClass('error')
                        .removeClass('valid')
                        .attr('rel', 'popover')
                        .attr('data-content', errorList[obj].message)
                        .attr('data-original-title', $._("Error!"))
                        .popover();
                }
                this.defaultShowErrors();
            },
            errorPlacement: function () {},
            highlight: function () {},
            unhighlight: function (elem, error, valid) {
                $(elem).addClass('valid')
                    .removeClass('error')
                    .attr('rel', null)
                    .attr('data-content', null)
                    .attr('data-original-title', null);
            },
            submitHandler: _.bind(that.onSubmit, that),
            invalidHandler: function () {
                that.$('.error-correct').show();
            }
        });

        return this;
    },

    remove: function () {
        if ($(this.el).modal(true).isShown)
            $(this.el).modal('hide');
        if (_.isFunction(this.options.remove))
            this.options.remove();
        $(this.el).remove();
        window.app.navigate('');
    },

    onSubmitClick: function () {
        this.$('form').submit();
        return false;
    },

    onSubmit: function () {
        var loading = new LoadingView($._("Sending data")).render();
        this.$('.error-correct').hide();

        var new_user = false;
        if (_.isUndefined(this.model) || _.isNull(this.model)) {
            new_user = true;
            this.model = new User();
        }

        var user = this.model;
        user.set({
            firstname: this.$('#firstname').val(),
            lastname: this.$('#lastname').val(),
            address: this.$('#address').val(),
            email: this.$('#email').val(),
            status: this.$('#active').is(':checked') ? "verified" : "needs_verification",
            admin: this.$('#administrator').is(':checked')
        });
        if (!_.isEmpty(this.$('#password').val()))
{'fraction_non_alphanumeric': 0.15502365711104926, 'fraction_numerical': 0.0009741163373225717, 'mean_word_length': 1.376653439153439, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2616531', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1798, 'n_words': 362}