cloudlog/application/views/lotw_views/index.php
Peter Goodhall 88e95b0db9 Add HTMX modal upload and cert table refresh
Enable HTMX-driven certificate uploads and partial UI updates for LoTW. Updated Lotw controller to detect HTMX requests in do_cert_upload, return inline success/error alerts for modal uploads, and added cert_table_refresh endpoint to return the cert table partial. Extracted the certificate table into a new view (lotw_views/cert_table.php) and replaced the inline table in index.php with a container that loads that partial. Added a Bootstrap modal view (upload_cert_modal.php) with an HTMX multipart form, drag-and-drop file UI, JS handlers to manage upload state and refresh the certificate list, and modal reset behavior. Minor refactors to flash/success handling to support both full-page and HTMX flows.
2026-02-18 15:51:19 +00:00

63 lines
2.3 KiB
PHP

<div class="container lotw">
<br>
<a class="btn btn-outline-primary btn-sm float-end" href="<?php echo site_url('/lotw/import'); ?>" role="button"><i class="fas fa-cloud-download-alt"></i> <?php echo lang('lotw_btn_lotw_import'); ?></a>
<h2><?php echo lang('lotw_title'); ?></h2>
<!-- Card Starts -->
<div class="card">
<div class="card-header">
<button class="btn btn-outline-success btn-sm float-end" data-bs-toggle="modal" data-bs-target="#uploadCertModal" role="button"><i class="fas fa-cloud-upload-alt"></i> <?php echo lang('lotw_btn_upload_certificate'); ?></button><i class="fab fa-expeditedssl"></i> <?php echo lang('lotw_title_available_cert'); ?>
</div>
<div class="lotw-cert-list" id="lotw-cert-list">
<?php $this->load->view('lotw_views/cert_table', array('lotw_cert_results' => $lotw_cert_results)); ?>
</div>
</div>
<!-- Card Ends -->
<br>
<!-- Information Card - Only show if certificates exist -->
<?php if ($lotw_cert_results->num_rows() > 0) { ?>
<div class="card">
<div class="card-header">
<?php echo lang('lotw_title_information'); ?>
</div>
<div class="card-body">
<button id="manual-sync-btn" class="btn btn-outline-success"
hx-get="<?php echo site_url('lotw/lotw_upload'); ?>"
hx-target="#lotw_manual_results"
hx-indicator="#sync-spinner">
<span id="sync-spinner" class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true" style="display: none;"></span>
<?php echo lang('lotw_btn_manual_sync'); ?>
</button>
<div id="lotw_manual_results"></div>
</div>
</div>
<?php } ?>
</div>
<!-- Load Certificate Upload Modal -->
<?php $this->load->view('lotw_views/upload_cert_modal'); ?>
<script>
document.addEventListener('DOMContentLoaded', function() {
const syncBtn = document.getElementById('manual-sync-btn');
const spinner = document.getElementById('sync-spinner');
// Show spinner when htmx request starts
syncBtn.addEventListener('htmx:beforeRequest', function() {
spinner.style.display = 'inline-block';
syncBtn.disabled = true;
});
// Hide spinner when htmx request completes (success or error)
syncBtn.addEventListener('htmx:afterRequest', function() {
spinner.style.display = 'none';
syncBtn.disabled = false;
});
});
</script>