"Refactor database shm and wal files, update guest request template"

This commit is contained in:
Till Tomczak 2025-05-29 16:48:18 +02:00
parent 259bf3f19d
commit 9c1df5e62d
3 changed files with 776 additions and 11 deletions

Binary file not shown.

Binary file not shown.

View File

@ -792,22 +792,787 @@
</div>
</form>
</div>
<!-- Enhanced Status Check Section -->
<div class="guest-form-container p-8">
<div class="text-center">
<div class="inline-flex items-center justify-center w-16 h-16 bg-mercedes-green text-white rounded-xl mb-6">
<svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"/>
</svg>
</div>
<h3 class="text-2xl font-bold text-mercedes-black dark:text-white mb-3">
Status Ihres Antrags prüfen
</h3>
<p class="text-mercedes-gray dark:text-slate-400 mb-8 max-w-2xl mx-auto">
Haben Sie bereits einen Antrag gestellt? Prüfen Sie hier den aktuellen Status Ihrer Anfrage
und verfolgen Sie den Fortschritt in Echtzeit.
</p>
<div class="flex flex-col sm:flex-row items-center justify-center gap-4">
<a href="{{ url_for('guest.guest_requests_overview') if url_for else '/guest/requests' }}"
class="btn-primary flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
<span>Anträge Übersicht</span>
</a>
<button onclick="showStatusCheck()" class="btn-secondary flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
</svg>
<span>Status abfragen</span>
</button>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// File upload preview
const fileInput = document.getElementById('{{ form.file.id }}');
if (fileInput) {
fileInput.addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const label = fileInput.closest('label');
const textElement = label.querySelector('p');
textElement.innerHTML = `<span class="font-semibold">Datei ausgewählt:</span> ${file.name}`;
let selectedFile = null;
let validationState = {
name: false,
email: false,
printer_id: false,
duration_min: false,
reason: false,
file: false
};
let isSubmitting = false;
document.addEventListener('DOMContentLoaded', function() {
initializeGuestRequestForm();
});
function initializeGuestRequestForm() {
setupFileUpload();
setupFormValidation();
setupRealTimeValidation();
setupAccessibility();
setupFormEnhancements();
setupProgressTracking();
}
// Enhanced File Upload with Drag & Drop
function setupFileUpload() {
const uploadArea = document.getElementById('upload-area');
const fileInput = document.getElementById('file-input');
const uploadContent = document.getElementById('upload-content');
if (!uploadArea || !fileInput) return;
// Click to upload
uploadArea.addEventListener('click', (e) => {
if (!selectedFile && !e.target.closest('.file-preview')) {
fileInput.click();
}
});
// Drag and drop events
let dragCounter = 0;
uploadArea.addEventListener('dragenter', (e) => {
e.preventDefault();
dragCounter++;
uploadArea.classList.add('drag-over');
});
uploadArea.addEventListener('dragleave', (e) => {
e.preventDefault();
dragCounter--;
if (dragCounter === 0) {
uploadArea.classList.remove('drag-over');
}
});
uploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
});
uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
dragCounter = 0;
uploadArea.classList.remove('drag-over');
const files = e.dataTransfer.files;
if (files.length > 0) {
handleFileSelection(files[0]);
}
});
// File input change
fileInput.addEventListener('change', (e) => {
if (e.target.files.length > 0) {
handleFileSelection(e.target.files[0]);
}
});
}
});
function handleFileSelection(file) {
const validation = validateFile(file);
if (!validation.valid) {
showAdvancedMessage(validation.message, 'error');
return;
}
selectedFile = file;
validationState.file = true;
showFilePreview(file);
updateFormValidation();
if (validation.warning) {
showAdvancedMessage(validation.warning, 'warning');
}
}
function validateFile(file) {
const allowedExtensions = ['.stl', '.obj', '.3mf', '.gcode', '.ply'];
const maxSize = 50 * 1024 * 1024; // 50MB
const minSize = 1024; // 1KB
const fileName = file.name.toLowerCase();
const fileExtension = '.' + fileName.split('.').pop();
// Check file extension
if (!allowedExtensions.includes(fileExtension)) {
return {
valid: false,
message: `Ungültiger Dateityp "${fileExtension}". Erlaubte Formate: ${allowedExtensions.join(', ')}`
};
}
// Check file size
if (file.size > maxSize) {
return {
valid: false,
message: `Datei zu groß (${formatFileSize(file.size)}). Maximum: 50MB`
};
}
if (file.size < minSize) {
return {
valid: false,
message: 'Datei ist zu klein. Mindestgröße: 1KB'
};
}
// Check for potential issues
let warning = null;
if (file.size > 25 * 1024 * 1024) {
warning = 'Große Datei erkannt. Upload kann länger dauern.';
}
return { valid: true, warning };
}
function showFilePreview(file) {
const previewContainer = document.getElementById('file-preview');
const uploadContent = document.getElementById('upload-content');
// Hide upload content, show preview
uploadContent.style.display = 'none';
previewContainer.classList.remove('hidden');
const fileSize = formatFileSize(file.size);
const fileType = getFileTypeInfo(file.name);
previewContainer.innerHTML = `
<div class="file-preview flex items-center justify-between p-4">
<div class="flex items-center space-x-4">
<div class="w-12 h-12 bg-mercedes-green text-white rounded-lg flex items-center justify-center">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
</div>
<div>
<h4 class="font-semibold text-mercedes-black dark:text-white">${file.name}</h4>
<p class="text-sm text-mercedes-gray dark:text-slate-400">
${fileType} • ${fileSize}
</p>
</div>
</div>
<button onclick="removeFile()" type="button" class="text-mercedes-red hover:text-red-700 transition-colors">
<svg class="w-5 h-5" 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"/>
</svg>
</button>
</div>
`;
}
function removeFile() {
selectedFile = null;
validationState.file = false;
const previewContainer = document.getElementById('file-preview');
const uploadContent = document.getElementById('upload-content');
const fileInput = document.getElementById('file-input');
previewContainer.classList.add('hidden');
uploadContent.style.display = 'block';
fileInput.value = '';
updateFormValidation();
}
// Real-time Form Validation
function setupRealTimeValidation() {
const fields = [
{ id: 'name', type: 'text', minLength: 2, required: true },
{ id: 'email', type: 'email', required: true },
{ id: 'printer_id', type: 'select', required: true },
{ id: 'duration_min', type: 'number', min: 1, max: 9999, required: true },
{ id: 'reason', type: 'textarea', minLength: 50, required: true }
];
fields.forEach(field => {
const element = document.getElementById(field.id) ||
document.querySelector(`[name="${field.id}"]`);
if (element) {
element.addEventListener('input', () => validateField(field, element));
element.addEventListener('blur', () => validateFieldOnBlur(field, element));
}
});
}
function validateField(fieldConfig, element) {
const value = element.value.trim();
let isValid = true;
let message = '';
// Required check
if (fieldConfig.required && !value) {
isValid = false;
message = 'Dieses Feld ist erforderlich';
}
// Type-specific validation
if (value && isValid) {
switch (fieldConfig.type) {
case 'email':
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(value)) {
isValid = false;
message = 'Bitte geben Sie eine gültige E-Mail-Adresse ein';
}
break;
case 'number':
const num = parseInt(value);
if (isNaN(num) || num < fieldConfig.min || num > fieldConfig.max) {
isValid = false;
message = `Wert muss zwischen ${fieldConfig.min} und ${fieldConfig.max} liegen`;
}
break;
case 'text':
case 'textarea':
if (fieldConfig.minLength && value.length < fieldConfig.minLength) {
isValid = false;
message = `Mindestens ${fieldConfig.minLength} Zeichen erforderlich`;
}
break;
}
}
validationState[fieldConfig.id] = isValid;
updateFieldVisualState(element, isValid, message);
updateFormValidation();
}
function validateFieldOnBlur(fieldConfig, element) {
const value = element.value.trim();
// Enhanced validation on blur
if (fieldConfig.id === 'email' && value) {
// Check for common email providers
const commonDomains = ['gmail.com', 'yahoo.com', 'outlook.com', 'mercedes-benz.com', 'daimler.com'];
const domain = value.split('@')[1];
if (domain && !commonDomains.includes(domain)) {
showFieldHint(element, 'Hinweis: Externe E-Mail-Adresse. Stellen Sie sicher, dass Sie E-Mails empfangen können.');
}
}
if (fieldConfig.id === 'reason' && value.length > 0 && value.length < 50) {
showFieldHint(element, `Noch ${50 - value.length} Zeichen bis zur empfohlenen Mindestlänge.`);
}
}
function updateFieldVisualState(element, isValid, message) {
// Clear previous states
element.classList.remove('input-error', 'input-success');
clearFieldMessages(element);
if (element.value.trim()) {
if (isValid) {
element.classList.add('input-success');
} else {
element.classList.add('input-error');
if (message) {
showFieldError(element, message);
}
}
}
}
function showFieldError(element, message) {
const errorDiv = document.createElement('div');
errorDiv.className = 'field-error mt-2 text-sm text-mercedes-red';
errorDiv.innerHTML = `
<div class="flex items-center">
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
${message}
</div>
`;
element.parentNode.appendChild(errorDiv);
}
function showFieldHint(element, message) {
const hintDiv = document.createElement('div');
hintDiv.className = 'field-hint mt-2 text-sm text-mercedes-blue';
hintDiv.innerHTML = `
<div class="flex items-center">
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
${message}
</div>
`;
element.parentNode.appendChild(hintDiv);
}
function clearFieldMessages(element) {
const messages = element.parentNode.querySelectorAll('.field-error, .field-hint');
messages.forEach(msg => msg.remove());
}
function updateFormValidation() {
const submitButton = document.getElementById('submit-button');
const allValid = Object.values(validationState).every(state => state === true);
submitButton.disabled = !allValid;
if (allValid) {
submitButton.classList.remove('opacity-50', 'cursor-not-allowed');
} else {
submitButton.classList.add('opacity-50', 'cursor-not-allowed');
}
// Update progress indicator
updateProgressIndicator();
}
function updateProgressIndicator() {
const completedFields = Object.values(validationState).filter(state => state === true).length;
const totalFields = Object.keys(validationState).length;
const progress = (completedFields / totalFields) * 100;
const progressBar = document.querySelector('.progress-step.active + .flex-1 .bg-mercedes-blue');
if (progressBar) {
progressBar.style.width = `${Math.min(progress, 100)}%`;
}
}
// Form Submission
function setupFormValidation() {
const form = document.getElementById('guestRequestForm');
if (form) {
form.addEventListener('submit', handleFormSubmission);
}
}
async function handleFormSubmission(event) {
event.preventDefault();
if (isSubmitting) return;
// Final validation
if (!Object.values(validationState).every(state => state === true)) {
showAdvancedMessage('Bitte füllen Sie alle erforderlichen Felder korrekt aus.', 'error');
return;
}
if (!selectedFile) {
showAdvancedMessage('Bitte wählen Sie eine Datei aus.', 'error');
return;
}
isSubmitting = true;
showLoadingState();
try {
const formData = new FormData();
formData.append('name', document.getElementById('name').value.trim());
formData.append('email', document.getElementById('email').value.trim());
formData.append('printer_id', document.getElementById('printer_id').value);
formData.append('duration_min', document.getElementById('duration_min').value);
formData.append('reason', document.getElementById('reason').value.trim());
formData.append('file', selectedFile);
// Add CSRF token
const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content');
if (csrfToken) {
formData.append('csrf_token', csrfToken);
}
const response = await fetch(window.location.href, {
method: 'POST',
body: formData
});
if (response.ok) {
const result = await response.text();
if (result.includes('success') || response.redirected) {
showSuccessMessage();
setTimeout(() => {
if (response.redirected) {
window.location.href = response.url;
} else {
window.location.href = '/guest/requests';
}
}, 2000);
} else {
throw new Error('Unerwartete Antwort vom Server');
}
} else {
const errorData = await response.json().catch(() => ({}));
throw new Error(errorData.message || `HTTP ${response.status}: Anfrage fehlgeschlagen`);
}
} catch (error) {
console.error('Form submission error:', error);
showAdvancedMessage(`Fehler beim Einreichen des Antrags: ${error.message}`, 'error');
} finally {
isSubmitting = false;
hideLoadingState();
}
}
function showLoadingState() {
const submitButton = document.getElementById('submit-button');
const submitIcon = document.getElementById('submit-icon');
const submitSpinner = document.getElementById('submit-spinner');
const submitText = document.getElementById('submit-text');
submitButton.disabled = true;
submitIcon.classList.add('hidden');
submitSpinner.classList.remove('hidden');
submitText.textContent = 'Wird eingereicht...';
}
function hideLoadingState() {
const submitButton = document.getElementById('submit-button');
const submitIcon = document.getElementById('submit-icon');
const submitSpinner = document.getElementById('submit-spinner');
const submitText = document.getElementById('submit-text');
submitIcon.classList.remove('hidden');
submitSpinner.classList.add('hidden');
submitText.textContent = 'Antrag einreichen';
updateFormValidation(); // Re-enable if form is valid
}
function showSuccessMessage() {
const overlay = document.createElement('div');
overlay.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50';
overlay.innerHTML = `
<div class="bg-white dark:bg-slate-800 rounded-xl p-8 max-w-md mx-4 text-center">
<div class="success-checkmark w-16 h-16 bg-green-100 dark:bg-green-900 text-green-600 dark:text-green-400 rounded-full flex items-center justify-center mx-auto mb-4">
<svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
</svg>
</div>
<h3 class="text-xl font-bold text-mercedes-black dark:text-white mb-2">Antrag erfolgreich eingereicht!</h3>
<p class="text-mercedes-gray dark:text-slate-400 mb-4">
Ihr Druckantrag wurde erfolgreich übermittelt. Sie erhalten in Kürze eine E-Mail-Bestätigung.
</p>
<p class="text-sm text-mercedes-blue">Sie werden automatisch weitergeleitet...</p>
</div>
`;
document.body.appendChild(overlay);
}
// Enhanced Form Features
function setupFormEnhancements() {
// Character counter for textarea
const reasonTextarea = document.getElementById('reason');
if (reasonTextarea) {
setupCharacterCounter(reasonTextarea, 50, 500);
}
// Auto-resize textarea
setupAutoResize(reasonTextarea);
// Save form data to localStorage
setupAutoSave();
}
function setupCharacterCounter(textarea, minChars, maxChars) {
const wrapper = textarea.parentNode;
const counter = document.createElement('div');
counter.className = 'character-counter mt-2 text-xs text-right text-mercedes-gray dark:text-slate-400';
wrapper.appendChild(counter);
function updateCounter() {
const length = textarea.value.length;
counter.textContent = `${length}/${maxChars} Zeichen`;
if (length < minChars) {
counter.className = 'character-counter mt-2 text-xs text-right text-mercedes-red';
} else if (length > maxChars * 0.9) {
counter.className = 'character-counter mt-2 text-xs text-right text-yellow-600';
} else {
counter.className = 'character-counter mt-2 text-xs text-right text-mercedes-gray dark:text-slate-400';
}
}
textarea.addEventListener('input', updateCounter);
updateCounter();
}
function setupAutoResize(textarea) {
if (!textarea) return;
function resize() {
textarea.style.height = 'auto';
textarea.style.height = textarea.scrollHeight + 'px';
}
textarea.addEventListener('input', resize);
resize();
}
function setupAutoSave() {
const form = document.getElementById('guestRequestForm');
if (!form) return;
const fields = form.querySelectorAll('input, select, textarea');
fields.forEach(field => {
field.addEventListener('input', () => {
saveFormData();
});
});
// Load saved data on page load
loadFormData();
}
function saveFormData() {
const formData = {
name: document.getElementById('name')?.value || '',
email: document.getElementById('email')?.value || '',
printer_id: document.getElementById('printer_id')?.value || '',
duration_min: document.getElementById('duration_min')?.value || '',
reason: document.getElementById('reason')?.value || ''
};
localStorage.setItem('guestRequestFormData', JSON.stringify(formData));
}
function loadFormData() {
const savedData = localStorage.getItem('guestRequestFormData');
if (!savedData) return;
try {
const formData = JSON.parse(savedData);
Object.entries(formData).forEach(([key, value]) => {
const element = document.getElementById(key);
if (element && value) {
element.value = value;
// Trigger validation
element.dispatchEvent(new Event('input'));
}
});
} catch (error) {
console.error('Error loading form data:', error);
}
}
function clearSavedFormData() {
localStorage.removeItem('guestRequestFormData');
}
// Accessibility Features
function setupAccessibility() {
// Add ARIA labels
const form = document.getElementById('guestRequestForm');
if (form) {
form.setAttribute('aria-describedby', 'form-description');
}
// Screen reader announcements
const srContainer = document.createElement('div');
srContainer.setAttribute('aria-live', 'polite');
srContainer.setAttribute('aria-atomic', 'true');
srContainer.className = 'sr-only';
srContainer.id = 'sr-announcements';
document.body.appendChild(srContainer);
// Keyboard navigation for file upload
const uploadArea = document.getElementById('upload-area');
if (uploadArea) {
uploadArea.setAttribute('tabindex', '0');
uploadArea.setAttribute('role', 'button');
uploadArea.setAttribute('aria-label', 'Datei zum Hochladen auswählen');
uploadArea.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
document.getElementById('file-input').click();
}
});
}
}
function setupProgressTracking() {
// Track form completion progress
window.addEventListener('beforeunload', (e) => {
const hasData = Object.values(validationState).some(state => state === true);
if (hasData && !isSubmitting) {
e.preventDefault();
e.returnValue = 'Sie haben ungespeicherte Änderungen. Möchten Sie die Seite wirklich verlassen?';
return e.returnValue;
}
});
}
// Utility Functions
function formatFileSize(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function getFileTypeInfo(filename) {
const extension = filename.toLowerCase().split('.').pop();
const types = {
'stl': 'STL-Datei (3D Mesh)',
'obj': 'OBJ-Datei (3D Object)',
'3mf': '3MF-Datei (3D Manufacturing)',
'gcode': 'G-Code-Datei (Druckfertig)',
'ply': 'PLY-Datei (3D Scan)'
};
return types[extension] || 'Unbekannter Dateityp';
}
function showAdvancedMessage(message, type) {
const toast = document.createElement('div');
toast.className = `fixed top-4 right-4 z-50 p-4 rounded-lg shadow-lg transform transition-all duration-300 translate-x-full opacity-0`;
const colors = {
'error': 'bg-red-50 border border-red-200 text-red-800 dark:bg-red-900 dark:border-red-700 dark:text-red-200',
'warning': 'bg-yellow-50 border border-yellow-200 text-yellow-800 dark:bg-yellow-900 dark:border-yellow-700 dark:text-yellow-200',
'success': 'bg-green-50 border border-green-200 text-green-800 dark:bg-green-900 dark:border-green-700 dark:text-green-200',
'info': 'bg-blue-50 border border-blue-200 text-blue-800 dark:bg-blue-900 dark:border-blue-700 dark:text-blue-200'
};
toast.className += ' ' + colors[type];
const icons = {
'error': '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>',
'warning': '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"/>',
'success': '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>',
'info': '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>'
};
toast.innerHTML = `
<div class="flex items-center">
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
${icons[type]}
</svg>
<span>${message}</span>
<button onclick="this.parentElement.parentElement.remove()" class="ml-4 text-gray-400 hover:text-gray-600">
<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="M6 18L18 6M6 6l12 12"/>
</svg>
</button>
</div>
`;
document.body.appendChild(toast);
// Animate in
setTimeout(() => {
toast.classList.remove('translate-x-full', 'opacity-0');
}, 100);
// Auto-remove
setTimeout(() => {
toast.classList.add('translate-x-full', 'opacity-0');
setTimeout(() => toast.remove(), 300);
}, 5000);
}
// Global Functions
window.resetForm = function() {
if (confirm('Sind Sie sicher, dass Sie das Formular zurücksetzen möchten? Alle Eingaben gehen verloren.')) {
document.getElementById('guestRequestForm').reset();
removeFile();
Object.keys(validationState).forEach(key => {
validationState[key] = false;
});
updateFormValidation();
clearSavedFormData();
// Clear all field messages
document.querySelectorAll('.field-error, .field-hint').forEach(msg => msg.remove());
document.querySelectorAll('.input-error, .input-success').forEach(el => {
el.classList.remove('input-error', 'input-success');
});
showAdvancedMessage('Formular wurde zurückgesetzt', 'info');
}
};
window.showStatusCheck = function() {
const modal = document.createElement('div');
modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50';
modal.innerHTML = `
<div class="bg-white dark:bg-slate-800 rounded-xl p-8 max-w-md mx-4">
<h3 class="text-xl font-bold text-mercedes-black dark:text-white mb-4">Status abfragen</h3>
<p class="text-mercedes-gray dark:text-slate-400 mb-6">
Geben Sie Ihre E-Mail-Adresse ein, um den Status Ihrer Anträge zu überprüfen.
</p>
<input type="email" id="status-email" class="mercedes-form-input block w-full px-4 py-3 mb-4" placeholder="ihre.email@example.com">
<div class="flex space-x-4">
<button onclick="this.closest('.fixed').remove()" class="btn-secondary flex-1">Abbrechen</button>
<button onclick="checkStatus()" class="btn-primary flex-1">Status prüfen</button>
</div>
</div>
`;
document.body.appendChild(modal);
// Focus email input
setTimeout(() => {
document.getElementById('status-email').focus();
}, 100);
};
window.checkStatus = function() {
const email = document.getElementById('status-email').value.trim();
if (!email) {
showAdvancedMessage('Bitte geben Sie eine E-Mail-Adresse ein', 'error');
return;
}
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
showAdvancedMessage('Bitte geben Sie eine gültige E-Mail-Adresse ein', 'error');
return;
}
// Close modal and redirect
document.querySelector('.fixed.inset-0').remove();
window.location.href = `/guest/requests?email=${encodeURIComponent(email)}`;
};
</script>
{% endblock %}