<% modul_uniq_id ||= ''
uniq_prefix = "#{controller_name}_#{action_name}_#{modul_uniq_id}"
previous_group = false
final_entities = entities.collect{|entity| (entity.child? && !entities.include?(entity.parent)) ? entity.self_and_ancestors : entity}.flatten.uniq.sort_by(&:lft) -%>
<div class="autoscroll">
  <table class="list">
    <thead>
      <tr>
        <%= '<th class="grouped-space"></th>'.html_safe if query.grouped? -%>
        <th></th>
        <th style="display:none"></th>
        <% query.columns.each do |column| -%>
          <%= content_tag('th', column.caption) -%>
        <% end -%>
        <% unless entity_link_block.nil? -%>
          <th class="fast-icons"></th>
        <% end %>
      </tr>
    </thead>
    <tbody>
      <% final_entities.each do |entity|
        uniq_id = uniq_prefix + "entity-#{entity.id}" -%>
        <% filter_uniq_id = uniq_prefix + "_#{query.group_by_column.name}_#{query.group_by_column.value(entity).hash}" if query.grouped?%>
        <% if query.grouped? && (group = query.group_by_column.value(entity)) != previous_group -%>
          <tr class="group <%= 'open' if !toggle_button_expanded?(filter_uniq_id) %><%= '  easy-to-do-list-source' if entity.is_a?(Project) -%>">
            <td colspan="<%= query.columns.size + 3 -%>">
              <span class="expander" onclick="EASY.query.toggleTableRowGroupVisibility(this,'<%= filter_uniq_id %>', '<%= User.current.id -%>', false); return false;" alt="Expander" title="<%=l :collapse_expand %>">&nbsp;</span>
              <%= group.blank? ? 'None' : format_html_entity_attribute(entity.class, query.group_by_column, query.group_by_column.value(entity), {:entity => entity}) -%> <span class="count">(<%= query.entity_count_by_group[group] -%>)</span>
            </td>
          </tr>
          <% previous_group = group -%>
        <% end -%>
        <% css_classes = ((' '+ uniq_prefix +'parententity_' + entity.parent_id.to_s) if entity.child?) || '' -%>
        <tr id="<%= uniq_id-%>" class="selectable <%= (cycle('odd', 'even') if entity.root?).to_s -%> <%= css_classes -%><%= ' context-menu-selection' if selected_values && selected_values.detect{|a,b| a == entity.id.to_s} -%>"<%= ' style="display:none"' if !entity.root? -%>>
          <%= '<td class="grouped-space"></td>'.html_safe if query.grouped? -%>
          <td class="expander"><span class="<%= 'expander' if entity.children && (final_entities & entity.children).size > 0 -%>" onclick="EASY.utils.toggleTableRowVisibility('<%= uniq_prefix -%>', 'entity', '<%= entity.id -%>', '<%= User.current.id -%>', false);" alt="Expander" title="<%=l :collapse_expand %>">&nbsp;</span></td>
          <td style="display: none">
            <%= entity_modal_selector_checker(entity, selected_values, options[:multiple]) %>
          </td>
          <% query.columns.each_with_index do |column, index| %>
            <td class="<%= column.name.to_s.underscore -%><%= " item-level-#{entity.level}" if index == 0 -%>"><%= format_html_entity_attribute(entity.class, column, column.value(entity, {:params => params}), :no_link => true, :entity => entity) -%></td>
          <% end -%>
          <% unless entity_link_block.nil? -%>
            <td class="fast-icons">
              <%= capture(entity, &entity_link_block) -%>
            </td>
          <% end -%>
        </tr>
      <% end -%>
    </tbody>
  </table>
</div>

