280 lines
14 KiB
HTML
280 lines
14 KiB
HTML
{% extends "base.html" %}
|
|
|
|
{% block title %}Drucker hinzufügen - MYP Admin{% endblock %}
|
|
|
|
{% block extra_css %}
|
|
<!-- Zusätzliche Styles für diese Seite -->
|
|
<style>
|
|
.form-container {
|
|
background: rgba(255, 255, 255, 0.95);
|
|
backdrop-filter: blur(10px);
|
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.dark .form-container {
|
|
background: rgba(30, 41, 59, 0.95);
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="min-h-screen py-8">
|
|
<div class="max-w-2xl mx-auto px-4">
|
|
<!-- Header -->
|
|
<div class="form-container rounded-lg p-6 mb-6">
|
|
<div class="flex items-center justify-between">
|
|
<div class="flex items-center space-x-3">
|
|
<i class="fas fa-print text-blue-600 dark:text-blue-400 text-2xl"></i>
|
|
<h1 class="text-2xl font-bold text-slate-800 dark:text-white">Neuen Drucker hinzufügen</h1>
|
|
</div>
|
|
<a href="{{ url_for('admin.admin_dashboard', tab='printers') }}"
|
|
class="bg-slate-500 hover:bg-slate-600 text-white px-4 py-2 rounded-lg transition-colors">
|
|
<i class="fas fa-arrow-left mr-2"></i>Zurück
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Formular -->
|
|
<div class="form-container rounded-lg p-6">
|
|
<form id="printerForm" class="space-y-6">
|
|
<!-- CSRF Token -->
|
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
|
|
|
|
<!-- Name -->
|
|
<div>
|
|
<label for="name" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
<i class="fas fa-tag mr-2"></i>Drucker-Name *
|
|
</label>
|
|
<input type="text"
|
|
id="name"
|
|
name="name"
|
|
required
|
|
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
|
placeholder="z.B. Prusa MK3S+ Raum 101">
|
|
</div>
|
|
|
|
<!-- Modell -->
|
|
<div>
|
|
<label for="model" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
<i class="fas fa-cogs mr-2"></i>Drucker-Modell *
|
|
</label>
|
|
<input type="text"
|
|
id="model"
|
|
name="model"
|
|
required
|
|
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
|
placeholder="z.B. Prusa i3 MK3S+">
|
|
</div>
|
|
|
|
<!-- Standort -->
|
|
<div>
|
|
<label for="location" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
<i class="fas fa-map-marker-alt mr-2"></i>Standort
|
|
</label>
|
|
<input type="text"
|
|
id="location"
|
|
name="location"
|
|
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
|
placeholder="z.B. Werkstatt Erdgeschoss">
|
|
</div>
|
|
|
|
<!-- Steckdosen-Konfiguration -->
|
|
<div class="bg-slate-50 dark:bg-slate-900/50 rounded-lg p-4 space-y-4">
|
|
<h3 class="text-lg font-semibold text-slate-800 dark:text-white">
|
|
<i class="fas fa-plug mr-2"></i>Tapo Smart-Plug Konfiguration (optional)
|
|
</h3>
|
|
|
|
<!-- Plug IP -->
|
|
<div>
|
|
<label for="plug_ip" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
IP-Adresse der Steckdose
|
|
</label>
|
|
<input type="text"
|
|
id="plug_ip"
|
|
name="plug_ip"
|
|
pattern="^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
|
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
|
placeholder="192.168.1.100">
|
|
</div>
|
|
|
|
<!-- Plug Username -->
|
|
<div>
|
|
<label for="plug_username" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
Tapo Benutzername
|
|
</label>
|
|
<input type="text"
|
|
id="plug_username"
|
|
name="plug_username"
|
|
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
|
placeholder="TP-Link Konto E-Mail">
|
|
</div>
|
|
|
|
<!-- Plug Password -->
|
|
<div>
|
|
<label for="plug_password" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
Tapo Passwort
|
|
</label>
|
|
<input type="password"
|
|
id="plug_password"
|
|
name="plug_password"
|
|
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
|
placeholder="TP-Link Konto Passwort">
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Drucker IP (optional) -->
|
|
<div>
|
|
<label for="ip_address" class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2">
|
|
<i class="fas fa-network-wired mr-2"></i>Drucker IP-Adresse (optional)
|
|
</label>
|
|
<input type="text"
|
|
id="ip_address"
|
|
name="ip_address"
|
|
pattern="^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
|
class="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-slate-800 text-slate-900 dark:text-white"
|
|
placeholder="192.168.1.101">
|
|
<p class="text-sm text-slate-500 dark:text-slate-400 mt-1">IP-Adresse des Druckers selbst (falls verfügbar)</p>
|
|
</div>
|
|
|
|
<!-- Status -->
|
|
<div>
|
|
<label for="active" class="flex items-center space-x-2 text-sm font-medium text-slate-700 dark:text-slate-300 cursor-pointer">
|
|
<input type="checkbox"
|
|
id="active"
|
|
name="active"
|
|
checked
|
|
class="rounded text-blue-600 focus:ring-2 focus:ring-blue-500">
|
|
<span>Drucker aktiv</span>
|
|
</label>
|
|
</div>
|
|
|
|
<!-- Hinweise -->
|
|
<div class="bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4">
|
|
<div class="flex">
|
|
<i class="fas fa-info-circle text-blue-500 dark:text-blue-400 mt-0.5 mr-3"></i>
|
|
<div class="text-sm text-blue-700 dark:text-blue-300">
|
|
<p class="font-semibold mb-1">Hinweise:</p>
|
|
<ul class="list-disc list-inside space-y-1">
|
|
<li>Felder mit * sind Pflichtfelder</li>
|
|
<li>Die Tapo-Konfiguration ist optional, ermöglicht aber die Stromsteuerung</li>
|
|
<li>Bei fehlenden Tapo-Zugangsdaten werden die globalen Einstellungen verwendet</li>
|
|
<li>Eine MAC-Adresse wird automatisch generiert wenn nicht vorhanden</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Aktionen -->
|
|
<div class="flex space-x-3 pt-4">
|
|
<button type="submit"
|
|
id="submitBtn"
|
|
class="flex-1 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition-colors">
|
|
<i class="fas fa-save mr-2"></i>Drucker erstellen
|
|
</button>
|
|
<a href="{{ url_for('admin.admin_dashboard', tab='printers') }}"
|
|
class="flex-1 bg-slate-500 hover:bg-slate-600 text-white px-4 py-2 rounded-lg text-center transition-colors">
|
|
<i class="fas fa-times mr-2"></i>Abbrechen
|
|
</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
<!-- JavaScript für Form-Validierung und AJAX-Submit -->
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const form = document.getElementById('printerForm');
|
|
const submitBtn = document.getElementById('submitBtn');
|
|
|
|
// IP-Adresse-Validierung
|
|
function validateIP(ip) {
|
|
const ipRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
return !ip || ipRegex.test(ip);
|
|
}
|
|
|
|
// Form-Submit mit AJAX
|
|
form.addEventListener('submit', async function(e) {
|
|
e.preventDefault();
|
|
|
|
// Validierung
|
|
const plugIp = document.getElementById('plug_ip').value;
|
|
const printerIp = document.getElementById('ip_address').value;
|
|
|
|
if (!validateIP(plugIp)) {
|
|
showNotification('Ungültige Steckdosen-IP-Adresse', 'error');
|
|
return;
|
|
}
|
|
|
|
if (!validateIP(printerIp)) {
|
|
showNotification('Ungültige Drucker-IP-Adresse', 'error');
|
|
return;
|
|
}
|
|
|
|
// Button deaktivieren
|
|
submitBtn.disabled = true;
|
|
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i>Wird erstellt...';
|
|
|
|
// Daten sammeln
|
|
const formData = {
|
|
name: document.getElementById('name').value,
|
|
model: document.getElementById('model').value,
|
|
location: document.getElementById('location').value || '',
|
|
ip_address: printerIp || null,
|
|
plug_ip: plugIp || null,
|
|
plug_username: document.getElementById('plug_username').value || null,
|
|
plug_password: document.getElementById('plug_password').value || null,
|
|
active: document.getElementById('active').checked
|
|
};
|
|
|
|
try {
|
|
const response = await fetch('/api/admin/printers', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRFToken': document.querySelector('[name=csrf_token]').value
|
|
},
|
|
body: JSON.stringify(formData)
|
|
});
|
|
|
|
const result = await response.json();
|
|
|
|
if (response.ok && result.success) {
|
|
showNotification(result.message || 'Drucker erfolgreich erstellt', 'success');
|
|
// Nach kurzer Verzögerung zur Drucker-Liste
|
|
setTimeout(() => {
|
|
window.location.href = "{{ url_for('admin.admin_dashboard', tab='printers') }}";
|
|
}, 1500);
|
|
} else {
|
|
showNotification(result.error || 'Fehler beim Erstellen des Druckers', 'error');
|
|
submitBtn.disabled = false;
|
|
submitBtn.innerHTML = '<i class="fas fa-save mr-2"></i>Drucker erstellen';
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('Fehler:', error);
|
|
showNotification('Netzwerkfehler beim Erstellen des Druckers', 'error');
|
|
submitBtn.disabled = false;
|
|
submitBtn.innerHTML = '<i class="fas fa-save mr-2"></i>Drucker erstellen';
|
|
}
|
|
});
|
|
});
|
|
|
|
// Notification-Funktion
|
|
function showNotification(message, type = 'info') {
|
|
// Verwende die globale Notification-Funktion falls vorhanden
|
|
if (typeof window.showNotification === 'function') {
|
|
window.showNotification(message, type);
|
|
} else if (typeof showFlashMessage === 'function') {
|
|
showFlashMessage(message, type);
|
|
} else {
|
|
// Fallback
|
|
alert(message);
|
|
}
|
|
}
|
|
</script>
|
|
{% endblock %} |