Files
Backend/WEBROOT/services/ticket_control.php
T

97 lines
3.8 KiB
PHP

<div class="arbeitsberichte-wrapper">
<div class="table-container" style="margin-top: 30px;">
<h3>Ticket Verwaltung</h3>
<div id="tableWrapper">
<p>Lade Daten...</p>
</div>
</div>
</div>
<script src="/js/AjaxMethods.js"></script>
<script src="/js/AjaxRenderTables.js"></script>
<script src="/js/ajaxApi/TicketControlAjaxMethods.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const tableWrapper = document.getElementById('tableWrapper');
const allowedStatuses = ['OFFEN', 'DEPLOYED', 'ABGELEHNT', 'ANGENOMMEN'];
function renderTicketControTabelle(entries) {
if (!entries || entries.length === 0) {
tableWrapper.innerHTML = '<p>Keine Tickets vorhanden.</p>';
return;
}
let html = `
<table class="db-table mobile-responsive-table">
<thead>
<tr>
<th>Titel</th><th>Beschreibung</th><th>Status</th><th>Ersteller</th>
<th style="width: 220px;">Aktion</th>
</tr>
</thead>
<tbody>
`;
for (const e of entries) {
const options = allowedStatuses.map(s =>
`<option value="${escapeHtml(s)}" ${e.STATUS === s ? 'selected' : ''}>${escapeHtml(s)}</option>`
).join('');
html += `
<tr data-id="${escapeHtml(e.ID)}">
<td data-label="Titel">${escapeHtml(e.TITEL)}</td>
<td data-label="Beschreibung">${escapeHtml(e.BESCHREIBUNG)}</td>
<td data-label="Status">${escapeHtml(e.STATUS)}</td>
<td data-label="Ersteller">${escapeHtml(e.ERSTELLER)}</td>
<td data-label="Aktion">
<div style="display:flex; flex-direction:column; gap:6px; align-items:stretch;">
<select class="status-select" data-id="${escapeHtml(e.ID)}">
${options}
</select>
<button type="button" class="btn-edit" data-id="${escapeHtml(e.ID)}">Speichern</button>
<button type="button" class="btn-delete" data-id="${escapeHtml(e.ID)}" style="margin-top:3pt;">Löschen</button>
</div>
</td>
</tr>`;
}
html += `</tbody></table>`;
tableWrapper.innerHTML = html;
tableWrapper.querySelectorAll('.btn-edit').forEach(btn => {
btn.addEventListener('click', async () => {
const id = btn.dataset.id;
const select = tableWrapper.querySelector(
`.status-select[data-id="${id}"]`);
try {
await editTicketControEntry(id, select.value);
await ladeListe();
} catch (err) {
alert('Fehler beim Speichern: ' + err.message);
}
});
});
tableWrapper.querySelectorAll('.btn-delete').forEach(btn => {
btn.addEventListener('click', async () => {
if (!confirm('Möchtest du dieses Ticket wirklich löschen?')) return;
try {
await deleteTicketControEntry(btn.dataset.id);
await ladeListe();
} catch (err) {
alert('Fehler beim Löschen: ' + err.message);
}
});
});
}
async function ladeListe() {
try {
const data = await getTicketControEntries();
renderTicketControTabelle(data.entries);
} catch (err) {
tableWrapper.innerHTML = `<p>❌ ${escapeHtml(err.message)}</p>`;
}
}
ladeListe();
});
</script>