aggiunti trasferte, export excel, miglioramenti generali
This commit is contained in:
@@ -267,26 +267,70 @@ async function loadExclusions(officeId) {
|
||||
</span>
|
||||
${e.notes ? `<span class="rule-note">${e.notes}</span>` : ''}
|
||||
</div>
|
||||
<button class="btn-icon btn-danger" onclick="deleteExclusion('${e.id}')">
|
||||
×
|
||||
</button>
|
||||
<div class="rule-actions" style="display: flex; gap: 0.5rem; align-items: center;">
|
||||
<button class="btn-icon" onclick='openEditExclusion("${e.id}", ${JSON.stringify(e).replace(/'/g, "'")})' title="Modifica">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M12 20h9"></path><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path>
|
||||
</svg>
|
||||
</button>
|
||||
<button class="btn-icon btn-danger" onclick="deleteExclusion('${e.id}')" title="Elimina">
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
}
|
||||
|
||||
async function addExclusion(data) {
|
||||
const response = await api.post(`/api/offices/${currentOfficeId}/exclusions`, data);
|
||||
// Global variable to track edit mode
|
||||
let editingExclusionId = null;
|
||||
|
||||
async function openEditExclusion(id, data) {
|
||||
editingExclusionId = id;
|
||||
|
||||
// Populate form
|
||||
populateUserSelects();
|
||||
document.getElementById('exclusionUser').value = data.user_id;
|
||||
// Disable user select in edit mode usually? Or allow change? API allows it.
|
||||
|
||||
document.getElementById('exclusionStartDate').value = data.start_date || '';
|
||||
document.getElementById('exclusionEndDate').value = data.end_date || '';
|
||||
document.getElementById('exclusionNotes').value = data.notes || '';
|
||||
|
||||
// Change modal title/button
|
||||
document.querySelector('#exclusionModal h3').textContent = 'Modifica Esclusione';
|
||||
document.querySelector('#exclusionForm button[type="submit"]').textContent = 'Salva Modifiche';
|
||||
|
||||
document.getElementById('exclusionModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
async function saveExclusion(data) {
|
||||
let response;
|
||||
if (editingExclusionId) {
|
||||
response = await api.put(`/api/offices/${currentOfficeId}/exclusions/${editingExclusionId}`, data);
|
||||
} else {
|
||||
response = await api.post(`/api/offices/${currentOfficeId}/exclusions`, data);
|
||||
}
|
||||
|
||||
if (response && response.ok) {
|
||||
await loadExclusions(currentOfficeId);
|
||||
document.getElementById('exclusionModal').style.display = 'none';
|
||||
document.getElementById('exclusionForm').reset();
|
||||
resetExclusionForm();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.detail || 'Impossibile aggiungere l\'esclusione');
|
||||
alert(error.detail || 'Impossibile salvare l\'esclusione');
|
||||
}
|
||||
}
|
||||
|
||||
function resetExclusionForm() {
|
||||
document.getElementById('exclusionForm').reset();
|
||||
editingExclusionId = null;
|
||||
document.querySelector('#exclusionModal h3').textContent = 'Aggiungi Esclusione Parcheggio';
|
||||
document.querySelector('#exclusionForm button[type="submit"]').textContent = 'Aggiungi';
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function deleteExclusion(id) {
|
||||
if (!confirm('Eliminare questa esclusione?')) return;
|
||||
const response = await api.delete(`/api/offices/${currentOfficeId}/exclusions/${id}`);
|
||||
@@ -335,6 +379,10 @@ function setupEventListeners() {
|
||||
modals.forEach(m => {
|
||||
document.getElementById(m.btn).addEventListener('click', () => {
|
||||
if (m.id !== 'closingDayModal') populateUserSelects();
|
||||
|
||||
// Special handling for exclusion to reset edit mode
|
||||
if (m.id === 'exclusionModal') resetExclusionForm();
|
||||
|
||||
document.getElementById(m.id).style.display = 'flex';
|
||||
});
|
||||
document.getElementById(m.close).addEventListener('click', () => {
|
||||
@@ -368,7 +416,7 @@ function setupEventListeners() {
|
||||
|
||||
document.getElementById('exclusionForm').addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
addExclusion({
|
||||
saveExclusion({
|
||||
user_id: document.getElementById('exclusionUser').value,
|
||||
start_date: document.getElementById('exclusionStartDate').value || null,
|
||||
end_date: document.getElementById('exclusionEndDate').value || null,
|
||||
@@ -380,4 +428,7 @@ function setupEventListeners() {
|
||||
// Global functions
|
||||
window.deleteClosingDay = deleteClosingDay;
|
||||
window.deleteGuarantee = deleteGuarantee;
|
||||
window.deleteClosingDay = deleteClosingDay;
|
||||
window.deleteGuarantee = deleteGuarantee;
|
||||
window.deleteExclusion = deleteExclusion;
|
||||
window.openEditExclusion = openEditExclusion;
|
||||
|
||||
Reference in New Issue
Block a user