<% page_title t('titles.organisation'), t('titles.external_files') %>

<h1><%= t('external_files.title') %></h1>

<p><%= t('external_files.description') %></p>

<div class="external-files">

<%= form_tag({:action => :upload}, :multipart => true) do %>

<table class="list externalFiles">
  <tr class="thead">
    <th><%= t('external_files.columns.name') %></th>
    <th><%= t('external_files.columns.description') %></th>
    <th><%= t('external_files.columns.size') %></th>
    <th><%= t('external_files.columns.checksum') %></th>
    <th colspan="2"><%= t('external_files.columns.actions') %></th>
  </tr>

<% @external_files.each do |file| %>
  <tr>
    <td data-title="<%= t('external_files.columns.name') %>">
      <span data-title="File name" class="filename"><%= file["meta"]["name"] %></span>
    </td>

    <td data-title="<%= t('external_files.columns.description') %>">
    <% if file["meta"]["description"] %>
    <%= file["meta"]["description"] %>
    <% end %>
    </td>

    <td data-title="<%= t('external_files.columns.size') %>">
    <% if file["model"] %>
      <%= file["model"].puavoData.size %>
    <% else %>
      <%= t('external_files.no_file') %>
    <% end %>
    </td>

    <td data-title="<%= t('external_files.columns.checksum') %>">
    <% if file["model"] %>
      <%= file["model"].puavoDataHash %>
    <% else %>
      <%= t('external_files.no_file') %>
    <% end %>
    </td>

    <td data-title="<%= t('actions') %>" class="tableActions">
    <%= file_field_tag "file[#{ file["meta"]["name"] }", :value => "Add or change" %>
    <% if file["model"] %>
    <td>
    <span class="tableActions">
      <%= link_to(
            download_external_file_path(file["meta"]["name"]), :class => 'btn'
          ) do
      %>
      <i class="icon-download"></i> <%= t('external_files.buttons.download') %>
      <% end %>
      </span>
      <span class="tableActions">
      <%= link_to(
            destroy_external_file_path(file["meta"]["name"]),
            method: :delete, data: { confirm: t('general_confirm') }, :class => 'btn btn-danger'
          ) do
      %>
      <i class="icon-trash"></i><%= t('external_files.buttons.delete') %>
      <% end %>
      </span>
    <% else %>
      <td></td>
    <% end %>
    </tr>
  <% end %>
</table>

<div style="clear: both;"></div>
<br>

<table class="editForm">
  <tr class="buttonRow">
    <td>
      <%= submit_tag(t('external_files.buttons.master_save'), class: 'btn') %>
    </td>
  </tr>
</table>

<% end %>

</div>
