Guest User

Untitled

a guest
Feb 17th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var root = 'http://localhost:5000/api/v1';
  2. var app = {};
  3.  
  4. // Backbone Model
  5. app.UserModel = Backbone.Model.extend({
  6.     defaults: {
  7.         // urlRoot: root + '/users',
  8.         name: 'Default Name',
  9.         email: '30',
  10.         username: 'default_username'
  11.     },
  12.  
  13.     initialize: function() {
  14.         // this.fetch();
  15.         // console.log('User model \'' + this.id + '\' has been initialized.');
  16.     },
  17.  
  18.     parse: function(data) {
  19.         // console.log('Model parse funciton called');
  20.         // return data.data;
  21.     }
  22. });
  23.  
  24. // Backbone Model View
  25. app.UserView = Backbone.View.extend({
  26.     el: '#users-list',
  27.     // el: '.user-box-wrapper',
  28.  
  29.     template: _.template($('#connections-user-template').html()),
  30.  
  31.     initialize: function() {
  32.         // this.render();
  33.     },
  34.  
  35.     render: function() {
  36.         this.$el.append( this.template( this.model.toJSON()));
  37.     }
  38. });
  39.  
  40. // Backbone Collection
  41. app.UserCollection = Backbone.Collection.extend({
  42.     model: app.UserModel,
  43.     url: root + '/users',
  44.  
  45.     initialize: function() {
  46.         // this.fetch();
  47.     },
  48.  
  49.     parse: function(data) {
  50.         return data.data;
  51.     }
  52. });
  53.  
  54. // Backbone Collection View
  55. app.UserCollectionView = Backbone.View.extend({
  56.     el: '#users-list',
  57.  
  58.     template: _.template($('#connections-template').html()),
  59.  
  60.     initialize: function() {
  61.         this.connections = new app.UserCollection();
  62.         var self = this;
  63.         this.connections.fetch().done(function() {
  64.             self.render();
  65.         });
  66.     },
  67.  
  68.     render: function() {
  69.         this.$el.html(this.template());
  70.         // this.$el.append( this.template( this.model.toJSON()));
  71.         this.connections.each(function(user) {
  72.             console.log('User : ' + user.get('name'));
  73.             var userView = new app.UserView({
  74.                 model: user
  75.             });
  76.             // userView.model.fetch();
  77.             userView.render();
  78.         });
  79.     }
  80. });
  81. var connectionsView = new app.UserCollectionView();
Add Comment
Please, Sign In to add comment