working on user settings

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-07-21 23:57:42 +02:00
parent 03a0ba139f
commit f078491344
13 changed files with 252 additions and 17 deletions

View File

@@ -1,11 +1,27 @@
var user = null;
async function handleUser(response){
if (response.status == UNAUTHORIZED) {
window.location.href = 'login.html?return_to='+encodeURI(window.location.href);
return;
}
var user = await response.json();
// TODO: load navigation
if (response.ok){
user = await response.json();
fetch(web+"/navigation.html").then(handleNavigation);
}
}
async function handleNavigation(response){
if (response.ok){
var content = await response.text();
var nav = document.getElementsByTagName('nav')[0];
nav.innerHTML = content;
var links = nav.getElementsByTagName('a');
for (var index = 0; index < links.length; index++){
var link = links[index];
var clazz = link.hasAttribute('class') ? link.getAttribute("class") : null;
if (clazz != null && !user.permissions.includes(clazz)) nav.removeChild(link);
}
}
}
fetch(api+"/user",{method:'POST'}).then(handleUser);