/** * @fileoverview Manages the rooms list view functionality. * This file handles: * - Room list search with debounced input * - Room filter form submission * - Clear filter functionality for the rooms list */ /** * 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. * This helps prevent excessive form submissions during rapid user input. * @function * @param {Function} func - The function to debounce * @param {number} wait - The number of milliseconds to delay (300ms default for search) * @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 the rooms list functionality when the DOM is loaded. * Sets up event listeners for: * - Search input with debounced form submission (300ms delay) * - Clear filter button to reset search and refresh results * @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(); }); } });