<% provide :page_header do %>
  <h1><span class="fa fa-cloud-download" aria-hidden="true"></span> Exporters</h1>
  <div class="pull-right">
    <%= link_to new_exporter_path, class: 'btn btn-primary', data: { turbolinks: false } do %>
      <span class="fa fa-edit" aria-hidden="true"></span> <%= t(:'helpers.action.exporter.new') %>
    <% end %>
  </div>
<% end %>

<% content_for(:head) do %>
  <meta name="turbolinks-cache-control" content="no-cache">
<% end %>

<div class="panel panel-default">
  <div class="panel-body">
    <% if @exporters.present? %>
      <div class="table-responsive">
        <table class="table table-striped datatable">
          <thead>
            <tr>
              <th scope="col">Name</th>
              <th scope="col">Status</th>
              <th scope="col">Date Exported</th>
              <th scope="col">Downloadable Files</th>
              <th scope="col"></th>
              <th scope="col"></th>
              <th scope="col"></th>
            </tr>
          </thead>
          <tbody>
            <% @exporters.each do |exporter| %>
              <tr>
                <th scope="row"><%= link_to exporter.name, exporter_path(exporter) %></th>
                <td><%= exporter.status %></td>
                <td><%= exporter.created_at %></td>
                <td>
                  <% if File.exist?(exporter.exporter_export_zip_path) %>
                    <%= simple_form_for(exporter, method: :get, url: exporter_download_path(exporter)) do |form| %>
                      <%= render 'downloads', exporter: exporter, form: form %>
                      <%= form.button :submit, value: 'Download', data: { disable_with: false } %>
                    <% end %>
                  <% end%>
                </td>
                <td><%= link_to raw('<span class="glyphicon glyphicon-info-sign"></span>'), exporter_path(exporter) %></td>
                <td><%= link_to raw('<span class="glyphicon glyphicon-pencil"></span>'), edit_exporter_path(exporter), data: { turbolinks: false } %></td>
                <td><%= link_to raw('<span class="glyphicon glyphicon-remove"></span>'), exporter, method: :delete, data: { confirm: 'Are you sure?' } %></td>
              </tr>
            <% end %>
          </tbody>
        </table>
      </div>
      <% else %>
        <p>No exporters have been created.</p>
      <% end %>
  </div>
</div>

<script>
  $(function() {
    $('#DataTables_Table_0').DataTable({
      destroy: true, /* Reinitialize DataTable with config below */
      'columnDefs': [
          { 'orderable': true, 'targets': [0, 1, 2] },
          { 'orderable': false, 'targets': [3, 4, 5, 6] }
      ],
      'language': {
        'info': 'Showing _START_ to _END_ of _TOTAL_ exporters',
        'infoEmpty': 'No exporters to show',
        'infoFiltered': '(filtered from _MAX_ total exporters)',
        'lengthMenu': 'Show _MENU_ exporters'
      }
    })
  })
</script>