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

<% 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 %>
<% @is_servers = false %>

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

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

<% 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 DEFAULT_COLUMNS = ["school", "hw_time", "hn", "type", "tags", "mac", "current_image", "ram", "hd", "cpu"];
const DEFAULT_SORTING = { column: "hw_time", dir: ST.SortOrder.DESCENDING };

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

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

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