<% if @projects.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">
    <% @projects.each do |project| %>
      <tr id="sort_<%= project.id %>">
        <td><%= project.name %></td>
        <td><%= project.description %></td>
        <td><%= project.prio %></td>
        <td>
          <%= link_to raw('<i class="fas fa-edit"></i> Edycja'), edit_project_path(project), class: 'btn-sm btn-info' %>
          <%= link_to raw('<i class="fas fa-trash-can"></i> Usuń'), project, 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( "/projects/chg_prio", { authenticity_token: $('meta[name="csrf-token"]').attr("content"), ord: str }, function( data ) {
        window.location.reload(true);
      });
    }
  });
  $( "tbody" ).disableSelection();
} );
<% end %>
<% end %>
