remove js resposne for likes, do it in backbone with json responses instead
This commit is contained in:
parent
d9d878f11f
commit
6760e3868d
4 changed files with 50 additions and 8 deletions
|
|
@ -17,7 +17,6 @@ class LikesController < ApplicationController
|
||||||
Postzord::Dispatcher.build(current_user, @like).post
|
Postzord::Dispatcher.build(current_user, @like).post
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js { render 'likes/update', :status => 201 }
|
|
||||||
format.html { render :nothing => true, :status => 201 }
|
format.html { render :nothing => true, :status => 201 }
|
||||||
format.mobile { redirect_to post_path(@like.post_id) }
|
format.mobile { redirect_to post_path(@like.post_id) }
|
||||||
format.json{ render :json => @like.as_api_response(:backbone), :status => 201 }
|
format.json{ render :json => @like.as_api_response(:backbone), :status => 201 }
|
||||||
|
|
@ -35,13 +34,11 @@ class LikesController < ApplicationController
|
||||||
current_user.retract(@like)
|
current_user.retract(@like)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.any { }
|
format.any { }
|
||||||
format.js { render 'likes/update' }
|
|
||||||
format.json { render :nothing => true, :status => 204}
|
format.json { render :nothing => true, :status => 204}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.mobile { redirect_to :back }
|
format.mobile { redirect_to :back }
|
||||||
format.js { render :nothing => true, :status => 403 }
|
|
||||||
format.json { render :nothing => true, :status => 403}
|
format.json { render :nothing => true, :status => 403}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -61,6 +58,8 @@ class LikesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
def target
|
def target
|
||||||
@target ||= if params[:post_id]
|
@target ||= if params[:post_id]
|
||||||
current_user.find_visible_shareable_by_id(Post, params[:post_id])
|
current_user.find_visible_shareable_by_id(Post, params[:post_id])
|
||||||
|
|
|
||||||
|
|
@ -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)) %>");
|
|
||||||
|
|
@ -102,7 +102,6 @@
|
||||||
<a href="/posts/<%= id %>/likes" class="expand_likes">
|
<a href="/posts/<%= id %>/likes" class="expand_likes">
|
||||||
<%= likes_count %> like
|
<%= likes_count %> like
|
||||||
</a>
|
</a>
|
||||||
<span class="hidden likes_list"></span>
|
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ App.Views.Post = App.Views.StreamObject.extend({
|
||||||
"focus .comment_box": "commentTextareaFocused",
|
"focus .comment_box": "commentTextareaFocused",
|
||||||
"click .shield a": "removeNsfwShield",
|
"click .shield a": "removeNsfwShield",
|
||||||
"click .remove_post": "destroyModel",
|
"click .remove_post": "destroyModel",
|
||||||
"click .like_action": "toggleLike"
|
"click .like_action": "toggleLike",
|
||||||
|
"click .expand_likes": "expandLikes"
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
@ -76,6 +77,52 @@ App.Views.Post = App.Views.StreamObject.extend({
|
||||||
return this;
|
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("<a>", {
|
||||||
|
href : "/person/" + model.get("author")["id"]
|
||||||
|
}).html($("<img>", {
|
||||||
|
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){
|
focusCommentTextarea: function(evt){
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
this.$(".new_comment_form_wrapper").removeClass("hidden");
|
this.$(".new_comment_form_wrapper").removeClass("hidden");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue