diff --git a/app/assets/javascripts/app/models/profile.js b/app/assets/javascripts/app/models/profile.js index 43d04c8c4..c0134017d 100644 --- a/app/assets/javascripts/app/models/profile.js +++ b/app/assets/javascripts/app/models/profile.js @@ -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 } }); diff --git a/app/assets/javascripts/app/models/stream.js b/app/assets/javascripts/app/models/stream.js index 382dd58c5..e642171e0 100644 --- a/app/assets/javascripts/app/models/stream.js +++ b/app/assets/javascripts/app/models/stream.js @@ -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") } }); diff --git a/app/assets/javascripts/app/views/canvas_view.js b/app/assets/javascripts/app/views/canvas_view.js index 10a676289..8320f009c 100644 --- a/app/assets/javascripts/app/views/canvas_view.js +++ b/app/assets/javascripts/app/views/canvas_view.js @@ -10,23 +10,25 @@ app.views.Canvas = app.views.InfScroll.extend({ }, renderTemplate : function() { - if(this.stream.items.isEmpty()){ - var message - , person = app.page.model - if(person.get("is_own_profile")){ - message = "Make something to start the magic." + this.stream.deferred.done(_.bind(function(){ + if(this.stream.items.isEmpty()){ + var message + , person = app.page.model + 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("
") } else { - var name = person.get("name") || "" - message = name + " hasn't posted anything yet." + this.renderInitialPosts() } - this.$el.html("") - } else { - this.renderInitialPosts() - } - - //needs to be deferred so it happens after html rendering finishes - _.defer(_.bind(this.mason, this)) + //needs to be deferred so it happens after html rendering finishes + _.defer(_.bind(this.mason, this)) + }, this)) }, addPostView : function(post) { diff --git a/spec/javascripts/app/pages/profile_spec.js b/spec/javascripts/app/pages/profile_spec.js index c30970900..4621ff58e 100644 --- a/spec/javascripts/app/pages/profile_spec.js +++ b/spec/javascripts/app/pages/profile_spec.js @@ -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()