Noosfero/noosfero

View on GitHub
app/views/profile/_comment.html.erb

Summary

Maintainability
Test Coverage
<li class="article-comment comment-logged-<%= comment.author ? 'in' : 'out' %>">

  <div class="comment-author-pic">
    <% if comment.author %>
      <%= link_to image_tag(profile_icon(comment.author, :minor)),
        comment.author_url,
        :class => 'comment-picture',
        :title => comment.author_name
      %>
    <% else %>
      <% url_image, status_class = comment.author_id ?
        [comment.removed_user_image, 'icon-user-removed'] :
        [gravatar_profile_image_url( comment.email ), 'icon-user-unknown'] %>

      <%= link_to(
        image_tag(url_image, :onerror=>'gravatarCommentFailback(this)',
                  'data-gravatar'=>gravatar_profile_image_url(comment.email)) +
          content_tag('span', comment.author_name, :class => 'comment-info') +
          content_tag('span', comment.message,
                  :class => 'comment-user-status comment-user-status-wall ' + status_class),
                  gravatar_profile_url(comment.email),
                  :target => '_blank',
                  :class => 'comment-picture',
                  :title => '%s %s' % [comment.author_name, comment.message]
      )%>
    <% end %>
  </div>

  <div class="comment-content">
      <%= comment.author.present? ? link_to(comment.author_name, comment.author.url) : content_tag('strong', comment.author_name) %>
      <%= time_ago comment %>
      <p><%= txt2html comment.body %></p>
  </div>

  <% if logged_in? && (user == profile || user == comment.author || user.has_permission?(:moderate_comments, profile)) %>
    <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".article-comment", url_for(:profile => params[:profile], :action => :remove_comment, :comment_id => comment.id, :view => params[:view]), _('Are you sure you want to remove this comment and all its replies?')], :class => 'button icon-button icon-delete') %>
  <% end %>

  <div class="comment_reply post_comment_box closed">
    <% if @comment && @comment.errors.any? && @comment.reply_of_id.to_i == comment.id %>
      <%= error_messages_for :comment %>
      <script type="text/javascript">
        jQuery(function() {
          document.location.href = '#<%= comment.anchor %>';
          add_comment_reply_form('#comment-reply-to-<%= comment.id %>', <%= comment.id %>);
        });
      </script>
    <% end %>
    <%= report_abuse(comment.author, :comment_link, comment) if comment.author %>
    <% if comment.author && comment.author == user %>
      <%= expirable_comment_link comment, :edit, _('Edit'), {:action => 'edit_comment', :id => comment.id, :profile => profile.identifier} %>
      <%= content_tag('span', ' | ', :class => 'comment-footer comment-footer-hide') %>
    <% end %>
    <%= link_to_function _('Reply'),
        "var f = add_comment_reply_form(this, %s); f.find('input[name=comment[title]], textarea').val(''); return false" % comment.id,
        :class => 'comment-footer comment-footer-link comment-footer-hide',
        :id => 'comment-reply-to-' + comment.id.to_s
    %>
  </div>

  <% unless comment.replies.blank? %>
  <ul class="comment-replies">
    <% comment.replies.each do |reply| %>
      <%= render :partial => 'comment', :locals => { :comment => reply } %>
    <% end %>
  </ul>
  <% end %>

  </div>
</li>