2020-07-04 19:42:13 +01:00

81 lines
2.9 KiB
Cheetah

{{define "content"}}
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Servers</h4>
</div>
<div class="card-body" id="card">
<div class="card-body table-responsive">
<p class="center-align white" style="padding-top: 50px; font-size: 16px; display: none" id="no-guilds">
You are not the admin of any guilds that the bot is in. Click below to invite the bot:
<br/>
<a href="https://invite.ticketsbot.net"><button class="btn btn-primary btn-fill"><i class="fas fa-plus"></i> Invite</button></a>
</p>
<table class="table table-hover table-striped" id="guild-table" style="display: none">
<thead>
<th>Server Name</th>
</thead>
<tbody id="guild-container">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
async function getPermissionLevels(guilds) {
const res = await axios.get('/user/permissionlevel?guilds=' + guilds.map(guild => guild.id).join(","));
if (res.status !== 200 || !res.data.success) {
showToast('Error', res.data.error);
return;
}
return res.data.levels;
}
async function loadData() {
const res = await axios.get('/user/guilds');
const permissionLevels = await getPermissionLevels(res.data);
console.log(permissionLevels)
if (res.data.length > 0) {
document.getElementById('guild-table').style.display = 'table';
const container = document.getElementById('guild-container');
for (guild of res.data) {
const tr = document.createElement('tr');
const td = document.createElement('td');
const link = document.createElement('a');
// admin
if (permissionLevels[guild.id] === 2) {
link.href = `/manage/${guild.id}/settings`;
} else {
link.href = `/manage/${guild.id}/logs`;
}
link.classList.add('server');
link.appendChild(document.createTextNode(guild.name));
td.appendChild(link);
tr.appendChild(td);
container.appendChild(tr);
}
} else {
document.getElementById('no-guilds').style.display = 'block';
}
}
withLoadingScreen(loadData);
</script>
{{end}}