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

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

<table class="list" id="ldap">
  <tr class="thead">
    <th><%= sortable_list_column_header(t('activeldap.attributes.ldap_service.uid')) %></th>
    <th><%= sortable_list_column_header(t('activeldap.attributes.ldap_service.description')) %></th>
    <th><%= sortable_list_column_header(t('activeldap.attributes.ldap_service.dn')) %></th>
    <th><%= t('activeldap.attributes.ldap_service.groups') %></th>
    <th><%= t('.actions') %></th>
  </tr>

<% @ldap_services.each do |ldap_service| %>
  <tr>
    <td data-title="<%= t('activeldap.attributes.ldap_service.uid') %>"><%= link_to ldap_service.uid, ldap_service_path(ldap_service) %></td>
    <td data-title="<%= t('activeldap.attributes.ldap_service.description') %>"><%= h ldap_service.description %></td>
    <td data-title="<%= t('activeldap.attributes.ldap_service.dn') %>"><%= ldap_service.dn %></td>
    <td data-title="<%= t('activeldap.attributes.ldap_service.groups') %>">
      <ul>
      <% @system_groups.each do |g| %>
        <% if ldap_service.groups.include?(g) %>
        <li><%= g.description %></li>
        <% end %>
      <% end %>
      </ul>
    </td>
    <td data-title="<%= t('.actions') %>" class="tableActions">
      <%= link_to edit_ldap_service_path(ldap_service), class: "btn" do%>
       <i class="icon-pencil"></i> <%=t('link.edit')%>
      <% end %>

      <%= link_to( ldap_service_path(ldap_service),
                    data: { confirm: t('destroy_confirm', object_name: ldap_service.uid) },
                    method: :delete, class: 'btn btn-danger' ) do %>
        <i class="icon-trash"></i> <%=t('link.destroy')%>
      <% end %>
    </td>
  </tr>
<% end %>
</table>

<% content_for :page_tools do %>
<%=
toolbar do |tb|
  tb.link t('link.new_ldap_service'),
          href: new_ldap_service_path,
          icon: 'plus'
end %>
<% end %>

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

<script>
document.addEventListener("DOMContentLoaded", function() {
    new SortableTable(
        "ldap",
        [
            [ COLUMN_TYPE_STRING, COLUMN_FLAG_HTML ],   // name
            [ COLUMN_TYPE_STRING ],                     // description
            [ COLUMN_TYPE_STRING ],                     // bind DN
            [ COLUMN_TYPE_STRING, COLUMN_FLAG_HTML | COLUMN_FLAG_DONT_SORT ],    // system groups
            [ COLUMN_TYPE_STRING, COLUMN_FLAG_HTML | COLUMN_FLAG_DONT_SORT ],    // actions
        ],
        "fi",
        "<%= "#{LdapOrganisation.current.o}-ldap" %>"
    );
});
</script>
