From c4240154b15118668d4567471ba6095b038a915e Mon Sep 17 00:00:00 2001 From: Dennis Collinson Date: Thu, 24 May 2012 12:42:01 -0700 Subject: [PATCH] back to profile works --- app/assets/javascripts/app/pages/profile.js | 30 +++++++++++++------ .../app/views/profile_info_view.js | 2 +- spec/javascripts/app/pages/profile_spec.js | 3 ++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/app/pages/profile.js b/app/assets/javascripts/app/pages/profile.js index 583c67d90..a9ec994af 100644 --- a/app/assets/javascripts/app/pages/profile.js +++ b/app/assets/javascripts/app/pages/profile.js @@ -28,23 +28,34 @@ app.pages.Profile = app.views.Base.extend({ this.model = this.model || app.models.Profile.preloadOrFetch(this.personGUID) this.stream = options && options.stream || new app.models.Stream() + this.stream.preloadOrFetch() - this.stream.preloadOrFetch().done(_.bind(this.pulsateNewPostControl, this)); + this.initViews() + + /* binds */ this.stream.items.bind("remove", this.pulsateNewPostControl, this) + $(window).on("keydown", _.bind(this.closeComposer, this)) + }, - /* this needs to be fixed... used to be bound by this.model change event. - * will most likely result in spontaneous results :( - * - * note: defer to make sure the call stack is emptied before calling this, buying us a little more time */ - _.defer(_.bind(this.setPageTitleAndBackground, this)) - + initViews : function(){ this.canvasView = new app.views.Canvas({ model : this.stream }) this.wallpaperForm = new app.forms.Wallpaper() this.profileInfo = new app.views.ProfileInfo({ model : this.model }) this.composerView = new app.pages.Composer(); + }, - /* binds */ - $(window).on("keydown", _.bind(this.closeComposer, this)) + render :function () { + var self = this; + this.model.deferred + .done(function () { + self.setPageTitleAndBackground() + app.views.Base.prototype.render.call(self) + }) + .done(function () { + self.stream.deferred.done(_.bind(self.pulsateNewPostControl, self)); + }) + + return self }, presenter : function(){ @@ -63,6 +74,7 @@ app.pages.Profile = app.views.Base.extend({ }, setPageTitleAndBackground : function() { + console.log(this.model.attributes) if(this.model.get("name")) { document.title = this.model.get("name") this.$el.css("background-image", "url(" + this.model.get("wallpaper") + ")") diff --git a/app/assets/javascripts/app/views/profile_info_view.js b/app/assets/javascripts/app/views/profile_info_view.js index 0b2fb9574..ccba39a54 100644 --- a/app/assets/javascripts/app/views/profile_info_view.js +++ b/app/assets/javascripts/app/views/profile_info_view.js @@ -4,6 +4,6 @@ app.views.ProfileInfo = app.views.Base.extend({ tooltipSelector : "*[rel=tooltip]", initialize : function(){ - this.model.bind("change", this.render, this) //this should go on profile info view when it gets Extracted + this.model.bind("change", this.render, this) } }); \ No newline at end of file diff --git a/spec/javascripts/app/pages/profile_spec.js b/spec/javascripts/app/pages/profile_spec.js index 4621ff58e..ca199d26c 100644 --- a/spec/javascripts/app/pages/profile_spec.js +++ b/spec/javascripts/app/pages/profile_spec.js @@ -2,13 +2,16 @@ describe("app.pages.Profile", function(){ beforeEach(function(){ this.guid = 'abcdefg123' this.profile = factory.profile({personId: this.guid}) + this.profile.deferred = new $.Deferred() 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 + this.profile.deferred.resolve() }); it("fetches the profile of the user with the params from the router and assigns it as the model", function(){ var profile = new factory.profile() + profile.deferred = $.Deferred() spyOn(app.models.Profile, 'findByGuid').andReturn(profile) var page = new app.pages.Profile({personId : 'jarjabinkisthebest' }) expect(app.models.Profile.findByGuid).toHaveBeenCalledWith('jarjabinkisthebest')