mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 15:01:56 +00:00
Removed stray comments from Assets.cshtml, Fixed success toast not showing
This commit is contained in:
@@ -80,6 +80,32 @@
|
||||
|
||||
|
||||
<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
|
||||
@@ -128,39 +154,13 @@
|
||||
|
||||
showToast('Asset deleted successfully', 'success');
|
||||
} else {
|
||||
showToast(`❌ ${result.reason}: ${result.exception || 'Unknown error'}`, 'danger');
|
||||
showToast(`${result.reason}: ${result.exception || 'Unknown error'}`, 'danger');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
showToast('Error contacting server', 'danger');
|
||||
}
|
||||
});
|
||||
|
||||
// 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>
|
||||
|
||||
@@ -222,13 +222,13 @@
|
||||
<div class="col-12 mt-3">
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<h6 class="fw-bold mb-0">@T["Attributes"]</h6>
|
||||
<button type="button" class="btn btn-sm btn-outline-success" id="addAttributeBtn">
|
||||
➕ @T["Add Attribute"]
|
||||
</button>
|
||||
</div>
|
||||
<div id="attributesContainer" class="d-flex flex-column gap-2">
|
||||
<!-- Dynamic attribute rows will appear here -->
|
||||
</div>
|
||||
<button type="button" class="btn btn-sm btn-outline-success mt-3" id="addAttributeBtn">
|
||||
➕ @T["Add Attribute"]
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<hr class="my-3" />
|
||||
@@ -269,7 +269,6 @@
|
||||
const attributesContainer = document.getElementById('attributesContainer');
|
||||
const addAttributeBtn = document.getElementById('addAttributeBtn');
|
||||
|
||||
// Add a new attribute row
|
||||
addAttributeBtn.addEventListener('click', () => {
|
||||
const row = document.createElement('div');
|
||||
row.className = 'd-flex gap-2 align-items-center attribute-row';
|
||||
@@ -281,18 +280,15 @@
|
||||
attributesContainer.appendChild(row);
|
||||
});
|
||||
|
||||
// Delegate delete button click
|
||||
attributesContainer.addEventListener('click', (e) => {
|
||||
if (e.target.classList.contains('btn-remove-attribute')) {
|
||||
e.target.closest('.attribute-row').remove();
|
||||
}
|
||||
});
|
||||
|
||||
// 🔧 Hook into the existing submit handler to include attributes
|
||||
const createForm = document.getElementById('createAssetForm');
|
||||
const originalHandler = createForm.onsubmit;
|
||||
createForm.addEventListener('submit', (e) => {
|
||||
// Let’s patch the JSON generation just before sending
|
||||
const formData = new FormData(createForm);
|
||||
const jsonData = {};
|
||||
|
||||
@@ -307,7 +303,6 @@
|
||||
target[keys[keys.length - 1]] = value;
|
||||
}
|
||||
|
||||
// Add Attributes as Dictionary<string,string>
|
||||
const attributes = {};
|
||||
document.querySelectorAll('#attributesContainer .attribute-row').forEach(row => {
|
||||
const name = row.querySelector('[data-attr-name]').value.trim();
|
||||
@@ -320,8 +315,7 @@
|
||||
jsonData.Description.Attributes = attributes;
|
||||
}
|
||||
|
||||
// Replace the body before sending
|
||||
e.preventDefault(); // stop default form submit
|
||||
e.preventDefault();
|
||||
|
||||
fetch('/Assets/Create', {
|
||||
method: 'POST',
|
||||
@@ -338,9 +332,9 @@
|
||||
bootstrap.Modal.getInstance(createModalEl).hide();
|
||||
createForm.reset();
|
||||
attributesContainer.innerHTML = '';
|
||||
showToast('✅ Asset created successfully', 'success');
|
||||
showToast('Asset created successfully', 'success');
|
||||
} else {
|
||||
showToast(`❌ ${result.reason || 'Error creating asset'}`, 'danger');
|
||||
showToast(`${result.reason || 'Error creating asset'}`, 'danger');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
|
||||
Reference in New Issue
Block a user