like comments js response wip
This commit is contained in:
parent
2e15b6a61e
commit
797a6f5ca9
14 changed files with 48 additions and 51 deletions
|
|
@ -24,7 +24,7 @@ class LikesController < ApplicationController
|
|||
Postzord::Dispatch.new(current_user, @like).post
|
||||
|
||||
respond_to do |format|
|
||||
format.js { render :status => 201 }
|
||||
format.js { render 'likes/update', :status => 201 }
|
||||
format.html { render :nothing => true, :status => 201 }
|
||||
format.mobile { redirect_to post_path(@like.post_id) }
|
||||
end
|
||||
|
|
@ -37,10 +37,13 @@ class LikesController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
target_id = params[:post_id] || params[:comment_id]
|
||||
|
||||
if @like = Like.where(:id => params[:id], :author_id => current_user.person.id, :target_id => target_id).first
|
||||
if @like = Like.where(:id => params[:id], :author_id => current_user.person.id).first
|
||||
current_user.retract(@like)
|
||||
pp @like
|
||||
respond_to do |format|
|
||||
format.all{}
|
||||
format.js{ render 'likes/update' }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.mobile {redirect_to :back}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class Comment < ActiveRecord::Base
|
|||
belongs_to :post, :touch => true
|
||||
belongs_to :author, :class_name => 'Person'
|
||||
|
||||
has_many :likes, :foreign_key => :target_id, :conditions => {:positive => true}, :dependent => :delete_all
|
||||
has_many :likes, :conditions => {:positive => true}, :dependent => :delete_all, :as => :target
|
||||
|
||||
validates_presence_of :text, :post
|
||||
validates_length_of :text, :maximum => 2500
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class Like < ActiveRecord::Base
|
|||
belongs_to :target, :polymorphic => true #, :counter_cache => true
|
||||
belongs_to :author, :class_name => 'Person'
|
||||
|
||||
validates_uniqueness_of :target_id, :scope => :author_id
|
||||
validates_uniqueness_of :target_id, :scope => [:target_type, :author_id]
|
||||
validates_presence_of :author, :target
|
||||
|
||||
def diaspora_handle
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ class User < ActiveRecord::Base
|
|||
if target.likes.loaded?
|
||||
return target.likes.detect{ |like| like.author_id == self.person.id }
|
||||
else
|
||||
return Like.where(:author_id => self.person.id, :target_id => target.id).first
|
||||
return Like.where(:author_id => self.person.id, :target_type => target.class.base_class.to_s, :target_id => target.id).first
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
-# licensed under the Affero General Public License version 3 or later. See
|
||||
-# the COPYRIGHT file.
|
||||
|
||||
%li.comment.posted{:data=>{:guid => comment.id}, :class => ("hidden" if(defined? hidden))}
|
||||
%li.comment.posted{:id => comment.guid, :class => ("hidden" if(defined? hidden))}
|
||||
- if current_user && (current_user.owns?(comment) || current_user.owns?(post))
|
||||
.right.controls
|
||||
= link_to image_tag('deletelabel.png'), post_comment_path(comment.post_id, comment), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete comment_delete", :title => t('delete')
|
||||
|
|
@ -16,9 +16,18 @@
|
|||
%span{:class => direction_for(comment.text)}
|
||||
= markdownify(Diaspora::Taggable.format_tags(comment.text), :youtube_maps => comment.youtube_titles)
|
||||
|
||||
%br
|
||||
.comment_info
|
||||
%time.timeago{:datetime => comment.created_at}
|
||||
= comment.created_at ? timeago(comment.created_at) : timeago(Time.now)
|
||||
- unless (defined?(@commenting_disabled) && @commenting_disabled)
|
||||
= like_action(comment, current_user)
|
||||
·
|
||||
|
||||
.likes
|
||||
= render "likes/likes_container", :target_id => comment.id, :likes_count => comment.likes.count
|
||||
|
||||
- if comment.likes.count > 0
|
||||
·
|
||||
|
||||
- unless (defined?(@commenting_disabled) && @commenting_disabled)
|
||||
%span.like_action
|
||||
= like_action(comment, current_user)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@
|
|||
-# licensed under the Affero General Public License version 3 or later. See
|
||||
-# the COPYRIGHT file.
|
||||
|
||||
- if likes_count > 0
|
||||
.likes_container
|
||||
.likes
|
||||
= image_tag('icons/heart.svg')
|
||||
= link_to t('likes.likes.people_like_this', :count => likes_count), post_likes_path(target_id), :class => "expand_likes"
|
||||
%span.hidden.likes_list
|
||||
/= render 'likes/likes', :likes => likes
|
||||
.likes_container
|
||||
- if likes_count > 0
|
||||
= image_tag('icons/heart.svg')
|
||||
= link_to t('likes.likes.people_like_this', :count => likes_count), post_likes_path(target_id), :class => "expand_likes"
|
||||
%span.hidden.likes_list
|
||||
/= render 'likes/likes', :likes => likes
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
$(".like_action", ".stream_element[data-guid=<%=@like.target_id%>]").html("<%= escape_javascript(like_action(@like.target))%>");
|
||||
|
||||
WebSocketReceiver.processLike("<%=@like.target_id%>", "<%= escape_javascript(render("likes/likes_container", :target_id => @like.target_id, :likes_count => @like.target.likes.count)) %>");
|
||||
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
$(".like_action", ".stream_element[data-guid=<%=@like.target_id%>]").html("<%= escape_javascript(like_action(@like.target))%>");
|
||||
WebSocketReceiver.processLike("<%=@like.target_id%>", "<%= escape_javascript(render("likes/likes_container", :target_id => @like.target_id, :likes_count => @like.target.likes.count)) %>");
|
||||
|
||||
2
app/views/likes/update.js.erb
Normal file
2
app/views/likes/update.js.erb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$(".like_action", "#<%=@like.target.guid%>").first().html("<%= escape_javascript(like_action(@like.target))%>");
|
||||
WebSocketReceiver.processLike("<%=@like.target.guid%>", "<%= escape_javascript(render("likes/likes_container", :target_id => @like.target_id, :likes_count => @like.target.likes.count)) %>");
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
-# licensed under the Affero General Public License version 3 or later. See
|
||||
-# the COPYRIGHT file.
|
||||
|
||||
.stream_element{:data=>{:guid=>post.id}}
|
||||
.stream_element{:id => post.guid}
|
||||
- if current_user && post.author.owner_id == current_user.id
|
||||
.right.controls
|
||||
= link_to image_tag('deletelabel.png'), post_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete stream_element_delete", :title => t('delete')
|
||||
|
|
@ -55,8 +55,7 @@
|
|||
·
|
||||
= link_to t('comments.new_comment.comment'), '#', :class => 'focus_comment_textarea'
|
||||
|
||||
.likes
|
||||
- if post.likes.count > 0
|
||||
= render "likes/likes_container", :target_id => post.id, :likes_count => post.likes.count, :current_user => current_user
|
||||
.likes
|
||||
= render "likes/likes_container", :target_id => post.id, :likes_count => post.likes.count, :current_user => current_user
|
||||
|
||||
= render "comments/comments", :post => post, :current_user => current_user, :commenting_disabled => (defined?(@commenting_disabled) && @commenting_disabled)
|
||||
|
|
|
|||
|
|
@ -4,14 +4,11 @@
|
|||
*/
|
||||
|
||||
var ContentUpdater = {
|
||||
elementWithGuid: function(selector, guid) {
|
||||
return $(selector + "[data-guid='" + guid + "']");
|
||||
},
|
||||
addPostToStream: function(html) {
|
||||
var streamElement = $(html);
|
||||
var postId = streamElement.attr("data-guid");
|
||||
var postId = streamElement.id;
|
||||
|
||||
if($(".stream_element[data-guid='" + postId + "']").length === 0) {
|
||||
if($(".stream_element#" + postId).length === 0) {
|
||||
if($("#no_posts").length) {
|
||||
$("#no_posts").detach();
|
||||
}
|
||||
|
|
@ -27,7 +24,7 @@ var ContentUpdater = {
|
|||
},
|
||||
|
||||
addLikesToPost: function(postId, html) {
|
||||
var post = ContentUpdater.elementWithGuid("div", postId);
|
||||
var post = $("div#" + postId);
|
||||
|
||||
$(".likes_container", post)
|
||||
.fadeOut("fast")
|
||||
|
|
@ -35,4 +32,4 @@ var ContentUpdater = {
|
|||
.fadeIn("fast");
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ var View = {
|
|||
|
||||
/* notification routing */
|
||||
$("#notification").delegate('.hard_object_link', 'click', function(evt){
|
||||
var post = $("*[data-guid='"+ $(this).attr('data-ref') +"']"),
|
||||
var post = $("#"+ $(this).attr('data-ref')),
|
||||
lastComment = post.find('.comment.posted').last();
|
||||
|
||||
if(post.length > 0){
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ var WebSocketReceiver = {
|
|||
},
|
||||
|
||||
processRetraction: function(post_id){
|
||||
$("*[data-guid='" + post_id + "']").fadeOut(400, function() {
|
||||
$("#" + post_id).fadeOut(400, function() {
|
||||
$(this).remove();
|
||||
});
|
||||
if($("#main_stream")[0].childElementCount === 0) {
|
||||
|
|
@ -87,9 +87,9 @@ var WebSocketReceiver = {
|
|||
|
||||
processComment: function(postId, commentId, html, opts) {
|
||||
|
||||
if( $(".comment[data-guid='"+commentId+"']").length === 0 ) {
|
||||
if( $("#"+commentId).length === 0 ) {
|
||||
|
||||
var post = $("*[data-guid='"+postId+"']'"),
|
||||
var post = $("#"+postId),
|
||||
prevComments = $('.comment.posted', post);
|
||||
|
||||
if(prevComments.length > 0) {
|
||||
|
|
@ -123,9 +123,8 @@ var WebSocketReceiver = {
|
|||
Diaspora.widgets.directionDetector.updateBinds();
|
||||
},
|
||||
|
||||
processLike: function(postId, html) {
|
||||
var post = $("*[data-guid='"+postId+"']");
|
||||
$('.likes', post).html(html);
|
||||
processLike: function(targetGUID, html) {
|
||||
$('.likes', "#" + targetGUID).first().html(html);
|
||||
},
|
||||
|
||||
processPost: function(className, postId, html, aspectIds) {
|
||||
|
|
|
|||
|
|
@ -302,10 +302,10 @@ ul.as-selections
|
|||
:height 370px
|
||||
:width 500px
|
||||
|
||||
time
|
||||
:font
|
||||
:weight normal
|
||||
:size smaller
|
||||
.comment
|
||||
.comment_info
|
||||
:font
|
||||
:size smaller
|
||||
|
||||
.from
|
||||
a
|
||||
|
|
@ -667,10 +667,6 @@ form.new_comment
|
|||
:display inline-block
|
||||
|
||||
|
||||
.comments
|
||||
.timeago
|
||||
:color #999
|
||||
|
||||
.stream.show
|
||||
ul.comments
|
||||
li
|
||||
|
|
|
|||
Loading…
Reference in a new issue