All GCC vendors and employee details for IT department management
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.7 KiB

4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. // Global flags
  2. let otpSent = false;
  3. let isAdmin = false;
  4. async function loadRole() {
  5. try {
  6. const res = await fetch(`${contextPath}api/get-role`, {
  7. method: "POST"
  8. });
  9. const data = await res.json();
  10. if (!data.authenticated) {
  11. isAdmin = false;
  12. return;
  13. }
  14. isAdmin = data.isAdmin;
  15. } catch (e) {
  16. // swallow network errors
  17. console.error("Error: ", error);
  18. }
  19. }
  20. // Open the login modal
  21. function openLoginModal() {
  22. if (isAdmin) {
  23. // For admin → directly go to the post-verification page
  24. window.open(`${contextPath}view-login-det`, '_blank');
  25. return;
  26. }
  27. const modal = document.getElementById("login-modal");
  28. modal.classList.remove("hide");
  29. modal.classList.add("show");
  30. modal.style.display = "flex"; // make it visible immediately before animation
  31. }
  32. // Load role when page loads
  33. document.addEventListener("DOMContentLoaded", () => {
  34. loadRole();
  35. });
  36. document.addEventListener("DOMContentLoaded", function() {
  37. const dropdown = document.getElementById("urlDropdown");
  38. const urlStatDropdown = document.getElementById("urlStatDropdown");
  39. const urlLinkInput = document.getElementById("urlDataLink");
  40. const urlNameInput = document.getElementById("urlDataName");
  41. const urlUsrNameInput = document.getElementById("urlDataUsrName");
  42. const urlUsrPassInput = document.getElementById("urlDataUsrPass");
  43. const urlCatNameInput = document.getElementById("urlCatName");
  44. const togglePass = document.getElementById("togglePass");
  45. // safety check
  46. if (!dropdown || !togglePass) {
  47. return;
  48. }
  49. // if (!dropdown) return;
  50. // --- Dropdown change handler ---
  51. dropdown.addEventListener("change", function() {
  52. const selected = dropdown.options[dropdown.selectedIndex];
  53. if (!selected.value) {
  54. urlLinkInput.value = "";
  55. urlNameInput.value = "";
  56. urlUsrNameInput.value = "";
  57. urlUsrPassInput.value = "";
  58. urlCatNameInput.value = "";
  59. return;
  60. }
  61. const statId = selected.getAttribute("data-statId");
  62. if (statId) {
  63. urlStatDropdown.value = statId;
  64. }
  65. const link = selected.getAttribute("data-link");
  66. const name = selected.getAttribute("data-name");
  67. const usrname = selected.getAttribute("data-usrname");
  68. const pass = selected.getAttribute("data-pass");
  69. const urlCatName = selected.getAttribute("data-urlCatName");
  70. urlLinkInput.value = link || "";
  71. urlNameInput.value = name || "";
  72. urlUsrNameInput.value = (usrname && usrname !== "-") ? usrname : "";
  73. urlUsrPassInput.value = (pass && pass !== "-") ? pass : "";
  74. urlCatNameInput.value = (urlCatName && urlCatName !== "-") ? urlCatName : "";
  75. // Reset to hidden state
  76. urlUsrPassInput.type = "password";
  77. togglePass.classList.add("fa-eye");
  78. togglePass.classList.remove("fa-eye-slash");
  79. });
  80. // --- Toggle Password Visibility ---
  81. togglePass.addEventListener("click", function() {
  82. const isPassword = urlUsrPassInput.type === "password";
  83. urlUsrPassInput.type = isPassword ? "text" : "password";
  84. togglePass.classList.toggle("fa-eye");
  85. togglePass.classList.toggle("fa-eye-slash");
  86. });
  87. const form = document.getElementById("frm-url-det");
  88. // Existing form submission logic...
  89. form.addEventListener("submit", function(e) {
  90. e.preventDefault(); // Prevent default form submission
  91. const formData = new FormData(form);
  92. fetch(form.getAttribute("action"), {
  93. method: "POST",
  94. body: formData
  95. })
  96. .then(response => {
  97. if (!response.ok) {
  98. throw new Error("Network response was not ok: " + response.statusText);
  99. }
  100. return response.json();
  101. })
  102. .then(data => {
  103. if (data.resStat) {
  104. alert("Success: " + data.res);
  105. form.reset();
  106. } else {
  107. alert("Failed: " + data.res);
  108. }
  109. })
  110. .catch(error => {
  111. console.error("Error updating url:", error);
  112. alert("Error updating url. Please try again.");
  113. });
  114. });
  115. });