<% if @company_sizes.blank? %>
  <div class="alert alert-info alert-dismissible">
    <h5><i class="icon fas fa-info"></i> Informacja</h5>
      Brak elementów na liście
  </div>
<% else %>

<table class="table table-bordered">
  <thead>
    <tr>
      <th>Nazwa</th>
      <th>Opis</th>
      <th>Priorytet</th>
      <th style="width: 200px">Akcje</th>
    </tr>
  </thead>

  <tbody id="sortable_list">
    <% @company_sizes.each do |company_size| %>
      <tr id="sort_<%= company_size.id %>">
        <td><%= company_size.name %></td>
        <td><%= company_size.description %></td>
        <td><%= company_size.prio %></td>
        <td>
          <%= link_to raw('<i class="fas fa-edit"></i> Edycja'), edit_company_size_path(company_size), class: 'btn-sm btn-info' %>
          <%= link_to raw('<i class="fas fa-trash-can"></i> Usuń'), company_size, class: 'btn-sm btn-danger', method: :delete, data: { confirm: 'Czy na pewno?' } %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>
<% content_for :foot_scripts do %>
$( function() {
  $( "#sortable_list" ).sortable({
    update: function( event, ui ) {
      var str = "";
      $('#sortable_list > tr').each(function(index, tr) {
        str += tr.id + ",";
      });
      $.post( "/company_sizes/chg_prio", { authenticity_token: $('meta[name="csrf-token"]').attr("content"), ord: str }, function( data ) {
        window.location.reload(true);
      });
    }
  });
  $( "tbody" ).disableSelection();
} );
<% end %>
<% end %>
