fix: verificare, ma dovrebbe essere corretta la lattura da ldap

This commit is contained in:
2026-07-08 00:58:52 +02:00
parent bf8b4c387e
commit 78a26fe970
7 changed files with 231 additions and 34 deletions
+20 -8
View File
@@ -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) {
+17 -18
View File
@@ -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 => {