<%#
  This file is a part of RedmineX UX Upgrade plugin
  for Redmine

  Copyright 2020-2022 RedmineX. All Rights Reserved.
  https://www.redmine-x.com

  Licensed under GPL v2 (http://www.gnu.org/licenses/gpl-2.0.html)
  Created by Ondřej Svejkovský
%>

<% query_options = nil unless defined?(query_options) %>
<% query_options ||= {} %>

<%= form_tag({}, :data => {:cm_url => issues_context_menu_path}) do -%>
<%= hidden_field_tag 'back_url', url_for(:params => request.query_parameters), :id => nil %>
<%= query_columns_hidden_tags(query) %>
<div class="autoscroll">
<table class="list issues odd-even <%= query.css_classes %>">
  <thead>
    <tr>
      <th class="checkbox hide-when-print">
        <%= check_box_tag 'check_all', '', false, :class => 'toggle-selection',
              :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}" %>
      </th>
      <% query.inline_columns.each do |column| %>
        <%= column_header(query, column, query_options) %>
      <% end %>
      <th class="buttons"></th>
    </tr>
  </thead>
  <tbody>
  <script>
    window.rememberCollapsedIssuesState = <%= Setting.plugin_000_redmine_x_ux_upgrade[:remember_collapsed_issues_state] ? true : false  %>;
  </script>
  <%# We use group object_id to identify every type of group %>
  <% grouped_issue_list_projectino(issues, query) do |issue, level, group_name, group_count, group_totals, group_object_id| -%>
  <% if group_name %>
    <% reset_cycle %>
    <tr class="group open">
      <td colspan="<%= query.inline_columns.size + 2 %>">
        <%# Toggle functions are replaced by projectino versions, which enable to save state of the boxes 
            - see standard_theme.js %>
        <span class="expander icon icon-expended issue-group" id="<%= group_object_id %>" data-user="<%= User.current.id %>" onclick="window.RXU.Issues.toggleRowGroupProjectino(this);">&nbsp;</span>
        <span class="name"><%= group_name %></span> <span class="badge badge-count count"><%= group_count %></span> <span class="totals"><%= group_totals %></span>
        <%= link_to_function("#{l(:button_collapse_all)}/#{l(:button_expand_all)}",
                             "window.RXU.Issues.toggleAllRowGroupsProjectino(this)", :class => 'toggle-all', :'data-user' => User.current.id) %>
      </td>
    </tr>
  <% end %>
  <tr id="issue-<%= issue.id %>" class="hascontextmenu <%= cycle('odd', 'even') %> <%= issue.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
    <td class="checkbox hide-when-print"><%= check_box_tag("ids[]", issue.id, false, :id => nil) %></td>
    <% query.inline_columns.each do |column| %>
    <%= content_tag('td', column_content(column, issue), :class => column.css_classes ) %>
    <% end %>
    <td class="buttons"><%= link_to_context_menu_with_edit(issue) %></td>
  </tr>
  <% query.block_columns.each do |column|
       if (text = column_content(column, issue)) && text.present? -%>
  <tr class="<%= current_cycle %>">
    <td colspan="<%= query.inline_columns.size + 2 %>" class="<%= column.css_classes %> block_column">
      <% if query.block_columns.count > 1 %>
        <span><%= column.caption %></span>
      <% end %>
      <%= text %>
    </td>
  </tr>
  <% end -%>
  <% end -%>
  <% end -%>
  </tbody>
</table>
</div>
<% end -%>
