Skip to content

Commit

Permalink
- still trying to display users
Browse files Browse the repository at this point in the history
  • Loading branch information
ritzalam committed Oct 26, 2012
1 parent 3f64313 commit a894397
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 18 deletions.
6 changes: 6 additions & 0 deletions labs/html5-embed/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
</div>
<div id="users">
<h3>Users</h3>
<ul id="users-list"></ul>
</div>
<div id="chat">
<h3>Chat</h3>
Expand Down Expand Up @@ -101,5 +102,10 @@ <h3>Chat</h3>
</ul>
</div>
<script src="js/chat/behaviour.js"></script>
<script type="text/template" id="item-template">
<li>
User
</li>
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion labs/html5-embed/public/js/collections/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ define([
});
BBB.listen("UserJoinedEvent", function(bbbEvent) {
console.log("User [" + bbbEvent.userID + ", " + bbbEvent.userName + "] has joined.");
self.add({ userid: bbbEvent.userID, username: bbbEvent.userName});
self.add(new UserModel({ userid: bbbEvent.userID, username: bbbEvent.userName}));
});
}
});
Expand Down
4 changes: 4 additions & 0 deletions labs/html5-embed/public/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ define([
'underscore',
'backbone'
], function($, _, Backbone ){

var AppRouter = Backbone.Router.extend({
routes: {
// Default. We only have one route.
'*actions': 'defaultAction'
}
});

var initialize = function(){
var app_router = new AppRouter;
app_router.on('route:defaultAction', function (actions) {
Expand All @@ -27,7 +29,9 @@ define([
});
Backbone.history.start();
};

return {
initialize: initialize
};

});
32 changes: 15 additions & 17 deletions labs/html5-embed/public/js/views/users/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@ define([
'underscore',
'backbone',
'collections/users',
'text!templates/users/list.html'
], function($, _, Backbone, UserCollection, userListTemplate){



var UsersView = Backbone.View.extend({
el: $("#users"),
'views/users/user'
], function($, _, Backbone, UserCollection, UserView){

var UsersView = Backbone.View.extend({
el: $("#users-list"),
initialize: function(){
// UserCollection.add({ userid: "u1", username: "Richard"});
// UserCollection.add({ userid: "u2", username: "Jesus"});
// UserCollection.add({ userid: "u3", username: "Fred"});
},
exampleBind: function( model ){
console.log("Example Bind [" + model.get("userid") + ", " + model.get("username") + "]");
this.render();
UserCollection.on('add', this.addUser, this);
},
render: function(){
console.log("*** Rendering Users View [" + UserCollection.length + "]");
var data = {
users: UserCollection.models
};
var compiledTemplate = _.template( userListTemplate, data );
this.$el.html( compiledTemplate );
}
// var compiledTemplate = _.template( userListTemplate, data );
// this.$el.html( compiledTemplate );
},
addUser: function(user) {
console.log("Adding user [" + user.get("username") + "]");
var view = new UserView({model: user});
console.log("Rendering [" + view.render().el.html() + "]");
this.$el.append('<li>Hello</li>');
}
});

var usersView = new UsersView();
Expand Down
30 changes: 30 additions & 0 deletions labs/html5-embed/public/js/views/users/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Filename: views/users/user
define([
'jquery',
'underscore',
'backbone',
'text!templates/users/user.html'
], function($, _, Backbone, userTemplate){
var UserView = Backbone.View.extend({
tagName: "li",

initialize: function() {
this.model.on('change', this.render, this);
this.model.on('destroy', this.remove, this);
},

render: function() {
console.log("Render me! [" + this.model.get("username") + "]");
var compiledTemplate = _.template(userTemplate, this.model);
console.log("user is " + compiledTemplate);
this.$el.append(compiledTemplate);
console.log(this.$el.append(compiledTemplate));
return this;
//return compiledTemplate;
}

});

return UserView;

});
1 change: 1 addition & 0 deletions labs/html5-embed/public/templates/users/user.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world!

0 comments on commit a894397

Please sign in to comment.