This commit is contained in:
Tomas Dvorak
2025-05-30 13:15:14 +02:00
parent f187b092c1
commit 68f3f398f1
2 changed files with 61 additions and 1 deletions
+55
View File
@@ -2284,6 +2284,10 @@ function setupFileInput() {
// Reset form when modal is closed
// Initialize icon picker when the modal is shown
document.getElementById('appModal').addEventListener('show.bs.modal', function () {
// Initialize file input
setupFileInput();
// Initialize icon picker
initIconPicker();
// Set focus to search input when dropdown is shown
@@ -2601,6 +2605,57 @@ async function deleteApp(appId) {
}
}
// Save app function
async function saveApp(event) {
event.preventDefault();
// Get form data
const formData = new FormData(document.getElementById('appForm'));
// Add icon class to form data
const iconClass = document.getElementById('appIcon').value;
if (iconClass) {
formData.append('iconClass', iconClass);
}
// Add icon file if selected
const iconFile = document.getElementById('customIconInput').files[0];
if (iconFile) {
formData.append('icon', iconFile);
}
// Get app ID
const appId = document.getElementById('appId').value;
// Create request URL
const url = appId ? `/api/apps/${appId}` : '/api/apps';
// Set request method
const method = appId ? 'PUT' : 'POST';
// Send request
fetch(url, {
method: method,
body: formData,
credentials: 'include'
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
showNotification('Aplikace byla úspěšně uložena', 'success');
loadApps();
closeAppModal();
})
.catch(error => {
console.error('Error:', error);
showNotification('Chyba při ukládání aplikace', 'error');
});
}
// Logout functionality
document.getElementById('logoutBtn').addEventListener('click', function() {
localStorage.removeItem('token');