This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
<?= $this->extend('layout/main_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
<?php
|
||||
$isEditable = (bool) ($isEditable ?? true);
|
||||
$disabledAttr = $isEditable ? '' : ' disabled';
|
||||
?>
|
||||
|
||||
<div class="container my-4">
|
||||
<h4 class="text-dark mb-3" style="font-family: Arial, sans-serif;">Distribute Books to Students</h4>
|
||||
<?= view('partials/flash_messages') ?>
|
||||
<?php if (!$isEditable): ?>
|
||||
<div class="alert alert-info">
|
||||
You are viewing <?= esc($schoolYear ?? 'a closed school year') ?>. Book distribution actions are read-only for closed years.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Filter bar (GET) — no class section shown -->
|
||||
<form id="filterForm" class="row g-3 mb-3" method="get" action="<?= site_url('inventory/books/distribute') ?>">
|
||||
@@ -43,7 +52,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Submission form (POST) -->
|
||||
<form method="post" action="<?= site_url('inventory/books/distribute') ?>">
|
||||
<form method="post" action="<?= site_url('inventory/books/distribute') ?>" data-readonly="<?= $isEditable ? '0' : '1' ?>">
|
||||
<?= csrf_field() ?>
|
||||
<!-- Keep class section hidden -->
|
||||
<input type="hidden" name="class_section_id" value="<?= esc($class_section_id) ?>">
|
||||
@@ -53,8 +62,8 @@
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span>Students</span>
|
||||
<div class="d-flex gap-2">
|
||||
<button type="button" class="btn btn-sm btn-info" id="checkAllBtn">Check All</button>
|
||||
<button type="button" class="btn btn-sm btn-secondary" id="uncheckAllBtn">Uncheck All</button>
|
||||
<button type="button" class="btn btn-sm btn-info" id="checkAllBtn"<?= $disabledAttr ?>>Check All</button>
|
||||
<button type="button" class="btn btn-sm btn-secondary" id="uncheckAllBtn"<?= $disabledAttr ?>>Uncheck All</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -87,7 +96,7 @@
|
||||
class="form-check-input student-box"
|
||||
name="student_ids[]"
|
||||
value="<?= esc($sid) ?>"
|
||||
<?= $given ? 'checked' : '' ?>>
|
||||
<?= $given ? 'checked' : '' ?><?= $disabledAttr ?>>
|
||||
</td>
|
||||
<td><?= esc($student['school_id'] ?? '-') ?></td>
|
||||
<td><?= esc($student['firstname'] ?? '') ?></td>
|
||||
@@ -111,11 +120,11 @@
|
||||
<div class="card-footer">
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Note (optional)</label>
|
||||
<textarea class="form-control" rows="2" name="note" placeholder="e.g., Distributed in class today"></textarea>
|
||||
<textarea class="form-control" rows="2" name="note" placeholder="e.g., Distributed in class today"<?= $disabledAttr ?>></textarea>
|
||||
</div>
|
||||
<div class="d-flex gap-2">
|
||||
<button type="button" class="btn btn-success">Deduct & Save</button>
|
||||
<button type="button" class="btn btn-secondary" id="clearSelectionBtn">Cancel</button>
|
||||
<button type="button" class="btn btn-success"<?= $disabledAttr ?>>Deduct & Save</button>
|
||||
<button type="button" class="btn btn-secondary" id="clearSelectionBtn"<?= $disabledAttr ?>>Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -129,15 +138,20 @@
|
||||
|
||||
<?= $this->section('scripts') ?>
|
||||
<script>
|
||||
const distributeForm = document.querySelector('form[data-readonly]');
|
||||
const distributeReadonly = distributeForm?.getAttribute('data-readonly') === '1';
|
||||
|
||||
// Auto-submit filter when book changes
|
||||
document.getElementById('bookSelect')?.addEventListener('change', () => {
|
||||
document.getElementById('filterForm').submit();
|
||||
});
|
||||
|
||||
document.getElementById('checkAllBtn')?.addEventListener('click', () => {
|
||||
if (distributeReadonly) return;
|
||||
document.querySelectorAll('.student-box').forEach(cb => cb.checked = true);
|
||||
});
|
||||
document.getElementById('uncheckAllBtn')?.addEventListener('click', () => {
|
||||
if (distributeReadonly) return;
|
||||
document.querySelectorAll('.student-box').forEach(cb => cb.checked = false);
|
||||
});
|
||||
</script>
|
||||
@@ -149,17 +163,20 @@
|
||||
});
|
||||
|
||||
document.getElementById('checkAllBtn')?.addEventListener('click', () => {
|
||||
if (distributeReadonly) return;
|
||||
document.querySelectorAll('.student-box').forEach(cb => cb.checked = true);
|
||||
});
|
||||
|
||||
document.getElementById('uncheckAllBtn')?.addEventListener('click', () => {
|
||||
if (distributeReadonly) return;
|
||||
document.querySelectorAll('.student-box').forEach(cb => cb.checked = false);
|
||||
});
|
||||
|
||||
// Cancel button clears all checkboxes
|
||||
document.getElementById('clearSelectionBtn')?.addEventListener('click', () => {
|
||||
if (distributeReadonly) return;
|
||||
document.querySelectorAll('.student-box').forEach(cb => cb.checked = false);
|
||||
});
|
||||
</script>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
Reference in New Issue
Block a user