<% page_title t('titles.schools'), @school.displayName, t('titles.groups'), @group.displayName %>

<div class="basicInfo">
  <div class="basicInfoDetails">
    <h1><%= h @group.displayName %></h1>
  </div>
</div>

<%= render partial: 'integration_warnings', locals: { school: @school, group: @group } %>

<% if !current_user.organisation_owner? && @num_hidden > 0 %>
<p class="genericWarning"><%= t('.hidden_members_hidden_tools_warning') %></p>
<% end %>

<%= start_box t('.title'), extraClass="noFloat fullWidth" %>
  <table>
    <tr>
      <th><%= t('activeldap.attributes.group.cn') %></th>
      <td><%= h @group.cn %></td>
    </tr>

    <tr>
      <th><%= t('activeldap.attributes.group.puavoEduGroupType') %></th>
      <td>
        <% if @group.puavoEduGroupType.nil? %>
          <span class="missingData"><%= t('missing_data') %></span>
        <% else %>
          <%= h humanize_group_type(@group.puavoEduGroupType) %>
        <% end %>
      </td>
    </tr>

    <tr>
      <th><%= t('activeldap.attributes.group.puavoExternalId') %></th>
      <td><%= @group['puavoExternalId'].nil? ? t('missing_data') : @group['puavoExternalId'] %> </td>
    </tr>

    <tr>
      <th style="width: 15em;"><%= t('activeldap.attributes.dn') %></th>
      <td><%= h @group.dn %></td>
    </tr>

    <tr>
      <th><%= t('activeldap.attributes.group.gidNumber') %></th>
      <td><%= h @group.gidNumber %></td>
    </tr>

    <tr>
      <th><%= t('activeldap.attributes.group.puavoNotes')  %></th>
      <td class="noWrap"><%= format_notes(@group.puavoNotes) %></td>
    </tr>

    <tr>
      <th><%= t('ldap_create_time') %></th>
      <td><%= @group['createTimestamp'] %></td>
    </tr>

    <tr>
      <th><%= t('ldap_modify_time') %></th>
      <td><%= @group['modifyTimestamp'] %></td>
    </tr>

    <% if @group.puavoExternalData %>
    <tr>
      <th><%= t('groups.show.external_data') %></th>
      <td><code><%= h @group.puavoExternalData %></code></td>
    </tr>
    <% end %>
  </table>
<%= end_box %>

<%= start_box t('.members'), extraClass="noFloat fullWidth" %>
  <div class="flex-rows gap-5px">
    <div class="flex-cols gap-5px flex-vbottom">
      <div>
        <p class="margin-0"><%= t('.description') %></p>
        <input type="search" id="groupMembersSearch" class="searchBox groupMembersSearch" size="50" placeholder="<%= t('.placeholder_for_search') %>" autocomplete="off">
      </div>

      <div class="haveDropdown">
        <span class="btn"><i class="icon-collapse"></i> <%= t('groups.members.actions') %></span>
        <div class="dropdown">
          <ul>
            <ul>
              <li>
                <%= link_to get_members_as_csv_path(@school, @group), method: :get do %>
                  <i class="icon-download"></i><%= t('link.get_members_as_csv') %>
                <% end %>
              </li>

              <li>
                <%= link_to create_username_list_from_group_path(@school, @group), data: { confirm: t('.group_username_list_confirm') }, method: :put do %>
                  <i class="icon-list"></i><%= t('link.create_username_list_from_group') %>
                <% end %>
              </li>
            </ul>

            <ul>
              <li>
                <%= link_to mark_group_members_for_deletion_path(@school, @group), data: { confirm: t('general_confirm') }, method: :put do %>
                  <i class="icon-flag"></i><%= t('link.mark_group_members_for_deletion') %>
                <% end %>
              </li>

              <li>
                <%= link_to unmark_group_members_deletion_path(@school, @group), data: { confirm: t('general_confirm') }, method: :put do %>
                  <i class="icon-flag-empty"></i><%= t('link.unmark_group_members_deletion') %>
                <% end %>
              </li>
            </ul>

            <ul>
              <li>
                <%= link_to lock_all_members_path(@school, @group), data: { confirm: t('general_confirm') }, method: :put do %>
                  <i class="icon-lock"></i><%= t('link.lock_all_group_members') %>
                <% end %>
              </li>

              <li>
                <%= link_to unlock_all_members_path(@school, @group), data: { confirm: t('general_confirm') }, method: :put do %>
                  <i class="icon-lock-open"></i><%= t('link.unlock_all_group_members') %>
                <% end %>
              </li>
            </ul>

            <ul>
              <li>
                <%= link_to remove_all_members_path(@school, @group), data: { confirm: t('general_confirm') }, method: :put do %>
                  <i class="icon-minus-squared"></i><%= t('link.remove_all_members_from_group') %>
                <% end %>
              </li>
            </ul>
          </ul>
        </div>    <!-- dropdown UL div -->
      </div>    <!-- haveDropdown div -->
    </div>    <!-- upper div -->

    <div id="groupMembers">
    <%= render :partial => "members" %>
    </div>
  </div>
<%= end_box %>

<% content_for :page_tools do %>
<%=
toolbar do |tb|
  tb.link t('link.edit'),
          href: edit_group_path(@school, @group),
          icon: 'pencil'

  tb.dropdown t('link.more'), right: true do |menu|
    if @permit_group_creation
      menu.link t('link.new_group'),
                href: new_group_path(@school),
                icon: 'plus'
    end

    menu.separator

    if @permit_school_change
      menu.link t('link.change_school'),
                href: select_new_school_path(@school, @group),
                icon: 'exchange'
    end

    menu.separator

    if @permit_group_deletion && @num_hidden == 0
      menu.link t('link.delete_group'),
                href: group_path(@school, @group),
                confirm: t('general_confirm'),
                method: 'delete',
                icon: 'trash'
    end
  end
end %>
<% end %>

<hr>

<script>
document.addEventListener("DOMContentLoaded", function() {
    // Setup group members searching
    $(".groupMembersSearch").liveSearch({
        id: "membersSearchResults",                   // unique ID for the results box
        url: "<%= @group.id %>/user_search?words=",   // search URL
        field: "groupMembersSearch",                  // search term source
        typeDelay: 400,
        minLength: 2,
        width: "auto"
    });
});
</script>
