<%
# Code Review plugin for Redmine
# Copyright (C) 2009  Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-%>
<% for journal in journals %>

  <!-- skip initial entry of code review creation -->
  <% if not journal.initial? %>

    <!-- header and notes/comments -->
    <%
    header = <<-HTML
        <h4>
          #{authoring journal.created_at, journal.user, :label => :label_updated_time_by}
          #{content_tag('a', '', :name => "note-#{journal.anchor}")}
        </h4>

        <div class="profile-wrap">
          #{avatar(journal.user, :size => "40")}
        </div>
      HTML

    if not journal.notes.blank?
      if User.current.logged?
        editable = User.current.allowed_to?(:edit_issue_notes, journal.project)
        if journal.user == User.current
          editable ||= User.current.allowed_to?(:edit_own_issue_notes, journal.project)
        end
      end

      links = [].tap do |l|
        if editable
          l << link_to_in_place_notes_editor(image_tag('edit.png'), "journal-#{journal.id}-notes",
                { :controller => 'journals', :action => 'edit', :id => journal },
                  :title => l(:button_edit))
        end
      end

      css_classes = "wiki"
      css_classes << " editable" if editable

      content = ''
      content << content_tag('div', links.join(' '), :class => 'contextual') unless links.empty?
      content << textilizable(journal, :notes)

      header << content_tag("div", content, :id => "journal-#{journal.id}-notes", :class => css_classes)
    end
    %>

    <!-- details such as attribute changes -->
    <%
    details = ''
    if journal.details.any?
      content = journal.details.collect do |detail|
                  if d = journal.render_detail(detail)
                    content_tag("li", d)
                  end
                end.compact.join(' ')

      details = content_tag("ul", content, :class => "details journal-attributes") unless content.empty?
    end
    %>

    <!-- output HTML code -->
    <%= content_tag "div", "#{header}#{details}",
            { :id => "change-#{journal.id}", :class => journal.css_classes } %>

  <% end %>

<% end %>
