diaspora/public/javascripts/app/models/stream.js
2012-01-19 17:01:45 -08:00

50 lines
1.1 KiB
JavaScript

app.models.Stream = Backbone.Collection.extend({
initialize : function(){
this.posts = new app.collections.Posts();
},
url : function(){
return _.any(this.posts.models) ? this.timeFilteredPath() : this.basePath()
},
_fetching : false,
fetch: function() {
var self = this
// we're fetching the collection... there is probably a better way to do this
self._fetching = true;
this.posts
.fetch({
add : true,
url : self.url()
})
.done(
function(resp){
// we're done fetching... there is probably a better way to handle this
self._fetching = false;
self.trigger("fetched", self);
// all loaded?
if(resp.posts && (resp.posts.author || resp.posts.length == 0)) {
self.trigger("allPostsLoaded", self);
}
}
)
return this;
},
basePath : function(){
return document.location.pathname;
},
timeFilteredPath : function(){
return this.basePath() + "?max_time=" + _.last(this.posts.models).createdAt();
},
add : function(models){
this.posts.add(models)
}
})