diff --git a/app/assets/javascripts/app/models/stream.js b/app/assets/javascripts/app/models/stream.js index 3873f8650..459c71056 100644 --- a/app/assets/javascripts/app/models/stream.js +++ b/app/assets/javascripts/app/models/stream.js @@ -59,5 +59,12 @@ app.models.Stream = Backbone.Collection.extend({ add : function(models){ this.items.add(models) + }, + + preload : function(){ + var preloadJson = window.preLoadContent && JSON.parse(window.preLoadContent) + delete window.preLoadContent // always do this just to be safe in preventing dirty state across navigates + + if(preloadJson) { this.items.reset(preloadJson) } } }); diff --git a/app/assets/javascripts/app/pages/profile.js b/app/assets/javascripts/app/pages/profile.js index 1c569f776..6625e837e 100644 --- a/app/assets/javascripts/app/pages/profile.js +++ b/app/assets/javascripts/app/pages/profile.js @@ -1,12 +1,13 @@ //= require ../views/small_frame +//= require ../views/profile_info_view app.pages.Profile = app.views.Base.extend({ - className : "container", templateName : "profile", subviews : { + "#profile-info" : "profileInfo", "#canvas" : "canvasView" }, @@ -19,10 +20,10 @@ app.pages.Profile = app.views.Base.extend({ initialize : function(options) { this.model = new app.models.Profile.findByGuid(options.personId) this.stream = options && options.stream || new app.models.Stream() - this.stream.fetch(); - this.model.bind("change", this.render, this) //this should go on profile info view when it gets Extracted + this.stream.preload() - this.canvasView = new app.views.Canvas({model : this.stream}) + this.canvasView = new app.views.Canvas({ model : this.stream }) + this.profileInfo = new app.views.ProfileInfo({ model : this.model }) }, toggleEdit : function(evt) { @@ -30,5 +31,4 @@ app.pages.Profile = app.views.Base.extend({ this.editMode = !this.editMode this.$el.toggleClass("edit-mode") } - }); \ No newline at end of file diff --git a/app/assets/javascripts/app/views.js b/app/assets/javascripts/app/views.js index 29051fa01..b38555425 100644 --- a/app/assets/javascripts/app/views.js +++ b/app/assets/javascripts/app/views.js @@ -89,7 +89,8 @@ app.views.infiniteScrollMixin = { this.bind("loadMore", this.fetchAndshowLoader, this) this.stream.bind("fetched", this.hideLoader, this) this.stream.bind("allItemsLoaded", this.unbindInfScroll, this) - this.collection.bind("add", this.addPost, this); + + this.collection.bind("add", this.addPostView, this); var throttledScroll = _.throttle(_.bind(this.infScroll, this), 200); $(window).scroll(throttledScroll); @@ -99,12 +100,15 @@ app.views.infiniteScrollMixin = { if(this.stream.isFetching()) { this.showLoader() } }, - addPost : function(post) { - var postView = new this.postClass({ model: post }) - , placeInStream = (this.collection.at(0).id == post.id) ? "prepend" : "append"; - - this.$el[placeInStream](postView.render().el); + createPostView : function(post){ + var postView = new this.postClass({ model: post }); this.postViews.push(postView) + return postView + }, + + addPostView : function(post) { + var placeInStream = (this.collection.at(0).id == post.id) ? "prepend" : "append"; + this.$el[placeInStream](this.createPostView(post).render().el); }, unbindInfScroll : function() { @@ -122,7 +126,7 @@ app.views.infiniteScrollMixin = { }, hideLoader: function() { - $("#paginate .loader").addClass("hidden") + $("#paginate .loader").addClass("hidden") }, infScroll : function() { diff --git a/app/assets/javascripts/app/views/canvas_view.js b/app/assets/javascripts/app/views/canvas_view.js index d356791cf..20122214c 100644 --- a/app/assets/javascripts/app/views/canvas_view.js +++ b/app/assets/javascripts/app/views/canvas_view.js @@ -1,19 +1,26 @@ -app.views.Canvas = app.views.Base.extend(_.extend(app.views.infiniteScrollMixin, { +app.views.Canvas = app.views.Base.extend(_.extend({}, app.views.infiniteScrollMixin, { initialize: function(){ this.stream = this.model this.collection = this.stream.items - this.postClass = app.views.SmallFrame, + this.postClass = app.views.SmallFrame this.setupInfiniteScroll() }, renderTemplate : function() { - this.postRenderTemplate(); - //setTimeout(_.bind(this.mason, this), 1000) + this.stream.items.each(_.bind(function(post){ + this.$el.append(this.createPostView(post).render().el); + }, this)) + //needs to be defered so it happens after html rendering finishes + _.defer(_.bind(this.mason, this)) }, - mason : function() { + addPostView : function(post) { + _.defer(_.bind(function(){ this.$el.isotope("insert", this.createPostView(post).render().$el) }, this)) + }, + + mason : function() { this.$el.isotope({ itemSelector : '.canvas-frame' }) } -})) +})); diff --git a/app/assets/javascripts/app/views/profile_info_view.js b/app/assets/javascripts/app/views/profile_info_view.js new file mode 100644 index 000000000..f94f6d223 --- /dev/null +++ b/app/assets/javascripts/app/views/profile_info_view.js @@ -0,0 +1,7 @@ +app.views.ProfileInfo = app.views.Base.extend({ + templateName : "profile-info", + + initialize : function(){ + this.model.bind("change", this.render, this) //this should go on profile info view when it gets Extracted + } +}) \ No newline at end of file diff --git a/app/assets/stylesheets/new_styles/_spinner.scss b/app/assets/stylesheets/new_styles/_spinner.scss index 0e9c72ba1..25b392184 100644 --- a/app/assets/stylesheets/new_styles/_spinner.scss +++ b/app/assets/stylesheets/new_styles/_spinner.scss @@ -8,6 +8,11 @@ .loader { display: inline-block; + + &.hidden{ + display : none; + } + width : 14px; height: 14px; background-image : url(asset_path("static-loader.png", "image")) diff --git a/app/assets/templates/profile-info.jst.hbs b/app/assets/templates/profile-info.jst.hbs new file mode 100644 index 000000000..ef9608aa9 --- /dev/null +++ b/app/assets/templates/profile-info.jst.hbs @@ -0,0 +1,7 @@ +

{{full_name}}

+
+
Location:
{{location}}
+
Bio:
{{bio}}
+
Birthday:
{{birthday}}
+
Gender:
{{gender}}
+
\ No newline at end of file diff --git a/app/assets/templates/profile.jst.hbs b/app/assets/templates/profile.jst.hbs index 7e4d64802..0fc16c895 100644 --- a/app/assets/templates/profile.jst.hbs +++ b/app/assets/templates/profile.jst.hbs @@ -2,15 +2,7 @@ editing... -
-

{{full_name}}

-
-
Location:
{{location}}
-
Bio:
{{bio}}
-
Birthday:
{{birthday}}
-
Gender:
{{gender}}
-
-
+
COMPOSE | EDIT diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 3a3880964..5684cf359 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -123,7 +123,7 @@ class PeopleController < ApplicationController format.all do if params[:ex] @page = :experimental - render 'experimental', :layout => 'post' + render :text => @stream.stream_posts.as_api_response(:backbone).to_json, :layout => 'post' else respond_with @person, :locals => {:post_type => :all} end diff --git a/app/views/layouts/post.html.haml b/app/views/layouts/post.html.haml index ae393cd62..25e7711da 100644 --- a/app/views/layouts/post.html.haml +++ b/app/views/layouts/post.html.haml @@ -55,5 +55,4 @@ %body = flash_messages #container - - = yield + = javascript_tag "window.preLoadContent = '#{escape_javascript(yield)}'" diff --git a/spec/javascripts/app/pages/profile_spec.js b/spec/javascripts/app/pages/profile_spec.js index ab0032ecc..23db4a1bb 100644 --- a/spec/javascripts/app/pages/profile_spec.js +++ b/spec/javascripts/app/pages/profile_spec.js @@ -18,10 +18,10 @@ describe("app.pages.Profile", function(){ expect(this.page.canvasView.model).toBe(this.stream) }); - it("fetches the stream for the user", function(){ - spyOn(this.stream, "fetch") + it("preloads the stream for the user", function(){ + spyOn(this.stream, "preload") new app.pages.Profile({stream : this.stream}) - expect(this.stream.fetch).toHaveBeenCalled() + expect(this.stream.preload).toHaveBeenCalled() }) describe("rendering", function(){ diff --git a/spec/javascripts/app/views/photos_view_spec.js b/spec/javascripts/app/views/photos_view_spec.js index 2a240e856..6c24f5e6e 100644 --- a/spec/javascripts/app/views/photos_view_spec.js +++ b/spec/javascripts/app/views/photos_view_spec.js @@ -12,7 +12,7 @@ describe("app.views.Photos", function() { // do this manually because we've moved loadMore into render?? this.view.render(); _.each(this.view.collection.models, function(photo) { - this.view.addPost(photo); + this.view.addPostView(photo); }, this); }); diff --git a/spec/javascripts/app/views/stream_view_spec.js b/spec/javascripts/app/views/stream_view_spec.js index 616c1d4a8..0e98fff70 100644 --- a/spec/javascripts/app/views/stream_view_spec.js +++ b/spec/javascripts/app/views/stream_view_spec.js @@ -12,7 +12,7 @@ describe("app.views.Stream", function() { // do this manually because we've moved loadMore into render?? this.view.render(); _.each(this.view.collection.models, function(post) { - this.view.addPost(post); + this.view.addPostView(post); }, this); });