<% if tasks.blank? %>
  <p class="nodata"><%= l(:label_no_data) -%></p>
<% else %>
  <%= form_tag do %>
    <table class="list easy-rake-tasks">
      <tbody>
      <% grouped_tasks = tasks.group_by(&:category_caption_key) %>
      <% grouped_tasks.keys.sort { |a, b| a == :label_others ? 1 : (b == :label_others ? -1 : l(a) <=> l(b)) }.each do |category_key| %>
        <tr id="easy_rake_task-<%= category_key.to_s.underscore %>" class="group open">
          <td colspan="4" class="expander">
            <span class="expander" onclick="EASY.utils.toggleTableRowVisibility('', 'easy_rake_task', '<%= category_key.to_s.underscore -%>');" alt="Expander" title="<%= l(:collapse_expand) %>">&nbsp;</span><%= l(category_key) %>
          </td>
        </tr>

        <% grouped_tasks[category_key].each do |task| %>
          <% row_color = cycle('even', 'odd') %>
          <tr class="<%= row_color -%> hascontextmenu parenteasy_rake_task_<%= category_key.to_s.underscore %>">
            <td style="display: none;" class="checkbox hide-when-print"><%= check_box_tag 'ids[]', task.id, false, :id => nil, :class => 'checkbox hide-when-print' -%></td>
            <td><%= checked_image task.active? %></td>
            <td class="name">
              <%= link_to(task.caption, edit_easy_rake_task_path(task, {:back_url => url_for(params)})) -%>
              <br/>
              <%= task_period_description(task) %>
              <span class="contextual">
                <%= l(:label_easy_rake_last)%>: <%= l(:x_seconds, :scope => [:datetime, :distance_in_words], :count => task.last_duration) %>
                <%= l(:label_easy_rake_average)%>: <%= l(:x_seconds, :scope => [:datetime, :distance_in_words], :count => task.average_duration) %>
              </span>
            </td>
            <td class="buttons easy-query-additional-ending-buttons">
              <span class="btn_contextmenu_trigger icon icon-settings" title="<%= l(:label_settings) %>"></span>
            </td>
          </tr>
        <% end %>

      <% end %>

      </tbody>
    </table>
  <% end %>
<% end %>
