first commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
let logicHandler = new LogicHandler()
|
||||
let modalHandler = new StudyProgramModalHandler()
|
||||
|
||||
function renderStudyProgramModal(id) {
|
||||
id = typeof id == "undefined" ? "Create" : id
|
||||
|
||||
let studyProgram = id == "Create" ? getEmptyStudyProgram() : logicHandler.getItem("studyPrograms", id)
|
||||
|
||||
document.body.append(modalHandler.getStudyProgramModal(studyProgram))
|
||||
document.body.append(modalHandler.getStudyProgramModalButton(id))
|
||||
let htmlButton = document.getElementById("modalButton" + id)
|
||||
htmlButton.click()
|
||||
htmlButton.remove()
|
||||
}
|
||||
|
||||
function cancelStudyProgramModal(id) {
|
||||
document.getElementById("studyProgramModal" + id).remove()
|
||||
}
|
||||
|
||||
function saveStudyProgram(id) {
|
||||
logicHandler.saveItem("studyProgram", id)
|
||||
}
|
||||
|
||||
function removeStudyProgram(id) {
|
||||
logicHandler.removeItem("studyPrograms", id)
|
||||
document.getElementById("row" + id).remove()
|
||||
}
|
||||
|
||||
function getEmptyStudyProgram() {
|
||||
return {
|
||||
id: "Create",
|
||||
name: "",
|
||||
short: ""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
class StudyProgramModalHandler {
|
||||
|
||||
getStudyProgramModal(studyProgram) {
|
||||
let heading = studyProgram.id == "Create" ? "Neuen Studiengang erstellen" : `Studiengang #${studyProgram.id} bearbeiten`
|
||||
let modal = `
|
||||
<div class="modal modal-lg fade" id="studyProgramModal${studyProgram.id}" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="studyProgramModalLabel${studyProgram.id}" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-scrollable">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="studyProgramModalLabel${studyProgram.id}">${heading}</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Abbrechen" onclick="cancelStudyProgramModal('${studyProgram.id}')"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p class="error"><i class="bi bi-exclamation-circle"></i> Bitte alle Felder ausfüllen.</p>
|
||||
<form id="studyProgramForm${studyProgram.id}">
|
||||
<div class="mb-3">
|
||||
<label for="nameInput" class="form-label">Name</label>
|
||||
<input type="text" class="form-control modalInput" id="nameInput" name="name" value="${studyProgram.name}" >
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="shortInput" class="form-label">Kürzel</label>
|
||||
<input type="text" class="form-control modalInput" id="shortInput" name="short" value="${studyProgram.short}" >
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="cancelStudyProgramModal('${studyProgram.id}')">Abbrechen</button>
|
||||
<button type="button" class="btn btn-secondary" onclick="saveStudyProgram('${studyProgram.id}')">Speichern</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
||||
let htmlModal = document.createElement("div")
|
||||
htmlModal.innerHTML = modal
|
||||
return htmlModal
|
||||
}
|
||||
|
||||
getStudyProgramModalButton(id) {
|
||||
let button = `
|
||||
<button type="button" data-bs-toggle="modal" data-bs-target="#studyProgramModal${id}" id="modalButton${id}" style="display: none;"></button>
|
||||
`
|
||||
|
||||
let htmlButton = document.createElement("div")
|
||||
htmlButton.innerHTML = button
|
||||
return htmlButton
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
window.addEventListener("load", function () {
|
||||
let logicHandler = new LogicHandler()
|
||||
|
||||
let studyPrograms = logicHandler.getItems("studyPrograms")
|
||||
|
||||
if (studyPrograms != null) {
|
||||
studyPrograms.forEach(studyProgram => {
|
||||
|
||||
let content = `
|
||||
<th scope="row">${studyProgram.id}</th>
|
||||
<td>${studyProgram.name}</td>
|
||||
<td>${studyProgram.short}</td>
|
||||
<td>
|
||||
<div class="action-row">
|
||||
<button class="action-button edit" onclick="renderStudyProgramModal(${studyProgram.id})">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor"
|
||||
class="bi bi-pencil" viewBox="0 0 16 16">
|
||||
<path
|
||||
d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z" />
|
||||
</svg>
|
||||
</button>
|
||||
<button class="action-button delete" onclick="removeStudyProgram(${studyProgram.id})">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor"
|
||||
class="bi bi-trash" viewBox="0 0 16 16">
|
||||
<path
|
||||
d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z" />
|
||||
<path fill-rule="evenodd"
|
||||
d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
`
|
||||
|
||||
let row = document.createElement("tr")
|
||||
row.id = "row" + studyProgram.id
|
||||
row.innerHTML = content
|
||||
document.getElementById("studyProgramTable").appendChild(row)
|
||||
|
||||
document.getElementsByClassName("sidebar")[0].style.minHeight = `${document.body.offsetHeight - 66}px`
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user