Feat: Create a Service for Download Proof and make it reusable
This commit is contained in:
52
resources/views/components/download-proofs.blade.php
Normal file
52
resources/views/components/download-proofs.blade.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<div>
|
||||
<!-- Download Proofs Button -->
|
||||
<button id="download-proofs" class="btn btn-success" disabled>
|
||||
<i class="fas fa-download me-1"></i> Download Proofs
|
||||
</button>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const downloadProofsButton = document.getElementById('download-proofs');
|
||||
|
||||
downloadProofsButton.addEventListener('click', function () {
|
||||
const selectedIds = [];
|
||||
|
||||
// Collect selected row IDs
|
||||
document.querySelectorAll('.row-checkbox:checked').forEach(function (checkbox) {
|
||||
selectedIds.push(checkbox.value);
|
||||
});
|
||||
|
||||
if (selectedIds.length > 0) {
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = "{{ $route }}";
|
||||
|
||||
const csrfInput = document.createElement('input');
|
||||
csrfInput.type = 'hidden';
|
||||
csrfInput.name = '_token';
|
||||
csrfInput.value = "{{ csrf_token() }}";
|
||||
form.appendChild(csrfInput);
|
||||
|
||||
const idsInput = document.createElement('input');
|
||||
idsInput.type = 'hidden';
|
||||
idsInput.name = 'ids';
|
||||
idsInput.value = JSON.stringify(selectedIds);
|
||||
form.appendChild(idsInput);
|
||||
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
} else {
|
||||
alert('No rows selected');
|
||||
}
|
||||
});
|
||||
|
||||
// Enable/disable button based on row selection
|
||||
document.querySelectorAll('.row-checkbox').forEach(function (checkbox) {
|
||||
checkbox.addEventListener('change', function () {
|
||||
const selectedRows = document.querySelectorAll('.row-checkbox:checked').length;
|
||||
downloadProofsButton.disabled = selectedRows === 0;
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
Reference in New Issue
Block a user