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){
|
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
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -10,23 +10,25 @@ app.views.Canvas = app.views.InfScroll.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
renderTemplate : function() {
|
renderTemplate : function() {
|
||||||
if(this.stream.items.isEmpty()){
|
this.stream.deferred.done(_.bind(function(){
|
||||||
var message
|
if(this.stream.items.isEmpty()){
|
||||||
, person = app.page.model
|
var message
|
||||||
if(person.get("is_own_profile")){
|
, person = app.page.model
|
||||||
message = "Make something to start the magic."
|
if(person.get("is_own_profile")){
|
||||||
|
message = "Make something to start the magic."
|
||||||
|
} else {
|
||||||
|
var name = person.get("name") || ""
|
||||||
|
message = name + " hasn't posted anything yet."
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$el.html("<p class='no-post-message'>" + message + "</p>")
|
||||||
} else {
|
} else {
|
||||||
var name = person.get("name") || ""
|
this.renderInitialPosts()
|
||||||
message = name + " hasn't posted anything yet."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$el.html("<p class='no-post-message'>" + message + "</p>")
|
//needs to be deferred so it happens after html rendering finishes
|
||||||
} else {
|
_.defer(_.bind(this.mason, this))
|
||||||
this.renderInitialPosts()
|
}, this))
|
||||||
}
|
|
||||||
|
|
||||||
//needs to be deferred so it happens after html rendering finishes
|
|
||||||
_.defer(_.bind(this.mason, this))
|
|
||||||
},
|
},
|
||||||
|
|
||||||
addPostView : function(post) {
|
addPostView : function(post) {
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue