@@ -474,7 +473,7 @@ const TicketDetailView = {
bindEvents(ticket, articles, container, groupsData) {
// Quick-edit change detection
- const fields = document.querySelectorAll('.quick-edit-select, #qe-customer-user-id, #qe-customer-id');
+ const fields = document.querySelectorAll('.quick-edit-select:not(#qe-queue-search), #qe-queue, #qe-customer-user-id, #qe-customer-id');
const saveBtn = document.getElementById('qe-save');
const resetBtn = document.getElementById('qe-reset');
const timeUnitInput = document.getElementById('qe-time-unit');
@@ -486,7 +485,12 @@ const TicketDetailView = {
const original = String(this.originalValues[field] || '');
const current = el.value;
const changed = current !== original;
- el.classList.toggle('changed', changed);
+ if (el.id === 'qe-queue') {
+ const searchInput = document.getElementById('qe-queue-search');
+ if (searchInput) searchInput.classList.toggle('changed', changed);
+ } else {
+ el.classList.toggle('changed', changed);
+ }
if (changed) hasChanges = true;
});
@@ -504,6 +508,68 @@ const TicketDetailView = {
timeUnitInput.addEventListener('change', checkChanges);
}
+ // Queue Autocomplete inside Quick Edit
+ const queueSearchInput = document.getElementById('qe-queue-search');
+ const queueSuggestionsDiv = document.getElementById('qe-queue-suggestions');
+ const queueIdInput = document.getElementById('qe-queue');
+
+ let queueDebounce;
+ if (queueSearchInput) {
+ queueSearchInput.addEventListener('input', () => {
+ clearTimeout(queueDebounce);
+ const q = queueSearchInput.value.trim();
+
+ queueDebounce = setTimeout(async () => {
+ try {
+ const queues = await App.api(`/api/queues/search?q=${encodeURIComponent(q)}`);
+ if (queueSearchInput.value.trim() !== q) {
+ return;
+ }
+ if (queues.length === 0) {
+ queueSuggestionsDiv.innerHTML = '
Nessuna coda trovata
';
+ queueSuggestionsDiv.style.display = 'block';
+ return;
+ }
+
+ queueSuggestionsDiv.innerHTML = queues.map(q => {
+ const displayName = q.name.replace(/::/g, ' › ');
+ return `
+
+ ${App.escapeHtml(displayName)}
+
+ `;
+ }).join('');
+ queueSuggestionsDiv.style.display = 'block';
+
+ // Bind click/mousedown
+ queueSuggestionsDiv.querySelectorAll('.autocomplete-suggestion-item').forEach(item => {
+ if (item.dataset.id) {
+ item.addEventListener('mousedown', (e) => {
+ e.preventDefault();
+ queueSearchInput.value = item.dataset.name;
+ queueIdInput.value = item.dataset.id;
+ queueSuggestionsDiv.style.display = 'none';
+ queueIdInput.dispatchEvent(new Event('change'));
+ });
+ }
+ });
+ } catch (err) {
+ console.error(err);
+ }
+ }, 150);
+ });
+
+ queueSearchInput.addEventListener('focus', () => {
+ queueSearchInput.value = '';
+ queueIdInput.value = '';
+ queueSearchInput.dispatchEvent(new Event('input'));
+ });
+
+ queueSearchInput.addEventListener('blur', () => {
+ setTimeout(() => { queueSuggestionsDiv.style.display = 'none'; }, 150);
+ });
+ }
+
// Customer User Autocomplete inside Quick Edit
const customerSearchInput = document.getElementById('qe-customer-search');
const customerSuggestionsDiv = document.getElementById('qe-customer-suggestions');
@@ -574,6 +640,10 @@ const TicketDetailView = {
el.value = this.originalValues[el.dataset.field] || '';
el.classList.remove('changed');
});
+ if (queueSearchInput) {
+ queueSearchInput.classList.remove('changed');
+ queueSearchInput.value = this.originalValues['queue_name'] || '';
+ }
if (customerSearchInput) {
const first = this.originalValues['customer_first'] || '';
const last = this.originalValues['customer_last'] || '';
@@ -587,6 +657,12 @@ const TicketDetailView = {
// Save quick-edit
saveBtn.addEventListener('click', async () => {
+ const queueSearch = queueSearchInput ? queueSearchInput.value.trim() : '';
+ if (queueSearchInput && !queueIdInput.value) {
+ Toast.warning('Seleziona una coda valida dall\'elenco.');
+ return;
+ }
+
const customerSearch = customerSearchInput ? customerSearchInput.value.trim() : '';
if (customerSearch && !customerUserIdInput.value) {
customerUserIdInput.value = customerSearch;