fix: verificare, ma dovrebbe essere corretta la lattura da ldap
This commit is contained in:
@@ -455,11 +455,16 @@ const TicketDetailView = {
|
||||
customerSearchInput.addEventListener('input', () => {
|
||||
clearTimeout(customerDebounce);
|
||||
const q = customerSearchInput.value.trim();
|
||||
// Do not block empty query to allow all results on focus
|
||||
|
||||
customerDebounce = setTimeout(async () => {
|
||||
try {
|
||||
const users = await App.api(`/api/customer-users/search?q=${encodeURIComponent(q)}`);
|
||||
console.log('[Frontend LDAP Search Detail] Users returned:', users);
|
||||
// Prevent race conditions: discard results if the input value has changed
|
||||
if (customerSearchInput.value.trim() !== q) {
|
||||
console.log('[Frontend LDAP Search Detail] Discarding stale results for query:', q);
|
||||
return;
|
||||
}
|
||||
if (users.length === 0) {
|
||||
customerSuggestionsDiv.innerHTML = '<div class="autocomplete-suggestion-item" style="color:var(--text-muted); cursor:default;">Nessun utente trovato</div>';
|
||||
customerSuggestionsDiv.style.display = 'block';
|
||||
@@ -467,17 +472,18 @@ const TicketDetailView = {
|
||||
}
|
||||
|
||||
customerSuggestionsDiv.innerHTML = users.map(u => `
|
||||
<div class="autocomplete-suggestion-item" data-login="${App.escapeHtml(u.login)}" data-customer-id="${App.escapeHtml(u.customer_id || '')}" data-name="${App.escapeHtml(u.first_name + ' ' + u.last_name)}">
|
||||
<div class="autocomplete-suggestion-item" data-login="${App.escapeHtml(u.login || '')}" data-customer-id="${App.escapeHtml(u.customer_id || '')}" data-name="${App.escapeHtml((u.first_name + ' ' + u.last_name).trim() || u.login || '')}">
|
||||
<strong>${App.escapeHtml(u.first_name)} ${App.escapeHtml(u.last_name)}</strong>
|
||||
<span style="font-size:0.75rem; color:var(--text-muted); margin-left:var(--space-xs); font-weight:normal;">(Login: ${App.escapeHtml(u.login)} | Azienda: ${App.escapeHtml(u.customer_id || '—')})</span>
|
||||
<span style="font-size:0.75rem; color:var(--text-muted); margin-left:var(--space-xs); font-weight:normal;">(Login: ${App.escapeHtml(u.login || '')} | Azienda: ${App.escapeHtml(u.customer_id || '—')})</span>
|
||||
</div>
|
||||
`).join('');
|
||||
customerSuggestionsDiv.style.display = 'block';
|
||||
|
||||
// Bind click
|
||||
// Use mousedown instead of click to fire before blur event
|
||||
customerSuggestionsDiv.querySelectorAll('.autocomplete-suggestion-item').forEach(item => {
|
||||
if (item.dataset.login) {
|
||||
item.addEventListener('click', () => {
|
||||
item.addEventListener('mousedown', (e) => {
|
||||
e.preventDefault(); // prevent input from losing focus before value is set
|
||||
customerSearchInput.value = item.dataset.name;
|
||||
customerUserIdInput.value = item.dataset.login;
|
||||
customerIdInput.value = item.dataset.customerId || '';
|
||||
@@ -493,22 +499,15 @@ const TicketDetailView = {
|
||||
}, 300);
|
||||
});
|
||||
customerSearchInput.addEventListener('focus', () => {
|
||||
customerSearchInput.value = '';
|
||||
customerUserIdInput.value = '';
|
||||
customerIdInput.value = '';
|
||||
customerUserIdInput.dispatchEvent(new Event('change'));
|
||||
customerIdInput.dispatchEvent(new Event('change'));
|
||||
customerSearchInput.dispatchEvent(new Event('input'));
|
||||
if (!customerUserIdInput.value) {
|
||||
customerSearchInput.dispatchEvent(new Event('input'));
|
||||
}
|
||||
});
|
||||
customerSearchInput.addEventListener('blur', () => {
|
||||
setTimeout(() => { customerSuggestionsDiv.style.display = 'none'; }, 150);
|
||||
});
|
||||
}
|
||||
|
||||
// Close suggestions on click outside
|
||||
document.addEventListener('click', (e) => {
|
||||
if (customerSearchInput && e.target !== customerSearchInput && e.target !== customerSuggestionsDiv) {
|
||||
customerSuggestionsDiv.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
// Reset quick-edit
|
||||
resetBtn.addEventListener('click', () => {
|
||||
fields.forEach(el => {
|
||||
|
||||
Reference in New Issue
Block a user