Newer
Older
dmpopidor / app / views / phases / _list_notes.html.erb
<!--table displaying notes for this question and actions-->

<% if notes.count > 1 then%>
  <% style_to_add =  "height:150px; overflow-y:auto;" %>
<%else%>
  <% style_to_add = "" %>
<%end%>

<!-- sort notes into descending updated order -->
<% notes.sort! {|x,y| y["updated_at"] <=> x["updated_at"] } %>  <!--TODO: is this right? - probably not! -->

<div class="two-column-clear question-divider"></div>

<div class="div-table-content" style ="<%= style_to_add %>">
  <table class="dmp_table" id="dmp_table">
    <tbody class= "comment_table_body">
      <% notes.each do |c|%>
        <tr >
          <td class="dmp_border_bottom">
            <% user = c["user"] %>
            <% user = User.find(c["user_id"]) %>
            <%= user["name"] %> </br>
            (<%= l c["updated_at"], format: :custom %>)
          </td >
          <td  class="dmp_border_bottom">

            <% if c["archived"]  %>

              <% if c["archived_by"] == current_user.id %>
                <%= t("helpers.comments.retracted")%>
              <% else %>
                <% archived_by_user = User.find(c["archived_by"]) %>
                <%= t("helpers.comments.clear_by")%> <%= archived_by_user.name %>
              <%end%>

            <%else%>   <!-- not archived -->

              <%= link_to t("helpers.comments.view_label"),"#", :class => "dmp_table_link view_comment_button" %>
              <%= hidden_field_tag :note_id, c["id"], :class => "comment_id" %>

              <% if current_user.id == c["user_id"] %>
                <%= link_to t("helpers.comments.edit_label"),"#", :class => "dmp_table_link edit_comment_button" %>
                <%= hidden_field_tag :note_id, c["id"], :class => "comment_id" %>
                <%= link_to t("helpers.comments.retract_label"),"#", :class => "dmp_table_link archive_comment_button" %>
              <% end%>   <!-- if current user -->

              <% if plan.administerable_by?(current_user.id) && current_user.id != c["user_id"] %>
                <%= hidden_field_tag :note_id, c["id"], :class => "comment_id" %>
                <%= link_to t("helpers.comments.clear_label"),"#", :class => "dmp_table_link archive_comment_button" %>
              <% end%>
            <%end%>   <!-- archived -->

          </td>
        </tr>
      <%end%>   <!-- notes each -->
    </tbody>
  </table>
</div>

<div class="two-column-clear question-divider"></div>

<!-- view latest note block -->
<% notes_not_archived = notes.select { |n| n["archived"].nil? }  %>
<% latest_note = notes_not_archived.sort { |x,y| y["updated_at"] <=> x["updated_at"] }.first %>   <!--TODO: is this comp right? -->
<% if !latest_note.nil? then%>
  <div id = "latest_comment_div_<%= question["id"] %>" class ="view_comment_class">
    <%= render :partial => "view_note", locals: {note: latest_note} %>
    <div class="two-column-clear question-divider"></div>
  </div>
<%end%>
<!-- load notes to view and edit -->
<%notes.each do |com|%>
  <!-- view note -->
  <div id = "view_comment_div_<%= com["id"] %>" class ="view_comment_class" style="display: none">
    <%= render :partial => "view_note", locals: {note: com} %>
    <div class="two-column-clear question-divider"></div>
  </div>

  <!-- edit note block -->
  <div id = "edit_comment_div_<%= com["id"] %>"  class ="edit_comment_class" style="display: none">
    <%= render :partial => "edit_note", locals: {note: com} %>
    <div class="two-column-clear question-divider"></div>
  </div>

  <!-- archive note block -->
  <div id = "archive_comment_div_<%= com["id"] %>"  class ="archive_comment_class" style="display: none">
    <%= render :partial => "archive_note", locals: {note: com} %>
    <div class="two-column-clear question-divider"></div>
  </div>

<%end%>