91 lines
2.4 KiB
JavaScript
Raw Normal View History

2024-05-16 21:17:40 +02:00
let main_panel_buffer = null;
2024-05-16 21:07:07 +02:00
function show(file)
{
2024-05-16 21:17:40 +02:00
if (main_panel_buffer == null) main_panel_buffer = document.getElementById("main_panel").innerHTML;
2024-05-16 21:07:07 +02:00
$.ajax
({
2024-05-22 16:18:18 +02:00
url: "./res/forum/" + file + "/" + file + ".html",
2024-05-16 21:07:07 +02:00
dataType: "html",
success: function(data)
{
2024-05-16 21:17:40 +02:00
$("#main_panel").html(main_panel_buffer + data);
2024-05-16 21:07:07 +02:00
}
});
2024-05-22 18:19:19 +02:00
}
2024-05-22 18:25:45 +02:00
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)
2024-05-22 18:19:19 +02:00
{
let am_i_admin = await is_admin();
2024-05-22 18:19:19 +02:00
$.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>
2024-05-22 18:19:19 +02:00
Bio: <input id="bio" class="editable" type="text" value="${result.bio}"><br>`;
$(id).html(output + postfix);
}
});
2024-05-22 18:40:36 +02:00
}
async function update_user(old_username, username, nickname, admin, sex, bio, refresh)
2024-05-22 18:40:36 +02:00
{
let am_i_admin = await is_admin();
2024-05-22 18:40:36 +02:00
$.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 : ""),
2024-05-22 18:40:36 +02:00
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);
}
})
});
2024-05-16 21:07:07 +02:00
}