new modal for deleting tags and items

This commit is contained in:
x
2026-01-23 20:52:49 +01:00
parent e9c377dc87
commit ee6fda8f06
4 changed files with 186 additions and 21 deletions

View File

@@ -418,16 +418,66 @@ window.requestAnimFrame = (function () {
canvas.classList.add('fader-out');
}
}
} else if (e.target.closest('.removetag')) {
e.preventDefault();
const removeBtn = e.target.closest('.removetag');
const tagLink = removeBtn.previousElementSibling;
if (tagLink) {
const tagName = tagLink.textContent.trim();
const idLink = document.querySelector('.id-link');
const id = idLink ? idLink.textContent.trim() : null;
if (id && tagName) {
const modal = document.getElementById('delete-tag-modal');
const nameEl = document.getElementById('delete-tag-name');
const confirmBtn = document.getElementById('delete-tag-confirm');
const cancelBtn = document.getElementById('delete-tag-cancel');
if (modal) {
nameEl.textContent = tagName;
modal.style.display = 'flex';
const closeModal = () => {
modal.style.display = 'none';
confirmBtn.onclick = null;
cancelBtn.onclick = null;
};
cancelBtn.onclick = closeModal;
confirmBtn.onclick = () => {
confirmBtn.textContent = 'Deleting...';
confirmBtn.disabled = true;
fetch(`/api/v2/admin/${id}/tags/${encodeURIComponent(tagName)}`, {
method: 'DELETE'
})
.then(r => r.json())
.then(data => {
if (data.success) {
removeBtn.parentElement.remove();
closeModal();
} else {
alert('Error: ' + (data.msg || 'Unknown error'));
confirmBtn.textContent = 'Delete';
confirmBtn.disabled = false;
}
})
.catch(err => {
console.error(err);
alert('Failed to delete tag');
confirmBtn.textContent = 'Delete';
confirmBtn.disabled = false;
});
};
}
}
}
}
});
window.addEventListener('popstate', (e) => {
if (window.location.href.match(/\/p\/\d+/) || window.location.href.match(/[?&]page=\d+/) || window.location.pathname === '/') {
// Ideally we should reload page or call loadPageAjax(currentUrl) if it supports it
// But if we are going BACK to index from item, we expect grid.
// loadItemAjax fails on index.
// loadPageAjax handles /p/N logic.
// If just slash, loadPageAjax might default to page 1.
loadPageAjax(window.location.href);
} else {
loadItemAjax(window.location.href, true);