Merge pull request #171 from LD-Reborn/140-cleanup-add-a-script-for-shared-helper-functions

140 cleanup add a script for shared helper functions
This commit is contained in:
LD50
2025-10-26 08:23:22 +01:00
committed by GitHub
8 changed files with 155 additions and 297 deletions

View File

@@ -22,10 +22,10 @@
<data name="Location ID" xml:space="preserve">
<value>Ort ID</value>
</data>
<data name="Location name" xml:space="preserve">
<data name="Location Name" xml:space="preserve">
<value>Ort Name</value>
</data>
<data name="Room number" xml:space="preserve">
<data name="Room Number" xml:space="preserve">
<value>Raumnummer</value>
</data>
<data name="Seat" xml:space="preserve">
@@ -61,4 +61,25 @@
<data name="Location creation failed" xml:space="preserve">
<value>Erstellung des Ortes ist fehlgeschlagen</value>
</data>
<data name="Edit Location" xml:space="preserve">
<value>Ort anpassen</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Abbrechen</value>
</data>
<data name="Save changes" xml:space="preserve">
<value>Sitzplatz</value>
</data>
<data name="Create" xml:space="preserve">
<value>Erstellen</value>
</data>
<data name="DeleteLocationConfirmation" xml:space="preserve">
<value>Sind Sie sich sicher, dass Sie den Ort {0} löschen möchten?</value>
</data>
<data name="Yes, Delete" xml:space="preserve">
<value>Ja, löschen</value>
</data>
<data name="Confirm Delete" xml:space="preserve">
<value>Löschen bestätigen</value>
</data>
</root>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, ...</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, ...</value>
</resheader>
<data name="DeleteLocationConfirmation" xml:space="preserve">
<value>Are you sure you want to delete the location {0}?</value>
</data>
</root>

View File

