templates/export/_export-history-modal.html.twig line 1

Open in your IDE?
  1. {% block export_history_html %}
  2. <!-- Export History Modal -->
  3. <div class="modal fade" id="exportHistoryModal" tabindex="-1" aria-labelledby="exportHistoryModalLabel" aria-hidden="true">
  4.     <div class="modal-dialog modal-dialog-centered modal-xl">
  5.         <div class="modal-content">
  6.             <div class="modal-header">
  7.                 <h5 class="modal-title" id="exportHistoryModalLabel">
  8.                     <i data-lucide="clock" style="width: 18px; height: 18px;" class="me-2"></i>
  9.                     Export History
  10.                 </h5>
  11.                 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  12.             </div>
  13.             <div class="modal-body p-0" id="exportHistoryContent">
  14.                 <div class="text-center py-5">
  15.                     <div class="spinner-border text-primary" role="status">
  16.                         <span class="visually-hidden">Loading...</span>
  17.                     </div>
  18.                 </div>
  19.             </div>
  20.             <div class="modal-footer">
  21.                 <button type="button" id="deleteExportsBtn" class="btn btn-outline-danger btn-sm me-auto" disabled>
  22.                     <i data-lucide="trash-2" style="width: 14px; height: 14px;" class="me-1"></i>
  23.                     Delete
  24.                 </button>
  25.                 <button type="button" class="btn btn-outline-secondary btn-sm" data-bs-dismiss="modal">Close</button>
  26.             </div>
  27.         </div>
  28.     </div>
  29. </div>
  30. {% endblock %}
  31. {% block export_history_js %}
  32. <script>
  33.     $(document).ready(function() {
  34.         var $exportHistoryModal = $('#exportHistoryModal');
  35.         var $exportHistoryContent = $('#exportHistoryContent');
  36.         var currentPage = 1;
  37.         var isLoading = false;
  38.         // Load export history when modal opens
  39.         // Remove any existing handlers first to prevent duplicate requests
  40.         $exportHistoryModal.off('show.bs.modal').on('show.bs.modal', function() {
  41.             if (!isLoading) {
  42.                 loadExportHistory(1);
  43.             }
  44.         });
  45.         // Use event delegation for pagination links (since content is replaced via AJAX)
  46.         $exportHistoryContent.on('click', '.export-history-page-link', function(e) {
  47.             e.preventDefault();
  48.             var page = $(this).data('page');
  49.             if (page && !isLoading) {
  50.                 loadExportHistory(page);
  51.             }
  52.         });
  53.         // Select all checkbox handler
  54.         $(document).on('change', '#selectAllExports', function() {
  55.             var isChecked = $(this).is(':checked');
  56.             $('.export-checkbox').prop('checked', isChecked);
  57.             updateDeleteButton();
  58.         });
  59.         // Individual checkbox handler
  60.         $(document).on('change', '.export-checkbox', function() {
  61.             updateSelectAllCheckbox();
  62.             updateDeleteButton();
  63.         });
  64.         // Delete button handler
  65.         $('#deleteExportsBtn').on('click', function() {
  66.             var selectedTokens = $('.export-checkbox:checked').map(function() {
  67.                 return $(this).data('token');
  68.             }).get();
  69.             if (selectedTokens.length === 0) {
  70.                 return;
  71.             }
  72.             var count = selectedTokens.length;
  73.             var message = count === 1
  74.                 ? 'You are about to delete 1 export.'
  75.                 : 'You are about to delete ' + count + ' exports.';
  76.             if (typeof Swal !== 'undefined') {
  77.                 Swal.fire({
  78.                     title: 'Delete Exports?',
  79.                     text: message,
  80.                     icon: 'warning',
  81.                     showCancelButton: true,
  82.                     confirmButtonColor: '#dc3545',
  83.                     confirmButtonText: 'Yes, delete',
  84.                     cancelButtonText: 'Cancel'
  85.                 }).then(function(result) {
  86.                     if (result.isConfirmed) {
  87.                         deleteExports(selectedTokens);
  88.                     }
  89.                 });
  90.             } else if (confirm(message)) {
  91.                 deleteExports(selectedTokens);
  92.             }
  93.         });
  94.         function updateSelectAllCheckbox() {
  95.             var totalCheckboxes = $('.export-checkbox').length;
  96.             var checkedCheckboxes = $('.export-checkbox:checked').length;
  97.             $('#selectAllExports').prop('checked', totalCheckboxes > 0 && totalCheckboxes === checkedCheckboxes);
  98.         }
  99.         function updateDeleteButton() {
  100.             var checkedCount = $('.export-checkbox:checked').length;
  101.             $('#deleteExportsBtn').prop('disabled', checkedCount === 0);
  102.         }
  103.         function deleteExports(tokens) {
  104.             $('#deleteExportsBtn').prop('disabled', true).html('<span class="spinner-border spinner-border-sm me-1"></span>Deleting...');
  105.             $.ajax({
  106.                 url: '/exports/delete',
  107.                 method: 'DELETE',
  108.                 contentType: 'application/json',
  109.                 data: JSON.stringify({ tokens: tokens }),
  110.                 success: function() {
  111.                     loadExportHistory(currentPage);
  112.                     $('#deleteExportsBtn').prop('disabled', true).html('<i data-lucide="trash-2" style="width: 14px; height: 14px;" class="me-1"></i>Delete');
  113.                     if (typeof lucide !== 'undefined') {
  114.                         lucide.createIcons();
  115.                     }
  116.                 },
  117.                 error: function(xhr, status, error) {
  118.                     console.error('Error deleting exports:', error);
  119.                     alert('Failed to delete exports. Please try again.');
  120.                     $('#deleteExportsBtn').prop('disabled', false).html('<i data-lucide="trash-2" style="width: 14px; height: 14px;" class="me-1"></i>Delete');
  121.                     if (typeof lucide !== 'undefined') {
  122.                         lucide.createIcons();
  123.                     }
  124.                 }
  125.             });
  126.         }
  127.         function loadExportHistory(page) {
  128.             // Prevent duplicate requests
  129.             if (isLoading) {
  130.                 return;
  131.             }
  132.             
  133.             isLoading = true;
  134.             currentPage = page;
  135.             
  136.             // Show loading
  137.             $exportHistoryContent.html('<div class="text-center py-5"><div class="spinner-border text-primary" role="status"><span class="visually-hidden">Loading...</span></div></div>');
  138.             // Build URL with page, limit, and type as query parameter
  139.             // Route: /exports/list/{page?1}/{limit?20}
  140.             var url = '/exports/list/' + page + '/10?type=applications';
  141.             
  142.             $.ajax({
  143.                 url: url,
  144.                 method: 'GET',
  145.                 success: function(html) {
  146.                     $exportHistoryContent.html(html);
  147.                     
  148.                     // Re-initialize Lucide icons and tooltips
  149.                     if (typeof lucide !== 'undefined') {
  150.                         lucide.createIcons();
  151.                     }
  152.                     $('[data-bs-toggle="tooltip"]').each(function() {
  153.                         new bootstrap.Tooltip(this);
  154.                     });
  155.                     // Reset checkboxes and delete button state
  156.                     $('#selectAllExports').prop('checked', false);
  157.                     updateDeleteButton();
  158.                     isLoading = false;
  159.                 },
  160.                 error: function(xhr, status, error) {
  161.                     console.error('Error loading export history:', error);
  162.                     $exportHistoryContent.html('<div class="text-center py-5 text-danger"><i data-lucide="alert-circle" class="mb-2" style="width: 32px; height: 32px;"></i><p class="mb-0">Failed to load export history</p></div>');
  163.                     if (typeof lucide !== 'undefined') {
  164.                         lucide.createIcons();
  165.                     }
  166.                     isLoading = false;
  167.                 }
  168.             });
  169.         }
  170.     });
  171. </script>
  172. {% endblock %}