Neue Helper: - _renderCardPreview(): Gemeinsamer Helper für Agent/Session-Card-Vorschau (ersetzt renderAgentInCard + renderSessionSelectCard Duplikate) - withButtonLoading(btn, text, fn): Eliminiert ~15x identisches disable/text/try/finally/reset Pattern in allen Pages - formatDate(): Nach ui-helpers.js verschoben (war in dashboard.js) - createMDE(): maxHeight-Option hinzugefügt Dedupliziert: - handleStreamEvent: 12 Preparer/Review/Finalizer cases → 7 durch case-Grouping (start/text/tool_use shared) - _escCmdAttr() entfernt → nutzt jetzt esc() aus ui-helpers.js - feInitEasyMDE() nutzt jetzt createMDE() statt eigener EasyMDE-Init Betroffene Dateien: ui-helpers.js, chat.js, commands-ui.js, file-explorer.js, dashboard.js, session-page.js, cronjob-page.js, profile-page.js, admin-page.js, server-settings-page.js, settings-page.js
92 lines
2.8 KiB
JavaScript
92 lines
2.8 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', () => withButtonLoading(saveBtn, 'Speichern...', async () => {
|
||
try {
|
||
var updated = await apiUpdateProfile({
|
||
displayName: displayNameInput.value.trim(),
|
||
persona: _profileMde.value().trim()
|
||
});
|
||
if (currentUser) currentUser.displayName = updated.displayName;
|
||
showToast('Profil gespeichert');
|
||
} catch (err) {
|
||
showToast(err.message, 'error');
|
||
}
|
||
}));
|
||
|
||
// 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;
|
||
}
|
||
|
||
await withButtonLoading(passwordBtn, 'Ändern...', async () => {
|
||
try {
|
||
await apiChangePassword(currentPw, newPw);
|
||
currentPwInput.value = '';
|
||
newPwInput.value = '';
|
||
confirmPwInput.value = '';
|
||
showToast('Passwort geändert');
|
||
} catch (err) {
|
||
showToast(err.message, 'error');
|
||
}
|
||
});
|
||
});
|
||
|
||
// Logout
|
||
logoutBtn.addEventListener('click', async function() {
|
||
await apiLogout();
|
||
currentUser = null;
|
||
navigateTo('login');
|
||
});
|
||
},
|
||
destroy() {
|
||
if (_profileMde) {
|
||
_profileMde.toTextArea();
|
||
_profileMde = null;
|
||
}
|
||
}
|
||
});
|