59 lines
2.5 KiB
HTML
59 lines
2.5 KiB
HTML
{# Unified ban modal. Include once per page. Use: KR.openBanModal(pid, username) #}
|
|
<div class="kr-modal-backdrop" id="kr-ban-modal">
|
|
<div class="kr-modal" style="position:relative">
|
|
<button type="button" class="kr-modal-close" onclick="KR.closeModal('kr-ban-modal')">×</button>
|
|
<h3>Ban <span id="kr-ban-name">Player</span></h3>
|
|
<input type="hidden" id="kr-ban-pid">
|
|
<div class="form-group">
|
|
<label>Reason</label>
|
|
<input type="text" id="kr-ban-reason" placeholder="Rule violation..." maxlength="256">
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Duration</label>
|
|
<select id="kr-ban-duration">
|
|
<option value="1">1 hour</option>
|
|
<option value="24" selected>1 day</option>
|
|
<option value="168">1 week</option>
|
|
<option value="720">30 days</option>
|
|
{% if SCOPE_ADMIN in scopes %}
|
|
<option value="0">Permanent</option>
|
|
{% endif %}
|
|
</select>
|
|
</div>
|
|
<div class="form-group" style="display:flex;align-items:center;gap:.5rem">
|
|
<input type="checkbox" id="kr-ban-drop-ws" checked style="width:auto">
|
|
<label for="kr-ban-drop-ws" style="margin:0">Disconnect WebSocket immediately</label>
|
|
</div>
|
|
<div class="kr-modal-footer">
|
|
<button class="kr-btn kr-btn-ghost" type="button" onclick="KR.closeModal('kr-ban-modal')">Cancel</button>
|
|
<button class="kr-btn kr-btn-red" type="button" onclick="KR.confirmBan()">Ban Player</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
(function () {
|
|
if (window.openBanModal) return;
|
|
window.openBanModal = function (pid, username) {
|
|
document.getElementById('kr-ban-pid').value = pid;
|
|
document.getElementById('kr-ban-name').textContent = username || ('#' + pid);
|
|
document.getElementById('kr-ban-reason').value = '';
|
|
KR.openModal('kr-ban-modal');
|
|
};
|
|
KR.confirmBan = async function () {
|
|
const pid = parseInt(document.getElementById('kr-ban-pid').value);
|
|
const reason = document.getElementById('kr-ban-reason').value.trim() || 'Rule violation';
|
|
const duration = parseInt(document.getElementById('kr-ban-duration').value);
|
|
const drop_ws = document.getElementById('kr-ban-drop-ws').checked;
|
|
const d = await KR.apiPost('/admin/api/ban/' + pid, { reason, duration_hours: duration, drop_ws });
|
|
if (d.ok) {
|
|
KR.toast('Player banned');
|
|
KR.closeModal('kr-ban-modal');
|
|
if (typeof window.onBanSuccess === 'function') window.onBanSuccess(pid);
|
|
else setTimeout(() => location.reload(), 600);
|
|
} else {
|
|
KR.toast(d.error || 'Error', 'error');
|
|
}
|
|
};
|
|
})();
|
|
</script>
|