/* global I18n animateSpinner HelperModule DataTableHelpers DataTableCheckboxes notTurbolinksPreview */ /* eslint-disable no-param-reassign */ (function() { 'use strict'; var REPOSITORIES_TABLE; var CHECKBOX_SELECTOR; function updateActionButtons() { if (window.actionToolbarComponent) { window.actionToolbarComponent.fetchActions({ repository_ids: CHECKBOX_SELECTOR.selectedRows }); $('.dataTables_scrollBody').css('padding-bottom', `${CHECKBOX_SELECTOR.selectedRows.length > 0 ? 68 : 0}px`); } var rowsCount = CHECKBOX_SELECTOR.selectedRows.length; var row; $('#renameRepoBtn').attr('href', '#'); $('#deleteRepoBtn').attr('href', '#'); $('#copyRepoBtn').attr('href', '#'); switch (rowsCount) { case 0: $('.main-actions [data-action-mode="single"]').addClass('disabled hidden'); $('.main-actions [data-action-mode="multiple"]').addClass('disabled hidden'); break; case 1: row = $('#repositoriesList').find('tr#' + CHECKBOX_SELECTOR.selectedRows[0]); $('.main-actions [data-action-mode="single"]').removeClass('disabled hidden'); $('.main-actions [data-action-mode="multiple"]').removeClass('disabled hidden'); $('#renameRepoBtn').attr('href', row.data('rename-modal-url')); $('#deleteRepoBtn').attr('href', row.data('delete-modal-url')); $('#copyRepoBtn').attr('href', row.data('copy-modal-url')); break; default: $('.main-actions [data-action-mode="single"]').removeClass('hidden').addClass('disabled'); $('.main-actions [data-action-mode="multiple"]').removeClass('disabled hidden'); } } function initRepositoriesDataTable(tableContainer, archived = false) { var tableTemplate = $('#RepositoriesListTable').html(); $.get($(tableTemplate).data('source'), { archived: archived }, function(data) { if (REPOSITORIES_TABLE) REPOSITORIES_TABLE.destroy(); CHECKBOX_SELECTOR = null; $('.content-body').html(tableTemplate); REPOSITORIES_TABLE = $(tableContainer).DataTable({ aaData: data, dom: "R<'main-actions hidden'<'toolbar'><'filter-container'f>>t<'pagination-row hidden'<'pagination-info'li><'pagination-actions'p>>", processing: true, stateSave: true, pageLength: 25, colReorder: { enable: false }, sScrollX: '100%', sScrollXInner: '100%', order: [[1, 'asc']], destroy: true, language: { emptyTable: archived ? I18n.t('repositories.index.no_archived_inventories') : I18n.t('repositories.index.no_inventories'), zeroRecords: archived ? I18n.t('repositories.index.no_archived_inventories_matched') : I18n.t('repositories.index.no_inventories_matched') }, columnDefs: [{ targets: 0, visible: !$('.repositories-index').data('readonly'), searchable: false, orderable: false, render: function() { return `