category.js 965 B

123456789101112131415161718192021222324252627282930313233343536
  1. (() => {
  2. let selection = null;
  3. if (document.location.hash !== null &&
  4. (selection = document.getElementById(document.location.hash.replace("#", ""))) !== null) {
  5. selection.classList.add("selected");
  6. }
  7. function removeEntry(dn) {
  8. let csrfToken = document.getElementById("csrf").value;
  9. if (!csrfToken)
  10. return;
  11. let req = new XMLHttpRequest();
  12. req.onreadystatechange = () => {
  13. if (req.readyState === 4) {
  14. if (req.status === 203)
  15. document.location.reload();
  16. else
  17. alert("Error: " +req.statusText);
  18. }
  19. }
  20. req.open("DELETE", "/entity?dn=" + encodeURIComponent(dn) + "&csrf=" + encodeURIComponent(csrfToken));
  21. req.send();
  22. }
  23. document.querySelectorAll('.action-remove').forEach(i => {
  24. i.addEventListener('click', (e) => {
  25. let dn = e.target.dataset["dn"] || e.currentTarget.dataset["dn"];
  26. if (!dn)
  27. return;
  28. if (!window.confirm("Really remove entry " + dn + " ?"))
  29. return;
  30. removeEntry(dn);
  31. });
  32. });
  33. })();