/** * ShortcutsView — Gestione Shortcuts e Scorciatoie da Tastiera * Visualizza e permette la personalizzazione delle scorciatoie da tastiera. */ const ShortcutsView = { editingId: null, render() { const container = document.getElementById('view-container'); const shortcuts = this.getShortcutsList(); container.innerHTML = `
Shortcuts e Scorciatoie da Tastiera

Personalizza o abilita/disabilita le scorciatoie da tastiera rapide per velocizzare la gestione dei ticket e delle consuntivazioni.

${shortcuts.map(sc => this.buildShortcutRow(sc)).join('')}
`; this.bindEvents(); }, getShortcutsList() { const list = [ { id: 'create_ticket_open', name: 'Crea Nuovo Ticket', description: 'Apre la pagina di creazione di un nuovo ticket', context: 'Globale', defaultCombo: { ctrl: true, alt: true, shift: false, key: 'n', enabled: true } }, { id: 'create_ticket_submit', name: 'Invia Nuovo Ticket', description: 'Invia il modulo e crea un nuovo ticket', context: 'Pagina Nuovo Ticket', defaultCombo: { ctrl: true, alt: false, shift: false, key: 'Enter', enabled: true } }, { id: 'quick_edit_save', name: 'Salva Modifica Rapida', description: 'Salva le modifiche apportate nei campi di Modifica Rapida', context: 'Pagina Dettaglio Ticket (Modifica Rapida)', defaultCombo: { ctrl: true, alt: false, shift: false, key: 'Enter', enabled: true } } ]; return list.map(item => { const current = App.getShortcut(item.id); return { ...item, currentCombo: current }; }); }, buildShortcutRow(sc) { const combo = sc.currentCombo; const label = App.formatShortcutLabel(combo); const keysHtml = label.split(' + ').map(k => ` ${App.escapeHtml(k)} `).join(' + '); return `
${App.escapeHtml(sc.name)} ${App.escapeHtml(sc.context)}
${App.escapeHtml(sc.description)}
${combo.enabled ? keysHtml : 'Disabilitato'}
`; }, bindEvents() { // Reset all document.getElementById('sc-reset-all')?.addEventListener('click', () => { if (confirm('Ripristinare tutte le scorciatoie da tastiera ai valori predefiniti?')) { localStorage.removeItem('otrs_shortcuts'); Toast.success('Shortcuts ripristinati ai valori predefiniti'); this.render(); } }); // Toggles document.querySelectorAll('.sc-toggle-input').forEach(toggle => { toggle.addEventListener('change', (e) => { const id = e.target.dataset.id; const current = App.getShortcut(id); current.enabled = e.target.checked; App.saveCustomShortcut(id, current); Toast.success(`Shortcut ${current.enabled ? 'abilitato' : 'disabilitato'}`); this.render(); }); }); // Edit button let recordedCombo = null; const modal = document.getElementById('sc-modal'); const recorder = document.getElementById('sc-key-recorder'); const saveBtn = document.getElementById('sc-modal-save'); const cancelBtn = document.getElementById('sc-modal-cancel'); document.querySelectorAll('.sc-edit-btn').forEach(btn => { btn.addEventListener('click', () => { this.editingId = btn.dataset.id; const item = this.getShortcutsList().find(x => x.id === this.editingId); document.getElementById('sc-modal-title').textContent = `Modifica: ${item ? item.name : ''}`; recordedCombo = null; recorder.innerHTML = 'Premi i tasti sulla tastiera...'; saveBtn.disabled = true; modal.style.display = 'flex'; recorder.focus(); }); }); cancelBtn?.addEventListener('click', () => { modal.style.display = 'none'; }); recorder?.addEventListener('keydown', (e) => { e.preventDefault(); e.stopPropagation(); // Ignore lone modifier presses if (['Control', 'Alt', 'Shift', 'Meta'].includes(e.key)) { return; } const ctrl = e.ctrlKey || e.metaKey; const alt = e.altKey; const shift = e.shiftKey; let key = e.key; if (key === ' ') key = 'Space'; recordedCombo = { ctrl, alt, shift, key, enabled: true }; const label = App.formatShortcutLabel(recordedCombo); recorder.innerHTML = label.split(' + ').map(k => ` ${App.escapeHtml(k)} `).join(' + '); saveBtn.disabled = false; }); saveBtn?.addEventListener('click', () => { if (this.editingId && recordedCombo) { App.saveCustomShortcut(this.editingId, recordedCombo); Toast.success('Combinazione salvata!'); modal.style.display = 'none'; this.render(); } }); } };