<commit_before>define([
    'jquery',
    'underscore',
    'backbone',
    'app',
    'simplemde',
    'models/project/ProjectModel',
    'text!templates/projects/projectTemplate.html'
], function($, _, Backbone, app, SimpleMDE, ProjectModel, projectTemplate) {

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

        events: {
            'submit form': 'save'
        },

        initialize: function(options) {
            this.model = new ProjectModel();
            _.bindAll(this, 'render', 'save');
        },

        render: function() {
            $('.menu a').removeClass('active');
            $('.menu a[href="#/projects"]').addClass('active');
            var self = this;
            this.model.fetch({
                success: function(project) {
                    var data = {
                        project: project,
                        _: _
                    }
                    var compiledTemplate = _.template(projectTemplate, data);
                    self.$el.html(compiledTemplate);
                    var simplemde = new SimpleMDE({
                        autoDownloadFontAwesome: true,
                        autofocus: false,
                        autosave: {
                            enabled: false
                        },
                        element: $('#project-description-input')[0],
                        indentWithTabs: false,
                        spellChecker: false,
                        tabSize: 4
                    });
                },
                error: function() {
                    throw new Error("Failed to fetch project");
                }
            });
        },

        save: function(event) {
            event.preventDefault();
            event.stopPropagation();

            if (this.$("#project-form").parsley().validate()) {
                var self = this;
                this.model.save({
                    name: this.$("#project-name-input").val(),
                    description: this.$("#project-description-input").val(),
                }, {
                    wait: true,
                    success: function(mod, res) {
                        app.showAlert('Success!', 'Project ' + this.$("#project-name-input").val() + ' updated!', 'success')
                            //Backbone.history.navigate("#/projects/" + self.model.id, { trigger: false });
                        Backbone.history.history.back();
                    },
                    error: function(model, response, options) {
                        var message = _.has(response, 'statusText') ? response.statusText : 'Unknown error!';
                        if (
                            _.has(response, 'responseJSON') &&
                            _.has(response.responseJSON, 'name') &&
                            _.has(response.responseJSON.name, 'length') &&
                            response.responseJSON.name.length > 0
                        ) {
                            message = response.responseJSON.name[0];
                        }
                        app.showAlert('Failed to update Project', message, 'error');
                    }
                });
            } else {
                if (typeof DEBUG != 'undefined' && DEBUG) console.log("Did not pass clientside validation");
            }
        }

    });

    return ProjectView;

});<commit_msg>Active class for project view<commit_after>define([
    'jquery',
    'underscore',
    'backbone',
    'app',
    'simplemde',
    'models/project/ProjectModel',
    'text!templates/projects/projectTemplate.html'
], function($, _, Backbone, app, SimpleMDE, ProjectModel, projectTemplate) {

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

        events: {
            'submit form': 'save'
        },

        initialize: function(options) {
            this.model = new ProjectModel();
            _.bindAll(this, 'render', 'save');
        },

        render: function() {
            $('.item').removeClass('active');
            $('.item a[href="#/projects"]').parent().addClass('active');
            var self = this;
            this.model.fetch({
                success: function(project) {
                    var data = {
                        project: project,
                        _: _
                    }
                    var compiledTemplate = _.template(projectTemplate, data);
                    self.$el.html(compiledTemplate);
                    var simplemde = new SimpleMDE({
                        autoDownloadFontAwesome: true,
                        autofocus: false,
                        autosave: {
                            enabled: false
                        },
                        element: $('#project-description-input')[0],
                        indentWithTabs: false,
                        spellChecker: false,
                        tabSize: 4
                    });
                },
                error: function() {
                    throw new Error("Failed to fetch project");
                }
            });
        },

        save: function(event) {
            event.preventDefault();
            event.stopPropagation();

            if (this.$("#project-form").parsley().validate()) {
                var self = this;
                this.model.save({
                    name: this.$("#project-name-input").val(),
                    description: this.$("#project-description-input").val(),
                }, {
                    wait: true,
                    success: function(mod, res) {
                        app.showAlert('Success!', 'Project ' + this.$("#project-name-input").val() + ' updated!', 'success')
                            //Backbone.history.navigate("#/projects/" + self.model.id, { trigger: false });
                        Backbone.history.history.back();
                    },
                    error: function(model, response, options) {
                        var message = _.has(response, 'statusText') ? response.statusText : 'Unknown error!';
                        if (
                            _.has(response, 'responseJSON') &&
                            _.has(response.responseJSON, 'name') &&
                            _.has(response.responseJSON.name, 'length') &&
                            response.responseJSON.name.length > 0
                        ) {
                            message = response.responseJSON.name[0];
                        }
                        app.showAlert('Failed to update Project', message, 'error');
                    }
                });
            } else {
                if (typeof DEBUG != 'undefined' && DEBUG) console.log("Did not pass clientside validation");
            }
        }

    });

    return ProjectView;

});
{'fraction_non_alphanumeric': 0.12534737457949394, 'fraction_numerical': 0.001170103846716396, 'mean_word_length': 1.1537007874015748, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7136209', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1513, 'n_words': 301}