diff --git a/admin-dashboard.html b/admin-dashboard.html
index ce1fd88..7f05ea0 100644
--- a/admin-dashboard.html
+++ b/admin-dashboard.html
@@ -1004,11 +1004,12 @@
@@ -1062,7 +1063,62 @@
.logout-btn:hover {
background-color: #c0392b;
}
-
+
+
+
+
Vítejte v administraci
@@ -3046,6 +3102,163 @@ async function loadBanner() {
// Add submission flag at the top of the script
let isSubmitting = false;
+// Setup credentials form
+function setupCredentialsForm() {
+ const credentialsForm = document.getElementById('credentialsForm');
+ if (!credentialsForm) return;
+
+ credentialsForm.addEventListener('submit', async (e) => {
+ e.preventDefault();
+
+ // Prevent multiple submissions
+ if (isSubmitting) return;
+ isSubmitting = true;
+
+ const formData = new FormData(credentialsForm);
+ const currentUsername = formData.get('currentUsername');
+ const currentPassword = formData.get('currentPassword');
+ const newUsername = formData.get('newUsername');
+ const newPassword = formData.get('newPassword');
+ const confirmPassword = formData.get('confirmPassword');
+
+ // Reset previous errors
+ document.querySelectorAll('.form-control').forEach(el => el.classList.remove('border-red-500'));
+ const alertEl = document.getElementById('credentialsAlert');
+ alertEl.classList.add('hidden');
+
+ // Client-side validation
+ let isValid = true;
+
+ if (!currentUsername || !currentPassword) {
+ showError('Vyplňte prosím aktuální přihlašovací údaje.');
+ isValid = false;
+ }
+
+ if (newPassword && newPassword.length < 8) {
+ document.getElementById('newPassword').classList.add('border-red-500');
+ showError('Nové heslo musí mít alespoň 8 znaků.');
+ isValid = false;
+ }
+
+ if (newPassword !== confirmPassword) {
+ document.getElementById('confirmPassword').classList.add('border-red-500');
+ showError('Nová hesla se neshodují.');
+ isValid = false;
+ }
+
+ if (!isValid) {
+ isSubmitting = false;
+ return;
+ }
+
+ // Prepare request data
+ const requestData = {
+ currentUsername,
+ currentPassword,
+ newUsername: newUsername || undefined,
+ newPassword: newPassword || undefined
+ };
+
+ try {
+ const response = await fetch('/api/update-credentials', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${localStorage.getItem('token')}`
+ },
+ body: JSON.stringify(requestData)
+ });
+
+ const data = await response.json();
+
+ if (!response.ok) {
+ throw new Error(data.error || 'Nepodařilo se aktualizovat přihlašovací údaje');
+ }
+
+ // Show success message
+ showSuccess('Přihlašovací údaje byly úspěšně aktualizovány. Budete odhlášeni za 3 sekundy...');
+
+ // Logout after a delay
+ setTimeout(() => {
+ localStorage.removeItem('token');
+ window.location.href = '/login.html';
+ }, 3000);
+
+ } catch (error) {
+ console.error('Chyba při aktualizaci přihlašovacích údajů:', error);
+ showError(error.message || 'Nastala chyba při aktualizaci přihlašovacích údajů');
+ } finally {
+ isSubmitting = false;
+ }
+ });
+
+ function showError(message) {
+ const alertEl = document.getElementById('credentialsAlert');
+ alertEl.textContent = message;
+ alertEl.className = 'bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4';
+ alertEl.classList.remove('hidden');
+ alertEl.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
+ }
+
+ function showSuccess(message) {
+ const alertEl = document.getElementById('credentialsAlert');
+ alertEl.textContent = message;
+ alertEl.className = 'bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4';
+ alertEl.classList.remove('hidden');
+ alertEl.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
+ }
+}
+
+// Setup navigation
+function setupNavigation() {
+ const navLinks = document.querySelectorAll('.nav-link');
+ const sections = document.querySelectorAll('.card[id]');
+
+ // Show section based on hash or default to first section
+ function showSection(sectionId) {
+ // Hide all sections
+ sections.forEach(section => {
+ section.style.display = 'none';
+ });
+
+ // Show selected section
+ const targetSection = document.getElementById(sectionId);
+ if (targetSection) {
+ targetSection.style.display = 'block';
+ } else if (sections.length > 0) {
+ // Default to first section if target not found
+ sections[0].style.display = 'block';
+ }
+
+ // Update active nav link
+ navLinks.forEach(link => {
+ link.classList.toggle('active', link.getAttribute('data-section') === sectionId);
+ });
+
+ // Update URL hash
+ window.location.hash = `#${sectionId}`;
+ }
+
+ // Handle nav link clicks
+ navLinks.forEach(link => {
+ link.addEventListener('click', (e) => {
+ e.preventDefault();
+ const sectionId = link.getAttribute('data-section');
+ showSection(sectionId);
+ });
+ });
+
+ // Handle initial load
+ const initialSection = window.location.hash ? window.location.hash.substring(1) : 'aplikace';
+ showSection(initialSection);
+
+ // Handle browser back/forward
+ window.addEventListener('popstate', () => {
+ const sectionId = window.location.hash ? window.location.hash.substring(1) : 'aplikace';
+ showSection(sectionId);
+ });
+}
+
async function saveBanner(event) {
event.preventDefault();
@@ -4295,6 +4508,12 @@ document.addEventListener('DOMContentLoaded', function() {
// Initialize banner image upload functionality
const dragDropArea = document.getElementById('dragDropArea');
+
+ // Initialize credentials form
+ setupCredentialsForm();
+
+ // Navigation handling
+ setupNavigation();
const uploadImageBtn = document.getElementById('uploadImageBtn');
const bannerImageInput = document.getElementById('bannerImage');
diff --git a/admin.html b/admin.html
index eeaa5e9..b71a2b9 100644
--- a/admin.html
+++ b/admin.html
@@ -4,85 +4,202 @@
Admin Login - PP Kunovice
+
+
@@ -87,6 +88,7 @@