diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index f0ad406d9..e3f10b43d 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -17,7 +17,6 @@ class LikesController < ApplicationController Postzord::Dispatcher.build(current_user, @like).post respond_to do |format| - format.js { render 'likes/update', :status => 201 } format.html { render :nothing => true, :status => 201 } format.mobile { redirect_to post_path(@like.post_id) } format.json{ render :json => @like.as_api_response(:backbone), :status => 201 } @@ -35,13 +34,11 @@ class LikesController < ApplicationController current_user.retract(@like) respond_to do |format| format.any { } - format.js { render 'likes/update' } format.json { render :nothing => true, :status => 204} end else respond_to do |format| format.mobile { redirect_to :back } - format.js { render :nothing => true, :status => 403 } format.json { render :nothing => true, :status => 403} end end @@ -61,6 +58,8 @@ class LikesController < ApplicationController end end + protected + def target @target ||= if params[:post_id] current_user.find_visible_shareable_by_id(Post, params[:post_id]) diff --git a/app/views/likes/update.js.erb b/app/views/likes/update.js.erb deleted file mode 100644 index 1eaa8dfe2..000000000 --- a/app/views/likes/update.js.erb +++ /dev/null @@ -1,3 +0,0 @@ -var targetGuid = "<%=@like.target.guid%>"; -$(".like_action", "#"+targetGuid).first().html("<%= escape_javascript(like_action(@like.target))%>"); -ContentUpdater.addLikesToPost(targetGuid, "<%= escape_javascript(render("likes/likes_container", :target_id => @like.target_id, :likes_count => @like.target.reload.likes_count, :target_type => @like.target_type)) %>"); diff --git a/app/views/templates/stream_element.ujs b/app/views/templates/stream_element.ujs index 3100d1b75..3d63acb48 100644 --- a/app/views/templates/stream_element.ujs +++ b/app/views/templates/stream_element.ujs @@ -102,7 +102,6 @@ <%= likes_count %> like - <% } %> diff --git a/public/javascripts/app/views/post_view.js b/public/javascripts/app/views/post_view.js index 0725a1a00..73e310ce6 100644 --- a/public/javascripts/app/views/post_view.js +++ b/public/javascripts/app/views/post_view.js @@ -7,7 +7,8 @@ App.Views.Post = App.Views.StreamObject.extend({ "focus .comment_box": "commentTextareaFocused", "click .shield a": "removeNsfwShield", "click .remove_post": "destroyModel", - "click .like_action": "toggleLike" + "click .like_action": "toggleLike", + "click .expand_likes": "expandLikes" }, render: function() { @@ -76,6 +77,52 @@ App.Views.Post = App.Views.StreamObject.extend({ return this; }, + expandLikes: function(evt){ + if(evt) { evt.preventDefault(); } + + var self = this; + + this.model.likes.fetch({ + success: function(){ + // this should be broken out + + self.$(".expand_likes").remove(); + var likesView = Backbone.View.extend({ + + tagName: 'span', + + initialize: function(options){ + this.collection = options.collection; + _.bindAll(this, "render", "appendLike"); + }, + + render: function(){ + _.each(this.collection.models, this.appendLike) + return this; + }, + + appendLike: function(model){ + console.log(model.get('author')); + $(this.el).append("", { + href : "/person/" + model.get("author")["id"] + }).html($("", { + src : model.get("author")["avatar"]["small"], + "class" : "avatar" + })); + } + }); + + var view = new likesView({collection : self.model.likes}); + + self.$('.likes_container').removeClass("hidden") + .append(view.render().el); + + } + }); + + return this; + }, + focusCommentTextarea: function(evt){ evt.preventDefault(); this.$(".new_comment_form_wrapper").removeClass("hidden");