fix the "has no posts" on back bug.

This commit is contained in:
Dennis Collinson 2012-05-24 11:39:58 -07:00
parent 946f78b025
commit f3174941bd
4 changed files with 28 additions and 20 deletions

View file

@ -3,16 +3,18 @@ app.models.Profile = Backbone.Model.extend({
}, { }, {
preloadOrFetch : function(id){ preloadOrFetch : function(id){
if(app.hasPreload("person")) { return app.hasPreload("person") ? this.preload() : this.findByGuid(id)
return new app.models.Profile(app.parsePreload("person")) },
} else {
return this.findByGuid(id) preload : function(){
} var person = new app.models.Profile(app.parsePreload("person"))
person.deferred = $.when(true)
return person
}, },
findByGuid : function(personId){ findByGuid : function(personId){
var person = new app.models.Profile({ id : personId}) var person = new app.models.Profile({ id : personId})
person.fetch() person.deferred = person.fetch()
return person return person
} }
}); });

View file

@ -64,6 +64,7 @@ app.models.Stream = Backbone.Collection.extend({
preload : function(){ preload : function(){
this.items.reset(app.parsePreload("stream")) this.items.reset(app.parsePreload("stream"))
this.deferred = $.when(true)
this.trigger("fetched") this.trigger("fetched")
} }
}); });

View file

@ -10,6 +10,7 @@ app.views.Canvas = app.views.InfScroll.extend({
}, },
renderTemplate : function() { renderTemplate : function() {
this.stream.deferred.done(_.bind(function(){
if(this.stream.items.isEmpty()){ if(this.stream.items.isEmpty()){
var message var message
, person = app.page.model , person = app.page.model
@ -27,6 +28,7 @@ app.views.Canvas = app.views.InfScroll.extend({
//needs to be deferred so it happens after html rendering finishes //needs to be deferred so it happens after html rendering finishes
_.defer(_.bind(this.mason, this)) _.defer(_.bind(this.mason, this))
}, this))
}, },
addPostView : function(post) { addPostView : function(post) {

View file

@ -2,6 +2,7 @@ describe("app.pages.Profile", function(){
beforeEach(function(){ beforeEach(function(){
this.guid = 'abcdefg123' this.guid = 'abcdefg123'
this.profile = factory.profile({personId: this.guid}) this.profile = factory.profile({personId: this.guid})
spyOn(app.collections.Posts.prototype, "fetch").andReturn(new $.Deferred)
app.page = this.page = new app.pages.Profile({model : this.profile }); app.page = this.page = new app.pages.Profile({model : this.profile });
this.stream = this.page.stream this.stream = this.page.stream
}); });
@ -34,6 +35,7 @@ describe("app.pages.Profile", function(){
context("with no posts", function(){ context("with no posts", function(){
beforeEach(function(){ beforeEach(function(){
this.profile.set({"name" : "Alice Waters", person_id : "889"}) this.profile.set({"name" : "Alice Waters", person_id : "889"})
this.stream.deferred.resolve()
}) })
it("has a message that there are no posts", function(){ it("has a message that there are no posts", function(){
@ -52,6 +54,7 @@ describe("app.pages.Profile", function(){
beforeEach(function(){ beforeEach(function(){
this.post = factory.post() this.post = factory.post()
this.stream.add(this.post) this.stream.add(this.post)
this.stream.deferred.resolve()
this.page.toggleEdit() this.page.toggleEdit()
expect(this.page.editMode).toBeTruthy() expect(this.page.editMode).toBeTruthy()
this.page.render() this.page.render()