139 lines
3.7 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);
}
})
});
}
function show_upload_popup()
{
$("#upload_popup").css("display", "flex");
}
function upload()
{
let formData = new FormData();
formData.append('file_upload', $('#file_upload')[0].files[0]);
if ($('input[name="name"]').val().trim() != "") formData.append('name', $('input[name="name"]').val());
if ($('input[name="desc"]').val().trim() != "") formData.append('desc', $('input[name="desc"]').val());
$.ajax
({
url : './res/forum/api/upload_picture.php',
type : 'POST',
data : formData,
processData: false,
contentType: false,
success : function(result)
{
switch (result.status)
{
case 0:
2024-05-24 18:23:14 +02:00
alert(result.text);
show("home");
break;
case 1:
2024-05-24 18:23:14 +02:00
alert("Nebyl nahrán soubor!\nToto může znamenat že se snažíte nahrát soubor větší než 50MB!");
break;
case 2:
alert("Nebyl vyplněn název příspěvku!");
break;
case 3:
alert("Neplatný formát!");
break;
2024-05-24 18:23:14 +02:00
case 4:
alert("Příliš velký obrázek!\nMaximální velikost je 5MB!");
}
}
});
2024-05-16 21:07:07 +02:00
}