';
if (!isActive) html += ' ';
if (!isInactive) html += ' ';
html += ' ';
html += ' ';
if (!s.enabled) html += ' ';
if (s.enabled) html += ' ';
html += '
';
});
if (!html) html = '
No services match the filter.
';
tbody.innerHTML = html;
renderPagination(list, page);
}
function renderPagination(list, page) {
const totalPages = Math.ceil(list.length / perPage) || 1;
const container = document.getElementById('servicesPagination');
let html = '';
for (let p = 1; p <= totalPages && p <= 15; p++) {
html += '';
}
if (totalPages > 15) html += '...';
container.innerHTML = html + ' ' + list.length + ' services';
container.querySelectorAll('button').forEach(btn => {
const p = parseInt(btn.textContent);
if (!isNaN(p)) {
btn.onclick = function() { renderPage(list, p); };
}
});
}
applyFilters();
function getCsrfToken() { return document.querySelector('meta[name="csrf-token"]')?.content || ''; }
function serviceAction(action, service) {
fetch('/servers/' + serverId + '/services', {
method:'POST',
headers:{'Content-Type':'application/x-www-form-urlencoded','X-CSRF-Token':getCsrfToken()},
body:'action='+action+'&service='+encodeURIComponent(service)+'&_csrf_token='+encodeURIComponent(getCsrfToken()),
})
.then(r=>r.json()).then(d=>{
showToast(d.success?'success':'error', d.message);
if (d.output) {
document.getElementById('srTitle').textContent = d.success ? 'Success' : 'Error';
document.getElementById('srMessage').textContent = d.message;
document.getElementById('srOutputText').textContent = d.output;
document.getElementById('srOutput').style.display = 'block';
document.getElementById('serviceResultModal').style.display = 'flex';
}
setTimeout(() => location.reload(), 1500);
})
.catch(err => showToast('error', 'Request failed'));
}
function closeSrModal() {
document.getElementById('serviceResultModal').style.display = 'none';
document.getElementById('srOutput').style.display = 'none';
}
function escHtml(s) { const d=document.createElement('div'); d.textContent=s; return d.innerHTML; }
document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeSrModal(); });