fix the "has no posts" on back bug.
This commit is contained in:
parent
946f78b025
commit
f3174941bd
4 changed files with 28 additions and 20 deletions
|
|
@ -3,16 +3,18 @@ app.models.Profile = Backbone.Model.extend({
|
|||
}, {
|
||||
|
||||
preloadOrFetch : function(id){
|
||||
if(app.hasPreload("person")) {
|
||||
return new app.models.Profile(app.parsePreload("person"))
|
||||
} else {
|
||||
return this.findByGuid(id)
|
||||
}
|
||||
return app.hasPreload("person") ? this.preload() : this.findByGuid(id)
|
||||
},
|
||||
|
||||
preload : function(){
|
||||
var person = new app.models.Profile(app.parsePreload("person"))
|
||||
person.deferred = $.when(true)
|
||||
return person
|
||||
},
|
||||
|
||||
findByGuid : function(personId){
|
||||
var person = new app.models.Profile({ id : personId})
|
||||
person.fetch()
|
||||
person.deferred = person.fetch()
|
||||
return person
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ app.models.Stream = Backbone.Collection.extend({
|
|||
|
||||
preload : function(){
|
||||
this.items.reset(app.parsePreload("stream"))
|
||||
this.deferred = $.when(true)
|
||||
this.trigger("fetched")
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ app.views.Canvas = app.views.InfScroll.extend({
|
|||
},
|
||||
|
||||
renderTemplate : function() {
|
||||
this.stream.deferred.done(_.bind(function(){
|
||||
if(this.stream.items.isEmpty()){
|
||||
var message
|
||||
, 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
|
||||
_.defer(_.bind(this.mason, this))
|
||||
}, this))
|
||||
},
|
||||
|
||||
addPostView : function(post) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ describe("app.pages.Profile", function(){
|
|||
beforeEach(function(){
|
||||
this.guid = 'abcdefg123'
|
||||
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 });
|
||||
this.stream = this.page.stream
|
||||
});
|
||||
|
|
@ -34,6 +35,7 @@ describe("app.pages.Profile", function(){
|
|||
context("with no posts", function(){
|
||||
beforeEach(function(){
|
||||
this.profile.set({"name" : "Alice Waters", person_id : "889"})
|
||||
this.stream.deferred.resolve()
|
||||
})
|
||||
|
||||
it("has a message that there are no posts", function(){
|
||||
|
|
@ -52,6 +54,7 @@ describe("app.pages.Profile", function(){
|
|||
beforeEach(function(){
|
||||
this.post = factory.post()
|
||||
this.stream.add(this.post)
|
||||
this.stream.deferred.resolve()
|
||||
this.page.toggleEdit()
|
||||
expect(this.page.editMode).toBeTruthy()
|
||||
this.page.render()
|
||||
|
|
|
|||
Loading…
Reference in a new issue