@@ -305,6 +305,23 @@
|
||||
|
||||
const normalize = s => (s||'').toString().toLowerCase();
|
||||
const debounce = (fn, wait=200) => { let t; return (...args)=>{ clearTimeout(t); t=setTimeout(()=>fn(...args), wait); }; };
|
||||
const openFamilyResult = (type, id) => {
|
||||
const params = {};
|
||||
if (type === 'student') {
|
||||
params.student_id = id;
|
||||
} else if (type === 'guardian') {
|
||||
params.guardian_id = id;
|
||||
}
|
||||
if (Object.keys(params).length && typeof window.openFamilyCard === 'function') {
|
||||
window.openFamilyCard(params);
|
||||
return;
|
||||
}
|
||||
if (type === 'student') {
|
||||
window.location.href = '<?= site_url('family') ?>' + '?student_id=' + encodeURIComponent(id);
|
||||
} else if (type === 'guardian') {
|
||||
window.location.href = '<?= site_url('family') ?>' + '?guardian_id=' + encodeURIComponent(id);
|
||||
}
|
||||
};
|
||||
|
||||
// Preloaded datasets for suggestions (students + guardians)
|
||||
const STATIC_ITEMS = [
|
||||
@@ -368,12 +385,7 @@
|
||||
btn.className = 'list-group-item list-group-item-action';
|
||||
btn.innerHTML = `<div class="d-flex justify-content-between"><span>${(it.label||'').replace(/</g,'<')}</span><span class="text-muted small">${(it.sub||'').replace(/</g,'<')}</span></div>`;
|
||||
btn.addEventListener('click', () => {
|
||||
// Redirect to show only the selected family
|
||||
if (it.type === 'student') {
|
||||
window.location.href = '<?= site_url('family') ?>' + '?student_id=' + encodeURIComponent(it.id);
|
||||
} else if (it.type === 'guardian') {
|
||||
window.location.href = '<?= site_url('family') ?>' + '?guardian_id=' + encodeURIComponent(it.id);
|
||||
}
|
||||
openFamilyResult(it.type, it.id);
|
||||
});
|
||||
suggest.appendChild(btn);
|
||||
});
|
||||
@@ -455,7 +467,7 @@
|
||||
}
|
||||
if (best) {
|
||||
e.preventDefault();
|
||||
window.location.href = '<?= site_url('family') ?>' + '?student_id=' + encodeURIComponent(best.value);
|
||||
openFamilyResult('student', best.value);
|
||||
}
|
||||
});
|
||||
// Hide suggestions on outside click
|
||||
|
||||
Reference in New Issue
Block a user