Files
docupulse/static/js/rooms.js
2025-05-28 16:01:18 +02:00

48 lines
1.5 KiB
JavaScript

/**
* @fileoverview Manages room search and filtering functionality.
* This file handles:
* - Room search input with debounced submission
* - Clear filter functionality
* - Form submission for room filtering
*/
/**
* Creates a debounced version of a function that delays its execution
* until after a specified wait time has elapsed since the last time it was invoked.
* @function
* @param {Function} func - The function to debounce
* @param {number} wait - The number of milliseconds to delay
* @returns {Function} A debounced version of the provided function
*/
function debounce(func, wait) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), wait);
};
}
/**
* Initializes room search and filtering functionality when the DOM is loaded.
* Sets up event listeners for:
* - Search input with debounced form submission
* - Clear filter button
* @function
*/
document.addEventListener('DOMContentLoaded', function() {
const searchInput = document.getElementById('roomSearchInput');
const form = document.getElementById('roomFilterForm');
if (searchInput && form) {
searchInput.addEventListener('input', debounce(function() {
form.submit();
}, 300));
}
// Clear button logic
const clearBtn = document.getElementById('clearRoomsFilter');
if (clearBtn && searchInput) {
clearBtn.addEventListener('click', function() {
searchInput.value = '';
form.submit();
});
}
});