🔧 Update: Enhance printer deletion API and logging

**Änderungen:**
-  admin_unified.py: Implemented detailed logging for printer deletion actions, including success and error messages.
-  printers.html: Updated delete button functionality to utilize the PrinterManager class for improved code organization and error handling.

**Ergebnis:**
- Verbesserte Nachverfolgbarkeit und Fehlerdiagnose bei Drucker-Löschvorgängen.
- Optimierte Benutzerinteraktion durch verbesserte Fehlerbehandlung im Frontend.

🤖 Generated with [Claude Code](https://claude.ai/code)
This commit is contained in:
2025-06-16 00:33:20 +02:00
parent e98f273cad
commit fcefbef49d
84 changed files with 972 additions and 10 deletions

View File

@ -1170,7 +1170,7 @@
</div>
<div class="flex items-center justify-between pt-6 border-t border-mercedes-silver">
<button type="button" id="deletePrinterBtn" onclick="deletePrinter()" style="display: none;"
<button type="button" id="deletePrinterBtn" onclick="printerManager.deletePrinter()" style="display: none;"
class="px-6 py-3 bg-red-600 hover:bg-red-700 text-white rounded-lg transition-colors flex items-center gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
@ -2097,6 +2097,50 @@ class PrinterManager {
getCSRFToken() {
return document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') || '';
}
// Drucker löschen Funktion
async deletePrinter() {
const printerId = document.getElementById('printerId').value;
if (!printerId) {
this.showError('Keine Drucker-ID gefunden');
return;
}
const printer = allPrinters.find(p => p.id == printerId);
if (!printer) {
this.showError('Drucker nicht gefunden');
return;
}
// Bestätigungsdialog
const confirmed = confirm(`Sind Sie sicher, dass Sie den Drucker "${printer.name}" löschen möchten?\n\nDieser Vorgang kann nicht rückgängig gemacht werden.`);
if (!confirmed) return;
try {
const response = await fetch(`/api/admin/printers/${printerId}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': this.getCSRFToken()
}
});
const result = await response.json();
if (response.ok && result.success) {
this.showSuccess(`Drucker "${printer.name}" erfolgreich gelöscht`);
this.closeModal('printerModal');
await this.loadPrinters(); // Drucker-Liste neu laden
} else {
this.showError(`Fehler beim Löschen: ${result.error || 'Unbekannter Fehler'}`);
}
} catch (error) {
console.error('Fehler beim Löschen des Druckers:', error);
this.showError(`Netzwerkfehler beim Löschen: ${error.message}`);
}
}
// Weitere Modal-Funktionen
openPrinterDetails(printerId) {