fix: persist quick win reorder changes
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
const currentUserId = document.body.dataset.currentUserId;
|
||||
const currentUserName = document.body.dataset.currentUserName;
|
||||
const quickWinSortList = document.querySelector("[data-quick-win-sort-list]");
|
||||
const quickWinSortToken = document.getElementById("quickWinSortToken");
|
||||
const quickWinSortIds = document.getElementById("quickWinSortIds");
|
||||
const quickWinSortSave = document.getElementById("quickWinSortSave");
|
||||
const quickWinToggleButtons = document.querySelectorAll("[data-quick-win-toggle]");
|
||||
let draggedQuickWin = null;
|
||||
@@ -123,22 +123,14 @@
|
||||
});
|
||||
}
|
||||
|
||||
async function persistQuickWinSort() {
|
||||
if (!quickWinSortList || !quickWinSortToken) {
|
||||
function syncQuickWinSortIds() {
|
||||
if (!quickWinSortList || !quickWinSortIds) {
|
||||
return;
|
||||
}
|
||||
const ids = [...quickWinSortList.querySelectorAll("[data-quick-win-sort-item]")]
|
||||
.map((item) => item.dataset.quickWinSortItem)
|
||||
.filter(Boolean);
|
||||
|
||||
await fetch("/settings/quick-wins/reorder", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-CSRFToken": quickWinSortToken.value,
|
||||
},
|
||||
body: JSON.stringify({ ids }),
|
||||
});
|
||||
quickWinSortIds.value = ids.join(",");
|
||||
}
|
||||
|
||||
function setQuickWinSortDirty(isDirty) {
|
||||
@@ -149,6 +141,7 @@
|
||||
}
|
||||
|
||||
if (quickWinSortList) {
|
||||
syncQuickWinSortIds();
|
||||
setQuickWinSortDirty(false);
|
||||
|
||||
quickWinSortList.querySelectorAll("[data-quick-win-sort-item]").forEach((item) => {
|
||||
@@ -180,25 +173,12 @@
|
||||
} else {
|
||||
item.before(draggedQuickWin);
|
||||
}
|
||||
syncQuickWinSortIds();
|
||||
setQuickWinSortDirty(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (quickWinSortSave) {
|
||||
quickWinSortSave.addEventListener("click", async () => {
|
||||
if (!quickWinSortDirty) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await persistQuickWinSort();
|
||||
setQuickWinSortDirty(false);
|
||||
} catch (error) {
|
||||
console.error("Quick-Win-Sortierung konnte nicht gespeichert werden", error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
quickWinToggleButtons.forEach((button) => {
|
||||
button.addEventListener("click", () => {
|
||||
const targetId = button.dataset.target;
|
||||
|
||||
Reference in New Issue
Block a user