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