From 8af21bca61e779d8a4aad4c879b4ec4981218e67 Mon Sep 17 00:00:00 2001 From: Joshua Wilshere Date: Fri, 16 Jan 2026 22:37:39 +0000 Subject: [PATCH] bug fix - fixed group member select after search, group member removal, group member role update, and approve/reject request --- .../static/js/group/manage_group.js | 110 ++++++++++-------- 1 file changed, 61 insertions(+), 49 deletions(-) diff --git a/application/single_app/static/js/group/manage_group.js b/application/single_app/static/js/group/manage_group.js index 371689db..87a12b58 100644 --- a/application/single_app/static/js/group/manage_group.js +++ b/application/single_app/static/js/group/manage_group.js @@ -59,6 +59,39 @@ $(document).ready(function () { } }); + // Add event delegation for select user button in search results + $(document).on("click", ".select-user-btn", function () { + const id = $(this).data("user-id"); + const name = $(this).data("user-name"); + const email = $(this).data("user-email"); + selectUserForAdd(id, name, email); + }); + + // Add event delegation for remove member button + $(document).on("click", ".remove-member-btn", function () { + const userId = $(this).data("user-id"); + removeMember(userId); + }); + + // Add event delegation for change role button + $(document).on("click", ".change-role-btn", function () { + const userId = $(this).data("user-id"); + const currentRole = $(this).data("user-role"); + openChangeRoleModal(userId, currentRole); + $("#changeRoleModal").modal("show"); + }); + + // Add event delegation for approve/reject request buttons + $(document).on("click", ".approve-request-btn", function () { + const requestId = $(this).data("request-id"); + approveRequest(requestId); + }); + + $(document).on("click", ".reject-request-btn", function () { + const requestId = $(this).data("request-id"); + rejectRequest(requestId); + }); + // CSV Bulk Upload Events $("#addBulkMemberBtn").on("click", function () { $("#csvBulkUploadModal").modal("show"); @@ -407,17 +440,15 @@ function renderMemberActions(member) { } else { return ` `; @@ -473,8 +504,10 @@ function loadPendingRequests() { ${u.displayName} ${u.email} - - + + `; @@ -522,66 +555,44 @@ function rejectRequest(requestId) { }); } +// Search users for manual add function searchUsers() { const term = $("#userSearchTerm").val().trim(); if (!term) { - alert("Please enter a search term."); + alert("Enter a name or email to search."); return; } - - // UI state $("#searchStatus").text("Searching..."); $("#searchUsersBtn").prop("disabled", true); - $.ajax({ - url: "/api/userSearch", - method: "GET", - data: { query: term }, - dataType: "json", - }) - .done(function (results) { - renderUserSearchResults(results); - }) - .fail(function (jqXHR, textStatus, errorThrown) { - console.error("User search error:", textStatus, errorThrown); - - if (jqXHR.status === 401) { - // Session expired or no token → force re-login - window.location.href = "/login"; - } else { - const msg = jqXHR.responseJSON?.error - ? jqXHR.responseJSON.error - : "User search failed."; - alert(msg); - } + $.get("/api/userSearch", { query: term }) + .done(renderUserSearchResults) + .fail(function (jq) { + const err = jq.responseJSON?.error || jq.statusText; + alert("User search failed: " + err); }) .always(function () { - // Restore UI state $("#searchStatus").text(""); $("#searchUsersBtn").prop("disabled", false); }); } +// Render user-search results in add-member modal function renderUserSearchResults(users) { let html = ""; - if (!users || users.length === 0) { - html = ` - - No results found - - `; + if (!users || !users.length) { + html = `No results.`; } else { - users.forEach((u) => { + users.forEach(u => { html += ` ${u.displayName || "(no name)"} ${u.email || ""} - @@ -592,9 +603,10 @@ function renderUserSearchResults(users) { $("#userSearchResultsTable tbody").html(html); } -function selectUserForAdd(uid, displayName, email) { - $("#newUserId").val(uid); - $("#newUserDisplayName").val(displayName); +// Populate manual-add fields from search result +function selectUserForAdd(id, name, email) { + $("#newUserId").val(id); + $("#newUserDisplayName").val(name); $("#newUserEmail").val(email); }