<% content_for :head do %>
  <%= javascript_include_tag 'app_table' %>
<% end %>

<h1 class="head"><%= controller.heading %></h1>

<% #session[:csv_data] = @data %>
<%#= render :partial => 'layouts/table', :locals => {:data => @data} %>

      <script type="text/javascript" language="javascript">
        function show_form_for(id,type) {
          window.location = '<%= controller.root_url %>'+type+'/edit/'+id
        }
      </script>
<p>
  <a href="<%= @wiki_link %>" title="Zur Online-Dokumentation der Prüfung" target="_BLANK">
    <i class="fa fa-question-circle-o" aria-hidden="true" alt="Zur Onlinedokumentation"  title="Zur Online-Dokumentation"></i> Zur Online-Dokumentation der Prüfung
  </a><br/>
  <% if @data.empty? %>
    Ihre Anfrage ergab keine Treffer.
  <% else %>

  <div id="control-form">
    <form name="pagination" id="pagination"  action="<%= url_for {} %>">
      <% offset = (params['offset'].to_i > 0) ? params['offset'].to_i : 0 %>
      <% amount = @user.rows_per_page %>
      <%= hidden_field_tag 'offset', offset %>
      <div class="pager">
        <% if offset > 0 %>
          <a href="javascript:page_before();"><i class="fa fa-step-backward" aria-hidden="true"></i></a>
        <%  end %>
       <%= "<span class='fw-600'>Einträge: </span><span> #{offset+1} <span>bis</span> #{[offset+amount, @data.rec_count.to_i].min} <span>von</span> #{@data.rec_count.to_s}</span>".html_safe %>
        <% if offset+amount < @data.rec_count.to_i %>
          <a href="javascript:page_after();"><i class="fa fa-step-forward" aria-hidden="true"></i></a>
        <% end %>
      </div>
      <div>
        <b>Einträge pro Seite:</b> <%= text_field_tag 'amount', amount, :size => 3 %>
        <button type="submit" id="eintraegeproseite" style="vertical-align: middle">
            <i class="fa fa-check" aria-hidden="true"></i>
        </button>
      </div>
    </form>
  </div>

  <table style="white-space: nowrap" class="dtable row-highlight" id="data-table">
    <thead id="flt_head">
      <tr>
        <% @columns.each do |col| %>
          <th title="<%= col[:human_name] %>">
            <%= col[:human_name] %>
          </th>
        <% end %>
      </tr>
    </thead>
    <% columns = prepare_columns %>
    <% @data.each do |row| %>
      <% zeile %>
      <tr>
          <% puts '!!!'+columns.inspect %>
        <% columns.each do |col| %>
          <td class="zeile<%= $x %>">
            <% puts '==='+col.inspect %>
            <% if col[:type] == :link %>
              <%= make_link(row,col) %>
            <% elsif col[:type] == :link_list %>
              <%= format_link_list(row[col[:col_name]], col[:url_options]) %>
            <% else %>
              <%= format_value_for(row[col[:col_name].split('.').last],col[:type]) %>
            <% end %>
          </td>
        <% end %>
        </tr>
      <% end %>
    </table>
<% end %>
</p>
