<% 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 %>

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

<% @is_organisation = true %>
<% @is_servers = true %>

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

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

const SERVERS = <%= raw JSON.pretty_generate(@servers) %>;

const DEFAULT_COLUMNS = ["hn", "schools", "available_images", "location", "mac", "mfer", "model", "serial", "current_image"];
const DEFAULT_SORTING = { column: "hn", dir: ST.SortOrder.ASCENDING };

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

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

        // Settings
        {
            id: "servers",
            locale: "<%= supertable_sorting_locale %>",
            csvPrefix: `<%= LdapOrganisation.current.o %>-servers`,
            columnDefinitions: COLUMN_DEFINITIONS,
            columnOrder: COLUMN_ORDER,
            actions: userActions,
            openCallback: openCallbackServers,
            massSelects: MASS_SELECTS,
            massOperations: MASS_OPERATIONS,
            massOperationsEndpoint: "<%= servers_mass_operations_path %>",
            defaultColumns: DEFAULT_COLUMNS,
            defaultSorting: DEFAULT_SORTING,
            filterPresets: null,
            staticData: SERVERS,
        }
    );
});
</script>
<% end %>
