<% page_title t('titles.schools'), @school.displayName, t('titles.devices'), t('titles.printer_permissions') %>

<% unless @printers.empty? %>
<table class="list" id="printers">
  <tr class="thead">
    <th><%= sortable_list_column_header(t('activeldap.attributes.printer.printerDescription')) %></th>
    <th><%= sortable_list_column_header(t('activeldap.attributes.printer.printerInfo')) %></th>
    <th><%= sortable_list_column_header(t('activeldap.attributes.printer.printerMakeAndModel')) %></th>
    <th><%= sortable_list_column_header(t('activeldap.attributes.printer.printerLocation')) %></th>
    <th><%= sortable_list_column_header(t('printer_permissions.index.bootserver')) %></th>
    <th><%= t('actions') %></th>
  </tr>

  <% @printers.each do |printer| %>
  <tr>
    <td data-title="<%= t('activeldap.attributes.printer.printerDescription')%>"><%= h printer.printerDescription %></td>
    <td data-title="<%= t('activeldap.attributes.printer.printerInfo')%>"><%= h printer.printerInfo %></td>
    <td data-title="<%= t('activeldap.attributes.printer.printerMakeAndModel')%>"><%= h printer.printerMakeAndModel %></td>
    <td data-title="<%= t('activeldap.attributes.printer.printerLocation')%>"><%= h printer.printerLocation %></td>
    <td data-title="<%= t('printer_permissions.index.bootserver')%>">
    <% if current_user.organisation_owner? %>
      <%= link_to printer.server.puavoHostname, edit_server_path(printer.server) %>
    <% else %>
      <%= h printer.server.puavoHostname %>
    <% end %>
    </td>
    <td data-title="<%= t('actions') %>" class="tableActions">
      <%= link_to edit_printer_permission_path(@school, printer), :class => 'btn' do %>
        <i class="icon-pencil"></i><%= t('.edit_permissions') %>
      <% end %>
    </td>
  </tr>
  <% end %>
</table>

<% content_for :javascript do %>
<%= javascript_include_tag 'sortable_table', skip_pipeline: true %>
<% end %>

<script>
document.addEventListener("DOMContentLoaded", function() {
    new SortableTable(
        "printers",
        [
            [ COLUMN_TYPE_STRING ],                     // description (name)
            [ COLUMN_TYPE_STRING ],                     // printer info
            [ COLUMN_TYPE_STRING ],                     // make and model
            [ COLUMN_TYPE_STRING ],                     // location
            [ COLUMN_TYPE_STRING, COLUMN_FLAG_HTML ],   // boot server
            [ COLUMN_TYPE_STRING, COLUMN_FLAG_HTML | COLUMN_FLAG_DONT_SORT ],    // actions
        ],
        "fi",
        "<%= "#{@school.id.to_s}-printerpermissions" %>"
    );
});
</script>

<% end %>

<% if @printers.empty? %>
<% if current_user.organisation_owner? %>
<p class="ownersOnly"><%= t("printer_permissions.no_printers_html", :href => link_to(t("printer_permissions.bootserver_ref"), servers_path)) %></p>
<% else %>
<p class="genericNotice"><%= t("printer_permissions.no_printers_nonowner") %></p>
<% end %>
<% end %>