@@ -122,32 +122,6 @@ document.addEventListener('DOMContentLoaded', () => {
<script>
function createToastContainer() {
const container = document.createElement('div');
container.id = 'toastContainer';
container.className = 'toast-container position-fixed bottom-0 end-0 p-3';
document.body.appendChild(container);
return container;
}
// Simple toast helper
function showToast(message, type) {
const toastContainer = document.getElementById('toastContainer') || createToastContainer();
const toast = document.createElement('div');
toast.className = `toast align-items-center text-white bg-${type} border-0`;
toast.role = 'alert';
toast.innerHTML = `
<div class="d-flex">
<div class="toast-body">${message}</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
</div>
`;
toastContainer.appendChild(toast);
const bsToast = new bootstrap.Toast(toast, { delay: 3000 });
bsToast.show();
toast.addEventListener('hidden.bs.toast', () => toast.remove());
}
document.addEventListener('DOMContentLoaded', () => {
const deleteModal = document.getElementById('deleteModal');
let currentButton = null; // The delete button that opened the modal
@@ -680,72 +654,6 @@ document.addEventListener('DOMContentLoaded', () => {
<script src="https://cdn.jsdelivr.net/npm/jsbarcode@3.11.6/dist/JsBarcode.all.min.js" defer></script>
<script>
function downloadBarcode(svgId, filename = "barcode.png") {
const svg = document.getElementById(svgId);
const serializer = new XMLSerializer();
const svgString = serializer.serializeToString(svg);
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
// Optionally set canvas size
const bbox = svg.getBBox();
canvas.width = bbox.width + 20; // padding
canvas.height = bbox.height + 20;
const img = new Image();
const svgBlob = new Blob([svgString], { type: "image/svg+xml;charset=utf-8" });
const url = URL.createObjectURL(svgBlob);
img.onload = () => {
ctx.drawImage(img, 0, 0);
URL.revokeObjectURL(url);
const pngUrl = canvas.toDataURL("image/png");
const a = document.createElement("a");
a.href = pngUrl;
a.download = filename;
a.click();
};
img.src = url;
}
function printBarcode(svgId) {
const svg = document.getElementById(svgId);
if (!svg) return;
// Serialize the SVG
const serializer = new XMLSerializer();
const svgString = serializer.serializeToString(svg);
// Open a new window for printing
const printWindow = window.open('', '_blank');
printWindow.document.write(`
<html>
<head>
<title>Print Barcode</title>
<style>
body { text-align: center; margin: 0; padding: 20px; }
svg { width: 300px; height: auto; }
</style>
</head>
<body>
${svgString}
</body>
</html>
`);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
function idToEAN13(id) {
const padded = id.toString().padStart(12, "0"); // 12 digits
return padded;
}
document.addEventListener('DOMContentLoaded', () => {
const rows = document.querySelectorAll('.asset-row');
const viewModal = document.getElementById('viewAssetModal');

View File

@@ -90,33 +90,6 @@
<script>
// Simple toast helper
function showToast(message, type) {
const toastContainer = document.getElementById('toastContainer') || createToastContainer();
const toast = document.createElement('div');
toast.className = `toast align-items-center text-white bg-${type} border-0`;
toast.role = 'alert';
toast.innerHTML = `
<div class="d-flex">
<div class="toast-body">${message}</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
</div>
`;
toastContainer.appendChild(toast);
const bsToast = new bootstrap.Toast(toast, { delay: 3000 });
bsToast.show();
toast.addEventListener('hidden.bs.toast', () => toast.remove());
}
function createToastContainer() {
const container = document.createElement('div');
container.id = 'toastContainer';
container.className = 'toast-container position-fixed bottom-0 end-0 p-3';
document.body.appendChild(container);
return container;
}
document.addEventListener('DOMContentLoaded', () => {
const deleteModal = document.getElementById('deleteModal');
let currentButton = null; // The delete button that opened the modal

View File

@@ -64,99 +64,6 @@
<script defer>
function createToastContainer() {
const container = document.createElement('div');
container.id = 'toastContainer';
container.className = 'toast-container position-fixed bottom-0 end-0 p-3';
document.body.appendChild(container);
return container;
}
// Simple toast helper
function showToast(message, type) {
const toastContainer = document.getElementById('toastContainer') || createToastContainer();
const toast = document.createElement('div');
toast.className = `toast align-items-center text-white bg-${type} border-0`;
toast.role = 'alert';
toast.innerHTML = `
<div class="d-flex">
<div class="toast-body">${message}</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
</div>
`;
toastContainer.appendChild(toast);
const bsToast = new bootstrap.Toast(toast, { delay: 3000 });
bsToast.show();
toast.addEventListener('hidden.bs.toast', () => toast.remove());
}
function downloadBarcode(svgId, filename = "barcode.png") {
const svg = document.getElementById(svgId);
const serializer = new XMLSerializer();
const svgString = serializer.serializeToString(svg);
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
// Optionally set canvas size
const bbox = svg.getBBox();
canvas.width = bbox.width + 20; // padding
canvas.height = bbox.height + 20;
const img = new Image();
const svgBlob = new Blob([svgString], { type: "image/svg+xml;charset=utf-8" });
const url = URL.createObjectURL(svgBlob);
img.onload = () => {
ctx.drawImage(img, 0, 0);
URL.revokeObjectURL(url);
const pngUrl = canvas.toDataURL("image/png");
const a = document.createElement("a");
a.href = pngUrl;
a.download = filename;
a.click();
};
img.src = url;
}
function printBarcode(svgId) {
const svg = document.getElementById(svgId);
if (!svg) return;
// Serialize the SVG
const serializer = new XMLSerializer();
const svgString = serializer.serializeToString(svg);
// Open a new window for printing
const printWindow = window.open('', '_blank');
printWindow.document.write(`
<html>
<head>
<title>Print Barcode</title>
<style>
body { text-align: center; margin: 0; padding: 20px; }
svg { width: 300px; height: auto; }
</style>
</head>
<body>
${svgString}
</body>
</html>
`);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
function idToEAN13(id) {
const padded = id.toString().padStart(12, "0"); // 12 digits
return padded;
}
async function onScanSuccess(decodedText, decodedResult) {
const rawDecoded = decodedText;
decodedText = decodedText.substr(0,11).replace(/^0+/, '');

View File

@@ -1,3 +1,4 @@
@using Microsoft.AspNetCore.Html
@using Microsoft.AspNetCore.Mvc.Localization
@using Berufsschule_HAM.Models
@model LocationsIndexViewModel
@@ -21,8 +22,8 @@
<thead>
<tr>
<th>@T["Location ID"]</th>
<th>@T["Location name"]</th>
<th>@T["Room number"]</th>
<th>@T["Location Name"]</th>
<th>@T["Room Number"]</th>
<th>@T["Seat"]</th>
<th>@T["Action"]</th>
</tr>
@@ -68,52 +69,24 @@
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-danger text-white">
<h5 class="modal-title" id="deleteModalLabel">Confirm Delete</h5>
<h5 class="modal-title" id="deleteModalLabel">@T["Confirm Delete"]</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Are you sure you want to delete the location <strong id="locationName"></strong> (ID: <span id="locationId"></span>)?</p>
<p>
@T["DeleteLocationConfirmation", new HtmlString("<strong id=\"locationId\"></strong>")]
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@T["Cancel"]</button>
<form id="deleteForm" method="post" action="">
<button type="submit" class="btn btn-danger">Yes, Delete</button>
<button type="submit" class="btn btn-danger">@T["Yes, Delete"]</button>
</form>
</div>
</div>
</div>
</div>
<script defer>
function createToastContainer() {
const container = document.createElement('div');
container.id = 'toastContainer';
container.className = 'toast-container position-fixed bottom-0 end-0 p-3';
document.body.appendChild(container);
return container;
}
// Simple toast helper
function showToast(message, type) {
const toastContainer = document.getElementById('toastContainer') || createToastContainer();
const toast = document.createElement('div');
toast.className = `toast align-items-center text-white bg-${type} border-0`;
toast.role = 'alert';
toast.innerHTML = `
<div class="d-flex">
<div class="toast-body">${message}</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
</div>
`;
toastContainer.appendChild(toast);
const bsToast = new bootstrap.Toast(toast, { delay: 3000 });
bsToast.show();
toast.addEventListener('hidden.bs.toast', () => toast.remove());
}
</script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const deleteModal = document.getElementById('deleteModal');
@@ -125,7 +98,6 @@
const locationName = currentButton.getAttribute('data-location-name');
deleteModal.querySelector('#locationId').textContent = locationId;
deleteModal.querySelector('#locationName').textContent = locationName;
// Store the delete URL for later use
deleteModal.querySelector('#deleteForm').dataset.url = `/Locations/Delete?cn=${locationId}`;
@@ -178,7 +150,7 @@
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-warning text-dark">
<h5 class="modal-title" id="editModalLabel">Edit Location</h5>
<h5 class="modal-title" id="editModalLabel">@T["Edit Location"]</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form id="editForm">
@@ -186,23 +158,23 @@
<input type="hidden" id="editLocationId" name="LocationID">
<div class="mb-3">
<label for="editLocationName" class="form-label">Location Name</label>
<label for="editLocationName" class="form-label">@T["Location Name"]</label>
<input type="text" class="form-control" id="editLocationName" name="LocationName" required>
</div>
<div class="mb-3">
<label for="editRoomNumber" class="form-label">Room Number</label>
<label for="editRoomNumber" class="form-label">@T["Room Number"]</label>
<input type="text" class="form-control" id="editRoomNumber" name="RoomNumber">
</div>
<div class="mb-3">
<label for="editSeat" class="form-label">Seat</label>
<label for="editSeat" class="form-label">@T["Seat"]</label>
<input type="text" class="form-control" id="editSeat" name="Seat">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-warning">Save changes</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@T["Cancel"]</button>
<button type="submit" class="btn btn-warning">@T["Save changes"]</button>
</div>
</form>
</div>
@@ -290,30 +262,30 @@
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-primary text-white">
<h5 class="modal-title" id="createModalLabel">Create Location</h5>
<h5 class="modal-title" id="createModalLabel">@T["Create location"]</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form id="createForm">
<div class="modal-body">
<div class="mb-3">
<label for="createLocationName" class="form-label">Location Name</label>
<label for="createLocationName" class="form-label">@T["Location Name"]</label>
<input type="text" class="form-control" id="createLocationName" name="LocationName" required>
</div>
<div class="mb-3">
<label for="createRoomNumber" class="form-label">Room Number</label>
<label for="createRoomNumber" class="form-label">@T["Room Number"]</label>
<input type="text" class="form-control" id="createRoomNumber" name="RoomNumber">
</div>
<div class="mb-3">
<label for="createSeat" class="form-label">Seat</label>
<label for="createSeat" class="form-label">@T["Seat"]</label>
<input type="text" class="form-control" id="createSeat" name="Seat">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Create</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@T["Cancel"]</button>
<button type="submit" class="btn btn-primary">@T["Create"]</button>
</div>
</form>
</div>
@@ -373,14 +345,14 @@
data-seat="${newLoc.Seat}"
data-bs-toggle="modal"
data-bs-target="#editModal">
Edit
@T["Edit"]
</button>
<button class="btn btn-sm btn-danger btn-delete"
data-location-id="${slugifiedLocationID}"
data-location-name="${newLoc.Location}"
data-bs-toggle="modal"
data-bs-target="#deleteModal">
Delete
@T["Delete"]
</button>
</div>
</td>

View File

@@ -104,35 +104,6 @@
</div>
</div>
<script>
// Simple toast helper
function showToast(message, type) {
const toastContainer = document.getElementById('toastContainer') || createToastContainer();
const toast = document.createElement('div');
toast.className = `toast align-items-center text-white bg-${type} border-0`;
toast.role = 'alert';
toast.innerHTML = `
<div class="d-flex">
<div class="toast-body">${message}</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
</div>
`;
toastContainer.appendChild(toast);
const bsToast = new bootstrap.Toast(toast, { delay: 3000 });
bsToast.show();
toast.addEventListener('hidden.bs.toast', () => toast.remove());
}
function createToastContainer() {
const container = document.createElement('div');
container.id = 'toastContainer';
container.className = 'toast-container position-fixed bottom-0 end-0 p-3';
document.body.appendChild(container);
return container;
}
</script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const deleteModal = document.getElementById('deleteModal');

View File

@@ -1,4 +1,91 @@
// Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
// for details on configuring this project to bundle and minify static web assets.
function createToastContainer() {
const container = document.createElement('div');
container.id = 'toastContainer';
container.className = 'toast-container position-fixed bottom-0 end-0 p-3';
document.body.appendChild(container);
return container;
}
// Write your JavaScript code.
// Simple toast helper
function showToast(message, type) {
const toastContainer = document.getElementById('toastContainer') || createToastContainer();
const toast = document.createElement('div');
toast.className = `toast align-items-center text-white bg-${type} border-0`;
toast.role = 'alert';
toast.innerHTML = `
<div class="d-flex">
<div class="toast-body">${message}</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
</div>
`;
toastContainer.appendChild(toast);
const bsToast = new bootstrap.Toast(toast, { delay: 3000 });
bsToast.show();
toast.addEventListener('hidden.bs.toast', () => toast.remove());
}
function downloadBarcode(svgId, filename = "barcode.png") {
const svg = document.getElementById(svgId);
const serializer = new XMLSerializer();
const svgString = serializer.serializeToString(svg);
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
// Optionally set canvas size
const bbox = svg.getBBox();
canvas.width = bbox.width + 20; // padding
canvas.height = bbox.height + 20;
const img = new Image();
const svgBlob = new Blob([svgString], { type: "image/svg+xml;charset=utf-8" });
const url = URL.createObjectURL(svgBlob);
img.onload = () => {
ctx.drawImage(img, 0, 0);
URL.revokeObjectURL(url);
const pngUrl = canvas.toDataURL("image/png");
const a = document.createElement("a");
a.href = pngUrl;
a.download = filename;
a.click();
};
img.src = url;
}
function printBarcode(svgId) {
const svg = document.getElementById(svgId);
if (!svg) return;
// Serialize the SVG
const serializer = new XMLSerializer();
const svgString = serializer.serializeToString(svg);
// Open a new window for printing
const printWindow = window.open('', '_blank');
printWindow.document.write(`
<html>
<head>
<title>Print Barcode</title>
<style>
body { text-align: center; margin: 0; padding: 20px; }
svg { width: 300px; height: auto; }
</style>
</head>
<body>
${svgString}
</body>
</html>
`);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
function idToEAN13(id) {
const padded = id.toString().padStart(12, "0"); // 12 digits
return padded;
}