Feat: Create a Service for Download Proof and make it reusable

This commit is contained in:
Sallu9007
2025-05-11 15:41:58 +05:30
parent c224497740
commit 6e634eda5a
4 changed files with 141 additions and 58 deletions

View 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>