Commit d570dc448c7d2138fbce861371142a4f74414666
1 parent
c03afdf0
Exists in
master
and in
23 other branches
Properly update UI after comment removal/spam mark
ActionItem2306
Showing
3 changed files
with
15 additions
and
3 deletions
Show diff stats
app/helpers/content_viewer_helper.rb
| @@ -8,7 +8,7 @@ module ContentViewerHelper | @@ -8,7 +8,7 @@ module ContentViewerHelper | ||
| 8 | if n == 0 | 8 | if n == 0 |
| 9 | _('No comments yet') | 9 | _('No comments yet') |
| 10 | else | 10 | else |
| 11 | - n_('One comment', '%{comments} comments', n) % { :comments => n } | 11 | + n_('One comment', '<span class="comment-count">%{comments}</span> comments', n) % { :comments => n } |
| 12 | end | 12 | end |
| 13 | end | 13 | end |
| 14 | 14 |
app/views/content_viewer/_comment.rhtml
| @@ -65,7 +65,7 @@ | @@ -65,7 +65,7 @@ | ||
| 65 | 65 | ||
| 66 | <% if logged_in? && (user == profile || user == comment.author || user.has_permission?(:moderate_comments, profile)) %> | 66 | <% if logged_in? && (user == profile || user == comment.author || user.has_permission?(:moderate_comments, profile)) %> |
| 67 | | 67 | |
| 68 | - <%= link_to_function(_('Remove'), 'remove_comment(this, %s, %s); return false ;' % [url_for(:profile => params[:profile], :remove_comment => comment.id, :view => params[:view]).to_json, _('Are you sure you want to remove this comment and all its replies?').to_json], :class => 'comment-footer comment-footer-link comment-footer-hide') %> | 68 | + <%= link_to_function(_('Remove'), 'remove_comment(this, %s, %s); return false ;' % [url_for(:profile => params[:profile], :remove_comment => comment.id, :view => params[:view]).to_json, _('Are you sure you want to remove this comment and all its replies?').to_json], :class => 'comment-footer comment-footer-link comment-footer-hide remove-children') %> |
| 69 | <% end %> | 69 | <% end %> |
| 70 | 70 | ||
| 71 | <% unless comment.spam? %> | 71 | <% unless comment.spam? %> |
public/javascripts/application.js
| @@ -693,7 +693,19 @@ function remove_comment(button, url, msg) { | @@ -693,7 +693,19 @@ function remove_comment(button, url, msg) { | ||
| 693 | $button.addClass('comment-button-loading'); | 693 | $button.addClass('comment-button-loading'); |
| 694 | $.post(url, function(data) { | 694 | $.post(url, function(data) { |
| 695 | if (data.ok) { | 695 | if (data.ok) { |
| 696 | - $button.closest('.article-comment').slideUp(); | 696 | + var $comment = $button.closest('.article-comment'); |
| 697 | + var $replies = $comment.find('.comment-replies .article-comment'); | ||
| 698 | + $comment.slideUp(); | ||
| 699 | + var comments_removed = 1; | ||
| 700 | + if ($button.hasClass('remove-children')) { | ||
| 701 | + comments_removed = 1 + $replies.size(); | ||
| 702 | + } else { | ||
| 703 | + $replies.appendTo('.article-comments-list'); | ||
| 704 | + } | ||
| 705 | + $('.comment-count').each(function() { | ||
| 706 | + var count = parseInt($(this).html()); | ||
| 707 | + $(this).html(count - comments_removed); | ||
| 708 | + }); | ||
| 697 | } | 709 | } |
| 698 | }); | 710 | }); |
| 699 | } | 711 | } |