{"size": 2305, "ext": "js", "max_stars_repo_path": "public/js/views/auth/UserProfileView.js", "max_stars_repo_name": "kinow/nestor", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/js/views/auth/UserProfileView.js", "max_issues_repo_name": "kinow/nestor", "max_issues_repo_issues_event_min_datetime": "2015-01-04T17:02:40.000Z", "max_issues_repo_issues_event_max_datetime": "2017-03-02T11:37:16.000Z", "max_forks_repo_path": "public/js/views/auth/UserProfileView.js", "max_forks_repo_name": "kinow/nestor", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 49, "max_forks_count": null, "avg_line_length": 33.8970588235, "max_line_length": 108, "alphanum_fraction": 0.4559652928}
define([
    'jquery',
    'underscore',
    'backbone',
    'app',
    'text!templates/auth/userProfileTemplate.html'
], function($, _, Backbone, app, userProfileTemplate) {

    var UserProfileView = Backbone.View.extend({
        el: $("#page"),

        initialize: function() {
            _.bindAll(this, 'onUpdateProfile', 'render');
        },

        events: {
            'submit': 'onUpdateProfile'
        },

        onUpdateProfile: function(event) {
            if (event) {
                event.preventDefault();
                event.stopImmediatePropagation();
            }
            if (this.$("#profile-form").parsley().validate()) {
                // get user in the session
                var user = app.session.user;

                user.save({
                    username: this.$("#profile-username-input").val(),
                    name: this.$("#profile-name-input").val(),
                    email: this.$("#profile-email-input").val(),
                }, {
                    success: function(mod, res) {
                        if (typeof DEBUG != 'undefined' && DEBUG) console.log("SUCCESS", mod, res);
                        app.showAlert('Success', 'Profile updated!', 'success')
                        Backbone.history.navigate("#/me", {
                            trigger: false
                        });
                    },
                    error: function(err) {
                        if (typeof DEBUG != 'undefined' && DEBUG) console.log("ERROR", err);
                        app.showAlert('Error updating profile', err, 'error');
                    }
                });
            } else {
                // Invalid clientside validations thru parsley
                if (typeof DEBUG != 'undefined' && DEBUG) console.log("Did not pass clientside validation");
            }
        },

        render: function() {
            $('.item').removeClass('active');
            $('a[href="#/me"]').addClass('active');
            var data = {
                user: app.session.user,
                _: _
            };
            var compiledTemplate = _.template(userProfileTemplate, data);
            this.$el.html(compiledTemplate);
            $("#profile-username-input").focus();
        }

    });

    return UserProfileView;

});