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

<% content_for :javascript do %>
<script>
const SUPERTABLE_WORKER_FILE = "<%= javascript_path 'supertable3_worker' %>";
let GLOBAL_SUPERTABLE_INSTANCE = null;
</script>

<%= javascript_include_tag 'javascripts/modal_popup' %>
<%= javascript_include_tag 'javascripts/supertable3' %>
<% end %>

<% @is_organisation = true %>

<h1><%= t('titles.all_users') %></h1>

<% unless @synchronised_deletions_by_school.empty? %>

<div class="genericWarning">
<%= t('organisations.all_users.sync_deletion_1').html_safe %>

<ul>
<% @synchronised_deletions_by_school.collect { |key, value| [key, value] }.sort { |a, b| a[0] <=> b[0] }.each do |school_name, systems| %>
  <li><%= school_name %>: <%= systems.join(', ') %></li>
<% end %>
</ul>

<%= t('organisations.all_users.sync_deletion_2') %>
</div>

<% end %>

<%= render 'shared/supertable_controls' %>
<div class="superTable" id="tableUsers"></div>

<% content_for :post_load_javascript do %>
<script>
"use strict;"

<%= render partial: 'shared/supertable_translations', formats: [:js] %>
<%= render partial: 'shared/user_tables_common', formats: [:js] %>

const DEFAULT_COLUMNS = ["school", "uid", "name", "role", "eid", "locked", "dnd", "rrt", "mfa"];
const DEFAULT_SORTING = { column: "name", dir: ST.SortOrder.ASCENDING };

document.addEventListener("DOMContentLoaded", () => {
    modalPopup.setupGlobalEvents();

    GLOBAL_SUPERTABLE_INSTANCE = new ST.SuperTable(
        // Main container DIV
        document.getElementById("tableUsers"),

        // Settings
        {
            id: "orgUsers",
            locale: "<%= supertable_sorting_locale %>",
            csvPrefix: `<%= LdapOrganisation.current.o %>-users`,
            columnDefinitions: COLUMN_DEFINITIONS,
            columnOrder: COLUMN_ORDER,
            actions: userActions,
            openCallback: openCallback,
            massSelects: MASS_SELECTS,
            massOperations: MASS_OPERATIONS,
            massOperationsEndpoint: "<%= users_mass_operations_path %>",
            defaultColumns: DEFAULT_COLUMNS,
            defaultSorting: DEFAULT_SORTING,
            filterPresets: FILTER_PRESETS,
            dynamicData: "/get_all_users",
            defaultRowsPerPage: -1,     // show all users by default
            preFilterFunction: expandUserData,
        }
    );
});
</script>
<% end %>
