minor changes

This commit is contained in:
eclipse 2025-05-28 22:09:03 +02:00
parent bcf8fa5d66
commit 12fff63715

View File

@ -9,23 +9,17 @@ function initModal(modal_id, input_ids, headings, form_actions) {
document.getElementById("create-button").addEventListener("click", () => showDialog(modal_id, input_ids, headings[0], form_actions[0], new Array(input_ids.length).fill(""), 0)); document.getElementById("create-button").addEventListener("click", () => showDialog(modal_id, input_ids, headings[0], form_actions[0], new Array(input_ids.length).fill(""), 0));
// add event listeners to "update" elements // add event listeners to "update" elements
for (const el of document.querySelectorAll('.action-update')) { for (const el of document.querySelectorAll('.action-update')) {
el.addEventListener("click", event => showDialog( el.addEventListener("click", event => showDialog(modal_id, input_ids, headings[1], form_actions[1], input_ids.map(input => event.currentTarget.dataset[input.slice(5).toLowerCase()]), event.currentTarget.dataset.id));
modal_id,
input_ids,
headings[1],
form_actions[1],
input_ids.map(input => event.currentTarget.dataset[input.slice(5).toLowerCase()]),
event.currentTarget.dataset.id
));
} }
// add event listener to close button // add event listener to close button
document.querySelector("dialog button.modal-close").addEventListener("click", event => event.target.closest("dialog").close()); document.querySelector("dialog button.modal-close").addEventListener("click", event => {
event.target.closest("dialog").close();
});
} }
// raises a modal with the given options // raises a modal with the given options
function showDialog(modal_id, input_ids, heading, form_action, input_values, url_id) { function showDialog(modal_id, input_ids, heading, form_action, input_values, url_id) {
console.dir(arguments);
// if form action includes the string "update", the id at the end of the URL is a dummy and must be replaced with the correct id // if form action includes the string "update", the id at the end of the URL is a dummy and must be replaced with the correct id
if ( form_action.includes("update") && url_id) { if ( form_action.includes("update") && url_id) {
form_action = form_action.slice(0, form_action.lastIndexOf("/") + 1) + url_id; form_action = form_action.slice(0, form_action.lastIndexOf("/") + 1) + url_id;