mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-04 20:42:59 +00:00
s
This commit is contained in:
+26
-16
@@ -2610,14 +2610,21 @@ async function saveApp(event) {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
// Get form data
|
// Get form data
|
||||||
const formData = new FormData(document.getElementById('appForm'));
|
const form = document.getElementById('appForm');
|
||||||
|
const formData = new FormData(form);
|
||||||
|
|
||||||
// Get app ID
|
// Get app ID
|
||||||
const appId = document.getElementById('appId').value;
|
const appId = document.getElementById('appId').value;
|
||||||
|
|
||||||
// Get icon class from the selected icon
|
// Get icon class from the selected icon
|
||||||
const iconClass = document.getElementById('appIcon').value;
|
const iconClass = document.getElementById('appIcon').value;
|
||||||
formData.append('iconClass', iconClass);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
// Create request URL
|
// Create request URL
|
||||||
const url = appId ? `/api/apps/${appId}` : '/api/apps';
|
const url = appId ? `/api/apps/${appId}` : '/api/apps';
|
||||||
@@ -2626,26 +2633,29 @@ async function saveApp(event) {
|
|||||||
const method = appId ? 'PUT' : 'POST';
|
const method = appId ? 'PUT' : 'POST';
|
||||||
|
|
||||||
// Send request
|
// Send request
|
||||||
fetch(url, {
|
try {
|
||||||
method: method,
|
const response = await fetch(url, {
|
||||||
body: formData,
|
method: method,
|
||||||
credentials: 'include'
|
headers: {
|
||||||
})
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
.then(response => {
|
},
|
||||||
|
body: urlEncoded.toString(),
|
||||||
|
credentials: 'include'
|
||||||
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Network response was not ok');
|
const errorData = await response.json().catch(() => ({}));
|
||||||
|
throw new Error(errorData.error || 'Network response was not ok');
|
||||||
}
|
}
|
||||||
return response.json();
|
|
||||||
})
|
const data = await response.json();
|
||||||
.then(data => {
|
|
||||||
showNotification('Aplikace byla úspěšně uložena', 'success');
|
showNotification('Aplikace byla úspěšně uložena', 'success');
|
||||||
loadApps();
|
loadApps();
|
||||||
closeAppModal();
|
closeAppModal();
|
||||||
})
|
} catch (error) {
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
showNotification('Chyba při ukládání aplikace', 'error');
|
showNotification(`Chyba při ukládání aplikace: ${error.message}`, 'error');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logout functionality
|
// Logout functionality
|
||||||
|
|||||||
Reference in New Issue
Block a user