Add badge to server detail pages

This commit is contained in:
amcmanu3 2023-11-05 12:06:57 -05:00
parent ecb40ee2ec
commit a5f4a68c49
2 changed files with 30 additions and 1 deletions

View File

@ -82,6 +82,9 @@
<span class="mdi mdi-chevron-double-left"></span> <span class="mdi mdi-chevron-double-left"></span>
<span class="mdi mdi-chevron-double-right"></span> <span class="mdi mdi-chevron-double-right"></span>
</button> </button>
&nbsp;&nbsp;&nbsp;
<span class="badge-pill badge-outline-primary" id="server-name-nav" style="display: none;"></span>
{% include notify.html %} {% include notify.html %}

View File

@ -248,12 +248,38 @@
$("#player-body").html(text); $("#player-body").html(text);
} }
//used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security
function getCookie(name) {
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
return r ? r[1] : undefined;
}
const token = getCookie("_xsrf")
$(window).ready(function () { $(window).ready(function () {
console.log("ready!"); console.log("ready!");
//if (webSocket) { //if (webSocket) {
webSocket.on('update_server_details', update_server_details); webSocket.on('update_server_details', update_server_details);
add_server_name();
//} //}
}); });
async function add_server_name(){
let res = await fetch(`/api/v2/servers/${serverId}`, {
method: 'GET',
headers: {
'X-XSRFToken': token
},
});
let responseData = await res.json();
if (responseData.status === "ok") {
console.log(responseData)
$("#server-name-nav").html(`${responseData.data['server_name']}`)
$("#server-name-nav").show();
} else {
bootbox.alert({
title: responseData.error,
message: responseData.error_data
});
}
}
</script> </script>