custom-scripts/mccs-it/thermal/public/index.html

226 lines
10 KiB
HTML
Raw Normal View History

2024-09-06 23:26:30 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2024-09-12 17:58:13 +00:00
<title>ITS Thermal Printer</title>
2024-09-10 17:29:16 +00:00
<script src="https://cdn.tailwindcss.com"></script>
2024-09-06 23:26:30 +00:00
</head>
2024-09-10 17:29:16 +00:00
<body class="bg-gray-100 font-sans leading-normal tracking-normal">
2024-09-12 20:46:26 +00:00
<!-- Parent container to hold two columns -->
<div class="flex justify-center mt-10 space-x-4">
<!-- Left column containing the three original sections -->
<div class="flex flex-col space-y-4 max-w-lg">
<!-- ITS Thermal Printer Panel -->
<div class="bg-white p-8 rounded-lg shadow-lg">
<div class="flex justify-center mb-6">
<img src="./itslogo_color.png" alt="ITS Logo" class="h-24 w-auto">
2024-09-10 17:29:16 +00:00
</div>
2024-09-12 20:46:26 +00:00
<h1 class="text-2xl font-bold text-center mb-4" style="color: #1F3C70;">ITS Thermal Printer Panel</h1>
<p class="text-center text-gray-600 mb-6">
Provide the username and student ID in the fields below, then click the Generate button.<br>
A pre-formatted receipt will generate with the information. Click Print at the bottom of the page to print it.
</p>
<form id="printForm" class="space-y-4">
<div>
<label for="username" class="block text-sm font-medium text-gray-700">Username:</label>
<input type="text" id="username" name="username" required
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
</div>
<div>
<label for="studentId" class="block text-sm font-medium text-gray-700">Student ID:</label>
<input type="text" id="studentId" name="studentId" required
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
</div>
<div class="text-center">
<button type="submit" style="background-color: #1F3C70;"
class="w-full text-white py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50">
Generate Receipt
</button>
</div>
</form>
</div>
2024-09-09 20:27:51 +00:00
2024-09-12 20:46:26 +00:00
<!-- Temporary Password Printer -->
<div class="bg-white p-8 rounded-lg shadow-lg">
<h1 class="text-2xl font-bold text-center mb-4" style="color: #1F3C70;">Temporary Password Printer</h1>
<p class="text-center text-gray-600 mb-6">
Provide the temporary password in the field below, then click the Generate button.<br>
A pre-formatted receipt will generate with the information. Click Print at the bottom of the page to print it.
</p>
2024-09-10 17:29:16 +00:00
<div>
2024-09-12 20:46:26 +00:00
<label for="password" class="block text-sm font-medium text-gray-700">Temp Password:</label>
<input type="text" id="password" name="password" required
2024-09-10 17:29:16 +00:00
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
</div>
<div class="text-center">
2024-09-12 20:46:26 +00:00
<button type="submit" id="printTempPw" style="background-color: #1F3C70;"
class="w-full text-white py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 mt-4">
Generate Receipt
2024-09-10 19:42:42 +00:00
</button>
2024-09-10 17:29:16 +00:00
</div>
2024-09-12 20:46:26 +00:00
</div>
2024-09-12 17:58:13 +00:00
</div>
2024-09-12 16:24:02 +00:00
2024-09-12 20:46:26 +00:00
<!-- Right column containing the PDF Viewer -->
<div class="flex flex-col space-y-4 max-w-lg">
<div id="pdfContainer" class="max-w-lg bg-white p-8 rounded-lg shadow-lg text-center">
<h1 class="text-2xl font-bold mb-4" style="color: #1F3C70;">Receipt Preview</h1>
<!-- Refresh Button -->
<button id="refreshPdf"
class="bg-blue-200 hover:bg-blue-700 hover:text-white text-black font-bold py-2 px-4 rounded mb-4">
Refresh PDF
</button>
<!-- Print Button -->
<button id="print"
class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded mb-4">
Print Receipt
</button>
<!-- PDF Viewer -->
<div id="pdfViewer" class="border border-gray-300 p-4 rounded-md"></div>
2024-09-12 16:32:59 +00:00
</div>
2024-09-12 16:24:02 +00:00
2024-09-12 20:46:26 +00:00
<!-- Quick Prints -->
<div class="bg-white p-8 rounded-lg shadow-lg">
<h1 class="text-2xl font-bold text-center mb-4" style="color: #1F3C70;">Quick Prints</h1>
<p class="text-center text-gray-600 mb-6">
Click the button to generate the relevant receipt.<br>
Click Print at the bottom of the page to print it.
</p>
<button id="print-mcc" class="w-full bg-gray-200 text-black py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 mt-2">
Contractor Information
2024-09-12 16:32:59 +00:00
</button>
</div>
2024-09-10 17:29:16 +00:00
</div>
2024-09-12 19:29:44 +00:00
2024-09-12 20:46:26 +00:00
</div>
2024-09-12 19:40:41 +00:00
2024-09-12 19:29:44 +00:00
2024-09-12 16:24:02 +00:00
2024-09-06 23:26:30 +00:00
<script>
2024-09-12 19:29:44 +00:00
function loadPDF() {
fetch('./output.pdf')
.then(response => {
const pdfViewer = document.getElementById('pdfViewer');
pdfViewer.innerHTML = ''; // Clear any previous content
2024-09-12 19:42:38 +00:00
console.log('Emptied PDF Viewer');
2024-09-12 19:29:44 +00:00
if (response.ok) {
// If the PDF exists, reload the iframe
const iframe = document.createElement('iframe');
iframe.src = './output.pdf?' + new Date().getTime(); // Add timestamp to avoid caching
iframe.width = '100%';
iframe.height = '500px'; // Set the height as needed
iframe.classList.add('rounded-md');
pdfViewer.appendChild(iframe);
} else {
// If the PDF does not exist, display a message
pdfViewer.textContent = 'No PDF available';
}
})
.catch(() => {
// Handle errors, such as network issues
document.getElementById('pdfViewer').textContent = 'Error loading PDF';
});
}
// Load the PDF when the page loads
window.onload = loadPDF;
// Add event listener for the "Refresh PDF" button
document.getElementById('refreshPdf').addEventListener('click', loadPDF);
2024-09-10 19:42:42 +00:00
document.getElementById('print-mcc').addEventListener('click', (event) => {
// Send a POST request with the form data to the server
fetch('/print-mcc', {
method: 'POST'
})
2024-09-12 19:40:41 +00:00
.then(response => {
if (response.ok) {
return response.text(); // or .json() if your server returns JSON
} else {
throw new Error('Failed to send print request');
}
})
.then(message => alert(message))
.catch(error => alert('Error: ' + error));
});
document.getElementById('print').addEventListener('click', (event) => {
// Send a POST request with the form data to the server
fetch('/print', {
method: 'POST'
})
2024-09-10 19:42:42 +00:00
.then(response => {
if (response.ok) {
return response.text(); // or .json() if your server returns JSON
} else {
throw new Error('Failed to send print request');
}
})
.then(message => alert(message))
.catch(error => alert('Error: ' + error));
2024-09-12 19:46:57 +00:00
setTimeout(loadPDF, 300);
2024-09-10 19:42:42 +00:00
});
2024-09-09 20:27:51 +00:00
document.getElementById('printForm').addEventListener('submit', (event) => {
event.preventDefault(); // Prevent the form from submitting normally
// Get the form data
const formData = new FormData(event.target);
const username = formData.get('username');
const studentId = formData.get('studentId');
// Send a POST request with the form data to the server
2024-09-10 19:42:42 +00:00
fetch('/print-credentials', {
2024-09-09 20:27:51 +00:00
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: username,
studentId: studentId,
}),
})
.then(response => {
if (response.ok) {
return response.text(); // or .json() if your server returns JSON
} else {
throw new Error('Failed to send print request');
}
})
.then(message => alert(message))
.catch(error => alert('Error: ' + error));
2024-09-12 19:46:57 +00:00
setTimeout(loadPDF, 300);
2024-09-06 23:26:30 +00:00
});
2024-09-12 16:24:02 +00:00
2024-09-12 16:32:59 +00:00
document.getElementById('printTempPw').addEventListener('click', (event) => {
const password = document.getElementById('password').value;
2024-09-12 16:24:02 +00:00
// Send a POST request with the form data to the server
fetch('/print-temp-pw', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
password: password
}),
})
.then(response => {
if (response.ok) {
return response.text(); // or .json() if your server returns JSON
} else {
throw new Error('Failed to send print request');
}
})
.then(message => alert(message))
.catch(error => alert('Error: ' + error));
2024-09-12 19:46:57 +00:00
setTimeout(loadPDF, 300);
2024-09-12 16:24:02 +00:00
});
2024-09-06 23:26:30 +00:00
</script>
</body>
2024-09-09 20:27:51 +00:00
</html>