diff --git a/admin-dashboard.html b/admin-dashboard.html index 1c3e480..1f5ac9a 100644 --- a/admin-dashboard.html +++ b/admin-dashboard.html @@ -1056,24 +1056,24 @@
- - + +
- - + +
- - + +
- +
@@ -2609,43 +2609,44 @@ async function deleteApp(appId) { async function saveApp(event) { event.preventDefault(); - // Get form data - const form = document.getElementById('appForm'); - const formData = new FormData(form); - - // Get app ID + // Get form values + const name = document.getElementById('name').value.trim(); + const url = document.getElementById('url').value.trim(); + const description = document.getElementById('description').value.trim(); + const iconClass = document.getElementById('appIcon').value.trim(); const appId = document.getElementById('appId').value; - // Get icon class from the selected icon - const iconClass = document.getElementById('appIcon').value; - formData.set('iconClass', iconClass); - - // Convert FormData to URL-encoded string - const urlEncoded = new URLSearchParams(); - for (const [key, value] of formData.entries()) { - urlEncoded.append(key, value); + // Validate required fields + if (!name || !url || !iconClass) { + showNotification('Název, URL a ikona jsou povinné pole', 'error'); + return; } - // Create request URL - const url = appId ? `/api/apps/${appId}` : '/api/apps'; + // Create form data + const formData = new URLSearchParams(); + formData.append('name', name); + formData.append('url', url); + formData.append('description', description); + formData.append('iconClass', iconClass); - // Set request method + // Create request URL + const requestUrl = appId ? `/api/apps/${appId}` : '/api/apps'; const method = appId ? 'PUT' : 'POST'; - // Send request try { - const response = await fetch(url, { + const response = await fetch(requestUrl, { method: method, headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, - body: urlEncoded.toString(), + body: formData.toString(), credentials: 'include' }); if (!response.ok) { - const errorData = await response.json().catch(() => ({})); - throw new Error(errorData.error || 'Network response was not ok'); + const errorText = await response.text(); + console.error('Server response:', errorText); + throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); @@ -2653,7 +2654,7 @@ async function saveApp(event) { loadApps(); closeAppModal(); } catch (error) { - console.error('Error:', error); + console.error('Error saving app:', error); showNotification(`Chyba při ukládání aplikace: ${error.message}`, 'error'); } }