fix: allow only one instance of mediatype to be present

This commit is contained in:
2025-11-19 18:57:09 +01:00
parent 1ad010d079
commit d697c3e268

View File

@@ -103,13 +103,13 @@
<h2>Medien</h2>
<div class="media-controls">
<button type="button" class="btn btn-secondary" onclick="addMediaType('monografie')">
<button type="button" id="btn-monografie" class="btn btn-secondary" onclick="addMediaType('monografie')" title="Monografie Sektion hinzufügen">
<span class="mdi mdi-book"></span> + Monografie
</button>
<button type="button" class="btn btn-secondary" onclick="addMediaType('zeitschriftenartikel')">
<button type="button" id="btn-zeitschriftenartikel" class="btn btn-secondary" onclick="addMediaType('zeitschriftenartikel')" title="Zeitschriftenartikel Sektion hinzufügen">
<span class="mdi mdi-newspaper"></span> + Zeitschriftenartikel
</button>
<button type="button" class="btn btn-secondary" onclick="addMediaType('herausgeberwerk')">
<button type="button" id="btn-herausgeberwerk" class="btn btn-secondary" onclick="addMediaType('herausgeberwerk')" title="Herausgeberwerk Sektion hinzufügen">
<span class="mdi mdi-book-multiple"></span> + Herausgeberwerk
</button>
</div>
@@ -173,6 +173,9 @@
// Media management functions (global scope for onclick handlers)
function addMediaType(type) {
const btn = document.getElementById('btn-' + type);
// Prevent duplicate sections of same type
if (btn && btn.disabled) { return; }
const container = document.getElementById('media-sections');
const sectionId = 'section-' + sectionCounter++;
@@ -243,6 +246,11 @@
'</button>';
container.appendChild(section);
// Disable button for this type until section removed
if (btn) {
btn.disabled = true;
btn.title = 'Sektion bereits hinzugefügt entfernen zum erneuten Hinzufügen';
}
// Add first row automatically
addMediaRow(sectionId, type);
@@ -314,6 +322,7 @@
const section = document.getElementById(sectionId);
if (section) {
if (confirm('Möchten Sie diese Sektion wirklich entfernen?')) {
const type = section.getAttribute('data-type');
// Clean up tracking for removed rows
const rows = section.querySelectorAll('tr[id]');
rows.forEach(row => {
@@ -323,6 +332,12 @@
}
});
section.remove();
// Re-enable button for this media type
const btn = document.getElementById('btn-' + type);
if (btn) {
btn.disabled = false;
btn.title = 'Sektion hinzufügen';
}
updateSubmitButton();
}
}