Neue Helper-Funktionen: - _openCardMenu(trigger, dropdown): Card-Menü-Positionierung (4x in dashboard.js dedupliziert) - _createModal(title, extraClasses): Modal-Boilerplate (3 Modals in modals.js dedupliziert) - _openPickerModal(title, items, currentId, onSelect, opts): Picker-Modal (Agent + Session zusammengeführt) - createMDE(element, opts): EasyMDE-Initialisierung (3x in agent/session/profile-page dedupliziert) Weitere Bereinigungen: - _formatReplyTimestamp() entfernt, durch _formatTimestamp() ersetzt (reply.js + chat.js) - showFormMessage/showPageMessage in admin-page.js durch showToast() ersetzt - Inline-Nachrichten (profileMessage, profilePasswordMessage, adminMessage, adminFormMessage) durch Toast-Notifications ersetzt, zugehörige HTML-Elemente entfernt - profile-page.js: messageDiv/passwordMessageDiv-Logik durch showToast() ersetzt 11 Dateien, -210 Zeilen netto
109 lines
3.1 KiB
JavaScript
109 lines
3.1 KiB
JavaScript
// ── Profile Page ──
|
||
|
||
var _profileMde = null;
|
||
|
||
registerPage('profile', {
|
||
async init() {
|
||
var profile = await apiGetProfile();
|
||
if (!profile) return;
|
||
|
||
var usernameInput = document.getElementById('profileUsername');
|
||
var displayNameInput = document.getElementById('profileDisplayName');
|
||
var defaultPathInput = document.getElementById('profileDefaultPath');
|
||
var personaInput = document.getElementById('profilePersona');
|
||
var saveBtn = document.getElementById('profileSaveBtn');
|
||
|
||
// EasyMDE für Persona
|
||
_profileMde = createMDE(personaInput, {
|
||
initialValue: profile.persona || '',
|
||
minHeight: '150px',
|
||
placeholder: 'Beschreibe dich selbst – Name, Rolle, Präferenzen, Kommunikationsstil...'
|
||
});
|
||
|
||
var currentPwInput = document.getElementById('profileCurrentPassword');
|
||
var newPwInput = document.getElementById('profileNewPassword');
|
||
var confirmPwInput = document.getElementById('profileConfirmPassword');
|
||
var passwordBtn = document.getElementById('profilePasswordBtn');
|
||
|
||
var logoutBtn = document.getElementById('profileLogoutBtn');
|
||
|
||
// Felder befüllen
|
||
usernameInput.value = profile.username || '';
|
||
displayNameInput.value = profile.displayName || '';
|
||
defaultPathInput.value = profile.defaultPath || '';
|
||
|
||
// Profil speichern
|
||
saveBtn.addEventListener('click', async function() {
|
||
saveBtn.disabled = true;
|
||
saveBtn.textContent = 'Speichern...';
|
||
|
||
try {
|
||
var updated = await apiUpdateProfile({
|
||
displayName: displayNameInput.value.trim(),
|
||
persona: _profileMde.value().trim()
|
||
});
|
||
|
||
// currentUser aktualisieren
|
||
if (currentUser) {
|
||
currentUser.displayName = updated.displayName;
|
||
}
|
||
|
||
showToast('Profil gespeichert');
|
||
} catch (err) {
|
||
showToast(err.message, 'error');
|
||
} finally {
|
||
saveBtn.disabled = false;
|
||
saveBtn.textContent = 'Speichern';
|
||
}
|
||
});
|
||
|
||
// Passwort ändern
|
||
passwordBtn.addEventListener('click', async function() {
|
||
var currentPw = currentPwInput.value;
|
||
var newPw = newPwInput.value;
|
||
var confirmPw = confirmPwInput.value;
|
||
|
||
if (!currentPw || !newPw) {
|
||
showToast('Alle Felder ausfüllen', 'error');
|
||
return;
|
||
}
|
||
|
||
if (newPw !== confirmPw) {
|
||
showToast('Neue Passwörter stimmen nicht überein', 'error');
|
||
return;
|
||
}
|
||
|
||
passwordBtn.disabled = true;
|
||
passwordBtn.textContent = 'Ändern...';
|
||
|
||
try {
|
||
await apiChangePassword(currentPw, newPw);
|
||
|
||
currentPwInput.value = '';
|
||
newPwInput.value = '';
|
||
confirmPwInput.value = '';
|
||
|
||
showToast('Passwort geändert');
|
||
} catch (err) {
|
||
showToast(err.message, 'error');
|
||
} finally {
|
||
passwordBtn.disabled = false;
|
||
passwordBtn.textContent = 'Passwort ändern';
|
||
}
|
||
});
|
||
|
||
// Logout
|
||
logoutBtn.addEventListener('click', async function() {
|
||
await apiLogout();
|
||
currentUser = null;
|
||
navigateTo('login');
|
||
});
|
||
},
|
||
destroy() {
|
||
if (_profileMde) {
|
||
_profileMde.toTextArea();
|
||
_profileMde = null;
|
||
}
|
||
}
|
||
});
|