Trying a view for user, timeline(s), entry(ies).
This commit is contained in:
@ -3,7 +3,15 @@ var Test = {};
|
||||
$(document).ready(function() {
|
||||
|
||||
Test.U = Backbone.Model.extend({
|
||||
url: '/ts_api/users'
|
||||
url: '/ts_api/users',
|
||||
|
||||
initialize: function() {
|
||||
this.timelines = {};
|
||||
}
|
||||
});
|
||||
|
||||
Test.E = Backbone.Model.extend({
|
||||
url: '/ts_api/entries/jdbernard/work'
|
||||
});
|
||||
|
||||
Test.UView = Backbone.View.extend({
|
||||
@ -18,9 +26,59 @@ $(document).ready(function() {
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var user = this.model.get('user');
|
||||
this.$('.fullname').text(user.name);
|
||||
this.$('.username').text(user.username);
|
||||
this.$('.fullname').text(this.model.get('name'));
|
||||
this.$('.username').text(this.model.get('id'));
|
||||
}
|
||||
});
|
||||
|
||||
Test.EList = Backbone.Collection.extend({
|
||||
model: Test.E,
|
||||
|
||||
url: '/ts_api/entries/jdbernard/work',
|
||||
|
||||
initalize: function(models, options) {
|
||||
this.user = options.user;
|
||||
},
|
||||
|
||||
comparator: function(entry) {
|
||||
return entry.get('timestamp');
|
||||
}
|
||||
});
|
||||
|
||||
Test.EView = Backbone.View.extend({
|
||||
|
||||
model: Test.E,
|
||||
|
||||
initialize: function() {
|
||||
_.bindAll(this, 'render');
|
||||
this.model.bind('change', this.render);
|
||||
this.model.view = this;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
$(this.el).html("<span class='entry-id'>" + this.model.get('id') + "<span class='mark'>" + this.model.get('mark') + "</span>");
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
Test.EListView = Backbone.View.extend({
|
||||
el: $("#entry-list"),
|
||||
initialize: function() {
|
||||
_.bindAll(this, 'render', 'refresh', 'addOne');
|
||||
|
||||
this.collection.bind('add', this.addOne);
|
||||
this.collection.bind('refresh', this.refresh);
|
||||
},
|
||||
|
||||
addOne: function(entry) {
|
||||
var view = new Test.EView({model: entry});
|
||||
$(this.el).append(view.render().el);
|
||||
},
|
||||
|
||||
refresh: function() {
|
||||
$(this.el).empty();
|
||||
var thisRef = this;
|
||||
this.collection.each(function(entry) {thisRef.addOne(entry)});
|
||||
}
|
||||
});
|
||||
|
||||
@ -65,5 +123,9 @@ function login() {
|
||||
$("#login-dialog").dialog('close');
|
||||
Test.currentUser.set({id: name.val()}, {silent: true});
|
||||
Test.currentUser.fetch();
|
||||
|
||||
Test.currentEntryList = Test.currentUser.timelines['work'] = new Test.EList([], {user: Test.currentUser});
|
||||
new Test.EListView({collection: Test.currentEntryList});
|
||||
Test.currentEntryList.fetch();
|
||||
}});
|
||||
}
|
||||
|
Reference in New Issue
Block a user