<commit_before>var template = require('../../../../templates/users/users.dust');
UserModel = Backbone.Model.extend({
    urlRoot: 'http://localhost:8000/api/users'
});

module.exports = Backbone.View.extend({
    /**
     * @returns {Object}
     */
    events: function () {
        return {
            'submit': 'onAddUser',
            'click .delete-user': 'remUser'
        };
    },

    /**
     *
     * @chainable
     * @returns {Backbone.View}
     */

    render: function () {
        var self = this;
        var userlist = new UserModel();

        userlist.fetch({
            success: function (data) {
                template({users: _.toArray(data.attributes)}, function (error, html) {
                    if (error) {
                        console.log(error);
                    }
                    else {
                        self.$el.html(html);
                    }
                });
            }
        });
    },


    onAddUser: function (e) {
        e.preventDefault();

        var formData = $('.form-user').serializeArray();
        var userDetails = {};
        var self = this;
        var user = new UserModel();

        _.forEach(formData, function forEveryFormData(val) {
            userDetails[val.name] = val.value;
        });
        //userDetails.id = userDetails.name;

        user.save(userDetails, {
            success: function (user) {
                console.log('Success');
                self.render();
            }
        });

        return false;
    },
    remUser: function(e) {
        e.preventDefault();

        var entry = e.currentTarget.value;
        var user = new UserModel({
            id: entry
        });

        user.destroy({
            success: function () {
                $('#tr-'+entry).remove();

            },
            failure: function () {
                console.log('The Command to delete: ' + entry + ' failed');
            }
        });

        return false;

    }
<commit_msg>refactor(listUsersView): make the code function like tasks<commit_after>UserModel = Backbone.Model.extend({
    urlRoot: 'http://localhost:8000/api/users'
});

module.exports = Backbone.View.extend({
    /**
     * @returns {Object}
     */
    events: function () {
        return {
            'submit': 'onAddUser',
            'click .delete-user': 'remUser'
        };
    },
    template: require('../../../../templates/users/users.dust'),
    helpers: function (cb) {
        var helpers = {};
        var userlist = new UserModel();
        userlist.fetch({
            success: function (data) {
                helpers.users =  _.toArray(data.attributes);
                cb(null, helpers);
            }
        });
    },
    /**
     *
     * @chainable
     * @returns {Backbone.View}
     */

    render: function () {
        var self = this;
        this.helpers(function (err, helpers) {
            self.template(helpers, function (error, html) {
                if (error) {
                    console.log(error);
                }
                else {
                    self.$el.html(html);
                }
            });
        });
    },


    onAddUser: function (e) {
        e.preventDefault();

        var formData = $('.form-user').serializeArray();
        var userDetails = {};
        var self = this;
        var user = new UserModel();

        _.forEach(formData, function forEveryFormData(val) {
            userDetails[val.name] = val.value;
        });
        //userDetails.id = userDetails.name;

        user.save(userDetails, {
            success: function (user) {
                console.log('Success');
                self.render();
            }
        });

        return false;
    },
    remUser: function (e) {
        e.preventDefault();

        var entry = e.currentTarget.value;
        var user = new UserModel({
            id: entry
        });

        user.destroy({
            success: function () {
                $('#tr-' + entry).remove();

            },
            failure: function () {
                console.log('The Command to delete: ' + entry + ' failed');
            }
        });

        return false;

    }

{'fraction_non_alphanumeric': 0.14142618650131172, 'fraction_numerical': 0.0019079418077748629, 'mean_word_length': 1.3222591362126246, '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': '3823245', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1102, 'n_words': 222}