<%= title [l(:label_tracker_plural), trackers_path], l(:field_summary) %>

<% if @trackers.any? %>
  <%= form_tag fields_trackers_path do %>
    <div class="autoscroll">
    <table class="list tracker-summary">
    <thead>
      <tr>
        <th></th>
        <% @trackers.each do |tracker| %>
        <th>
          <%= toggle_checkboxes_link("input.tracker-#{tracker.id}") %>
          <%= tracker.name %>
        </th>
        <% end %>
      </tr>
    </thead>
    <tbody>
      <tr class="group open">
        <td colspan="<%= @trackers.size + 1 %>">
          <span class="expander icon icon-expanded" onclick="toggleRowGroup(this);"><%= sprite_icon("angle-down") %></span>
          <%= l(:field_core_fields) %>
        </td>
      </tr>
      <% Tracker::CORE_FIELDS.each do |field| %>
      <tr>
        <% field_name = l("field_#{field}".delete_suffix('_id')) %>
        <td class="name">
          <%= toggle_checkboxes_link("input.core-field-#{field}") %>
          <%= field_name %>
        </td>
        <% @trackers.each do |tracker| %>
        <td title="<%= "#{tracker.name}: #{field_name}" %>">
          <%= check_box_tag "trackers[#{tracker.id}][core_fields][]", field, tracker.core_fields.include?(field),
                            :class => "tracker-#{tracker.id} core-field-#{field}", :id => nil %>
        </td>
        <% end %>
      </tr>
      <% end %>
      <% if @custom_fields.any? %>
        <tr class="group open">
          <td colspan="<%= @trackers.size + 1 %>">
            <span class="expander icon icon-expanded" onclick="toggleRowGroup(this);"><%= sprite_icon("angle-down") %></span>
            <%= l(:label_custom_field_plural) %>
          </td>
        </tr>
        <% @custom_fields.each do |field| %>
        <tr>
          <td class="name">
            <%= toggle_checkboxes_link("input.custom-field-#{field.id}") %>
            <%= field.name %>
          </td>
          <% @trackers.each do |tracker| %>
          <td title="<%= "#{tracker.name}: #{field.name}" %>">
            <%= check_box_tag "trackers[#{tracker.id}][custom_field_ids][]", field.id, tracker.custom_fields.include?(field),
                              :class => "tracker-#{tracker.id} custom-field-#{field.id}", :id => nil %>
          </td>
          <% end %>
        </tr>
        <% end %>
      <% end %>
    </tbody>
    </table>
    </div>
    <p><%= submit_tag l(:button_save) %></p>
    <% @trackers.each do |tracker| %>
      <%= hidden_field_tag "trackers[#{tracker.id}][core_fields][]", '' %>
      <%= hidden_field_tag "trackers[#{tracker.id}][custom_field_ids][]", '' %>
    <% end %>
  <% end %>
<% else %>
  <p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
