function buildQuery() { const params = []; const fields = [ { key: 'action', id: 'f_action' }, { key: 'username', id: 'f_username' }, { key: 'ip_address', id: 'f_ip_address' }, { key: 'entity_type', id: 'f_entity_type' }, { key: 'details', id: 'f_details' }, { key: 'date_from', id: 'f_date_from' }, { key: 'date_to', id: 'f_date_to' }, ]; fields.forEach(function (f) { const el = document.getElementById(f.id); if (el && el.value) { params.push(encodeURIComponent(f.key) + '=' + encodeURIComponent(el.value)); } }); return params.length ? '/admin/audit?' + params.join('&') : '/admin/audit'; } document.addEventListener('change', function (e) { if (e.target.matches('#f_date_from, #f_date_to, #f_action, #f_entity_type')) { window.location.href = buildQuery(); } }); document.addEventListener('keydown', function (e) { if (e.key === 'Enter' && e.target.matches('#f_username, #f_details, #f_ip_address')) { window.location.href = buildQuery(); } }); function clearFilters() { window.location.href = '/admin/audit'; } function clearField(id) { document.getElementById(id).value = ''; window.location.href = buildQuery(); }