Load user data from API when opening profile modal
This commit is contained in:
+24
-1
@@ -260,7 +260,30 @@ function filterUsers(searchTerm) {
|
||||
});
|
||||
}
|
||||
|
||||
function openProfileModal() {
|
||||
async function openProfileModal() {
|
||||
const sessionid = getCookie('sessionid');
|
||||
if (!sessionid) { alert('Bitte melden Sie sich an.'); return; }
|
||||
try {
|
||||
const response = await fetch(USER_URL, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ sessionid: sessionid })
|
||||
});
|
||||
console.log('openProfileModal response:', response.status, await response.clone().json());
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
console.log('openProfileModal data:', data);
|
||||
if (data.data && Array.isArray(data.data) && data.data.length > 0) {
|
||||
const user = data.data[0];
|
||||
document.getElementById('profile-username').value = user.username || '';
|
||||
document.getElementById('profile-name').value = user.name || '';
|
||||
document.getElementById('profile-llc').value = user.company || '';
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('openProfileModal error:', error);
|
||||
alert('Fehler beim Laden des Profils.');
|
||||
}
|
||||
document.getElementById('profile-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user