diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2c3b35a..d08c65b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -30,6 +30,8 @@ module ApplicationHelper include AccountHelper + include CommentHelper + def locale (@page && !@page.language.blank?) ? @page.language : FastGettext.locale end diff --git a/app/helpers/comment_helper.rb b/app/helpers/comment_helper.rb index d3d1454..36a52f7 100644 --- a/app/helpers/comment_helper.rb +++ b/app/helpers/comment_helper.rb @@ -21,5 +21,44 @@ module CommentHelper end title end + + #FIXME make this test + def comment_actions(comment) + links = links_for_comment_actions(comment) + content_tag(:li, link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger'), :class=> 'vcard') unless links.empty? + end + + private + + def links_for_comment_actions(comment) + [link_for_report_abuse(comment), link_for_spam(comment), link_for_edit(comment), link_for_remove(comment)].compact + end + + def link_for_report_abuse(comment) + if comment.author + report_abuse_link = report_abuse(comment.author, :comment_link, comment) + {:link => report_abuse_link} if report_abuse_link + end + end + + def link_for_spam(comment) + if comment.spam? + {:link => link_to_function(_('Mark as NOT SPAM'), 'remove_comment(this, %s); return false;' % url_for(:profile => profile.identifier, :mark_comment_as_ham => comment.id).to_json, :class => 'comment-footer comment-footer-link comment-footer-hide')} + elsif (logged_in? && (user == profile || user.has_permission?(:moderate_comments, profile))) + {:link => link_to_function(_('Mark as SPAM'), 'remove_comment(this, %s, %s); return false;' % [url_for(:profile => profile.identifier, :controller => 'comment', :action => :mark_as_spam, :id => comment.id).to_json, _('Are you sure you want to mark this comment as SPAM?').to_json], :class => 'comment-footer comment-footer-link comment-footer-hide')} + end + end + + def link_for_edit(comment) + if comment.author && comment.author == user + {:link => expirable_comment_link(comment, :edit, _('Edit'), url_for(:profile => profile.identifier, :controller => :comment, :action => :edit, :id => comment.id),:class => 'colorbox')} + end + end + + def link_for_remove(comment) + if logged_in? && (user == profile || user == comment.author || user.has_permission?(:moderate_comments, profile)) + {:link => link_to_function(_('Remove'), 'remove_comment(this, %s, %s); return false ;' % [url_for(:profile => profile.identifier, :controller => 'comment', :action => :destroy, :id => comment.id).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')} + end + end end diff --git a/app/views/comment/_comment.rhtml b/app/views/comment/_comment.rhtml index 82cf2c3..1f30529 100644 --- a/app/views/comment/_comment.rhtml +++ b/app/views/comment/_comment.rhtml @@ -31,6 +31,21 @@ <% comment_balloon do %>
+
+ <%= comment_actions(comment) %>
+
+
+ <% unless comment.spam? %> + <%= link_to_function '', + "var f = add_comment_reply_form(this, %s); f.find('comment_title, textarea').val(''); return false" % comment.id, + :class => 'comment-footer comment-footer-link comment-footer-hide comment-actions-reply button', + :id => 'comment-reply-to-' + comment.id.to_s + %> + <% end %> +