80 lines
2.5 KiB
JavaScript
80 lines
2.5 KiB
JavaScript
const appUrl = window.CMBNET_APP_URL || ((path) => `/${String(path || '').replace(/^\/+/, '')}`);
|
|
const tenant = window.CMBNET_TENANT || '';
|
|
const apiBase = appUrl(`${tenant}/admin/api`);
|
|
|
|
function changeRole(accountId, role) {
|
|
fetch(`${apiBase}/accounts/${accountId}/role`, {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({role: role})
|
|
}).then(r => r.json()).then(data => {
|
|
if (data.success) alert('Rolle geändert');
|
|
});
|
|
}
|
|
|
|
function openPasswordModal(accountId) {
|
|
document.getElementById('pwdAccountId').value = accountId;
|
|
document.getElementById('passwordModal').showModal();
|
|
}
|
|
|
|
function closePasswordModal() {
|
|
document.getElementById('passwordModal').close();
|
|
document.getElementById('newPassword').value = '';
|
|
}
|
|
|
|
function resetPassword() {
|
|
const accountId = document.getElementById('pwdAccountId').value;
|
|
const password = document.getElementById('newPassword').value;
|
|
fetch(`${apiBase}/accounts/${accountId}/password`, {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({password: password})
|
|
}).then(r => r.json()).then(data => {
|
|
if (data.success) {
|
|
alert('Passwort zurückgesetzt');
|
|
closePasswordModal();
|
|
} else {
|
|
alert(data.error);
|
|
}
|
|
});
|
|
}
|
|
|
|
function deleteAccount(accountId) {
|
|
if (!confirm('Account wirklich löschen?')) return;
|
|
fetch(`${apiBase}/accounts/${accountId}`, {
|
|
method: 'DELETE'
|
|
}).then(r => r.json()).then(data => {
|
|
if (data.success) {
|
|
location.reload();
|
|
}
|
|
});
|
|
}
|
|
|
|
function openCreateAccountModal() {
|
|
document.getElementById('createAccountModal').showModal();
|
|
}
|
|
|
|
function closeCreateAccountModal() {
|
|
document.getElementById('createAccountModal').close();
|
|
document.getElementById('newAccountName').value = '';
|
|
document.getElementById('newAccountPassword').value = '';
|
|
}
|
|
|
|
function createAccount() {
|
|
const name = document.getElementById('newAccountName').value;
|
|
const password = document.getElementById('newAccountPassword').value;
|
|
const role = document.getElementById('newAccountRole').value;
|
|
fetch(`${apiBase}/accounts`, {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({name, password, role})
|
|
}).then(r => r.json()).then(data => {
|
|
if (data.success) {
|
|
alert('Account angelegt');
|
|
location.reload();
|
|
} else {
|
|
alert(data.error);
|
|
}
|
|
});
|
|
}
|