<% provide :title, t('.title') %>
<h4>Batch Uploads</h4>

<table width="100%" class="highlightable">
  <thead>
    <tr>
      <th width="5%">#</th>
      <th width="10%"><%= t('.username') %></th>
      <th width="10%"><%= t('.url') %></th>
      <th width="25%"><%= t('.tags') %></th>
      <th width="45%"><%= t('.status') %></th>
    </tr>
  </thead>
  <tbody>
    <% @items.each do |item| %>
      <tr class="<%= cycle 'even', 'odd' %>">
        <td><%= item.id %></td>
        <td><%= link_to h(User.find_name(item.user_id)), :controller => "user", :action => "show", :id => item.user_id %></td>

        <td><%= h(File.basename(item.url)) %></td>
        <td><%= h(item.tags) %></td>
        <td>
          <% if item.status == "error" then %>
            <% if item.data["post_id"] then %>
              <%= t('.exists_html', :id => link_to("##{item.data['post_id']}", :controller => '/post', :action => :show, :id => item.data['post_id'])) %>
            <% else %>
              <%= h(item.data["error"].to_s) %>
            <% end %>
          <% elsif item.status == "pending" then %>
            <% if item.active then %>
              <%= t('.uploading') %>
            <% else %>
              <%= t('.pending') %>
            <% end %>
          <% elsif item.status == "paused" then %>
            <%= t('.paused') %>
          <% elsif item.status == "finished" then %>
            <%= t('.completed_html', :id => link_to("##{item.data['post_id']}", :controller => '/post', :action => :show, :id => item.data['post_id'])) %>
          <% end %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>

<div class="batch-buttons">
  <%= form_tag({:action => "create"}, :method => :get) do %>
    <%= submit_tag t('.queue_uploads'), :name => "queue" %>
  <% end %>

  <%= form_tag({:action => "update"}) do %>
    <%= hidden_field_tag "do", "retry" %>
    <%= submit_tag t('.retry_failed') %>
  <% end %>

  <%= form_tag({:action => "update"}) do %>
    <%= hidden_field_tag "do", "clear_finished" %>
    <%= submit_tag t('.clear') %>
  <% end %>

  <%= form_tag({:action => "update"}) do %>
    <%= hidden_field_tag "do", "abort_all" %>
    <%= submit_tag t('.cancel') %>
  <% end %>

  <%= form_tag({:action => "update"}) do %>
    <%= hidden_field_tag "do", "pause" %>
    <%= submit_tag t('.pause') %>
  <% end %>

  <%= form_tag({:action => "update"}) do %>
    <%= hidden_field_tag "do", "unpause" %>
    <%= submit_tag t('.resume') %>
  <% end %>
</div>

<div id="paginator">
  <%= will_paginate(@items) %>
</div>

