const alertBox = (type, message) => { const alert = document.getElementById('message'); alert.classList.add(type); alert.innerText = message; alert.style.display = 'block'; }; // Set expiresTimestamp to the time in const ban.expiresTimestamp (convert from js date number to local time string that conforms with html form values) if (ban.expiresTimestamp !== null) { const expiresTimestamp = document.getElementById('expiresTimestamp').value; const expiresDate = new Date(ban.expiresTimestamp) document.getElementById('expiresTimestamp').value = new Date(expiresDate.getTime() - (expiresDate.getTimezoneOffset() * 60000)).toISOString().slice(0, 16); } var reasonFlags = {}; fetch('/api/v1/info') .then(response => response.json()) .then(data => { reasonFlags = data.reasonFlags; }) .catch(error => { console.error('Error:', error); }); document.getElementById('banForm').addEventListener('submit', function (event) { event.preventDefault(); // Combine flag values const checkboxes = document.querySelectorAll('.flag-checkbox'); let combinedFlags = 0; checkboxes.forEach(checkbox => { if (checkbox.checked) { combinedFlags |= parseInt(checkbox.value); } }); document.getElementById('reasonsFlag').value = combinedFlags; const data = Object.fromEntries(new FormData(event.target)); if (data.expires) { const expiresDate = new Date(data.expiresTimestamp); data.expiresTimestamp = Math.floor(expiresDate.getTime()); } if ((!data.robloxId && !data.discordId)) { alertBox('alert-danger', 'Please enter a Roblox ID or Discord ID.'); return; } fetch(event.target.action, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(result => { if (result.success) { console.log('Success:', result); // Handle success (e.g., show a success message, redirect, etc.) window.location.href = '/admin'; } else { console.error('Error:', result.message); alertBox('alert-danger', 'An error has occurred: ' + result.message); } }) .catch(error => { console.error('Error:', error); alertBox('alert-danger', 'An error has occurred. Please contact support.\n' + error); // Handle error (e.g., show an error message) }); });