fix: verificare, ma dovrebbe essere corretta la lattura da ldap
This commit is contained in:
@@ -388,11 +388,16 @@ const TicketCreateView = {
|
||||
userSearchInput.addEventListener('input', () => {
|
||||
clearTimeout(userDebounce);
|
||||
const q = userSearchInput.value.trim();
|
||||
// Do not block empty query to allow all results on focus
|
||||
|
||||
userDebounce = setTimeout(async () => {
|
||||
try {
|
||||
const users = await App.api(`/api/customer-users/search?q=${encodeURIComponent(q)}`);
|
||||
console.log('[Frontend LDAP Search] Users returned:', users);
|
||||
// Prevent race conditions: discard results if the input value has changed
|
||||
if (userSearchInput.value.trim() !== q) {
|
||||
console.log('[Frontend LDAP Search] Discarding stale results for query:', q);
|
||||
return;
|
||||
}
|
||||
if (users.length === 0) {
|
||||
userSuggestionsDiv.innerHTML = '<div class="autocomplete-suggestion-item" style="color:var(--text-muted); cursor:default;">Nessun utente trovato</div>';
|
||||
userSuggestionsDiv.style.display = 'block';
|
||||
@@ -400,17 +405,18 @@ const TicketCreateView = {
|
||||
}
|
||||
|
||||
userSuggestionsDiv.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('');
|
||||
userSuggestionsDiv.style.display = 'block';
|
||||
|
||||
// Bind click
|
||||
// Use mousedown instead of click to fire before blur event
|
||||
userSuggestionsDiv.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
|
||||
userSearchInput.value = item.dataset.name;
|
||||
customerUserIdInput.value = item.dataset.login;
|
||||
userSuggestionsDiv.style.display = 'none';
|
||||
@@ -429,12 +435,18 @@ const TicketCreateView = {
|
||||
}, 300);
|
||||
});
|
||||
userSearchInput.addEventListener('focus', () => {
|
||||
userSearchInput.value = '';
|
||||
customerUserIdInput.value = '';
|
||||
userSearchInput.dispatchEvent(new Event('input'));
|
||||
if (!customerUserIdInput.value) {
|
||||
// Only search if no user is selected yet
|
||||
userSearchInput.dispatchEvent(new Event('input'));
|
||||
}
|
||||
});
|
||||
userSearchInput.addEventListener('blur', () => {
|
||||
// Small delay to allow mousedown on item to fire first
|
||||
setTimeout(() => { userSuggestionsDiv.style.display = 'none'; }, 150);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Owner Autocomplete (dynamic backend search)
|
||||
let ownerDebounce;
|
||||
if (ownerSearchInput) {
|
||||
|
||||
Reference in New Issue
Block a user