2024-05-22 21:20:46 +02:00

91 lines
2.4 KiB
JavaScript

let main_panel_buffer = null;
function show(file)
{
if (main_panel_buffer == null) main_panel_buffer = document.getElementById("main_panel").innerHTML;
$.ajax
({
url: "./res/forum/" + file + "/" + file + ".html",
dataType: "html",
success: function(data)
{
$("#main_panel").html(main_panel_buffer + data);
}
});
}
function selection(type, value)
{
return new Promise(function(resolve)
{
$.ajax
({
url: "./res/forum/admin/" + type + "_selection.html",
dataType: "html",
success: function(result)
{
resolve(result.replace("value=\"" + value, "selected value=\"" + value));
}
})
});
}
async function inject_info(id, username, postfix)
{
let am_i_admin = await is_admin();
$.ajax
({
url: "./res/forum/api/user_info.php?username=" + username,
success: async function(result)
{
let admin_select = await selection("admin", result.admin);
let sex_select = await selection("sex", result.sex);
let output =
((am_i_admin) ? `Uživatelské jméno: <input id="username" class="editable" type="text" value="${result.username}"><br>` : ``) +
`Přezdívka: <input id="nickname" class="editable" type="text" value="${result.nickname}"><br>` +
((am_i_admin) ? `Admin: ${admin_select}<br>` : ``) +
`Pohlaví: ${sex_select}<br>
Bio: <input id="bio" class="editable" type="text" value="${result.bio}"><br>`;
$(id).html(output + postfix);
}
});
}
async function update_user(old_username, username, nickname, admin, sex, bio, refresh)
{
let am_i_admin = await is_admin();
$.ajax
({
url: "./res/forum/api/update_user.php" +
"?old_username=" + old_username +
"&nickname=" + nickname +
"&sex=" + sex +
"&bio=" + bio +
((am_i_admin) ? "&username=" + username +
"&admin=" + admin : ""),
success: function(result)
{
show(refresh);
}
});
}
function is_admin()
{
return new Promise(function(resolve)
{
$.ajax
({
url: "./res/forum/api/is_admin.php",
success: function(result)
{
resolve(result.admin);
}
})
});
}