From 1d88b8ea6903049a5f6c5e81570e085e44d43e5f Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 9 Jul 2018 15:57:51 +0200 Subject: [PATCH] Can cancel groups membership invitations. --- assets/js/components/groups/interface.js | 19 ++++++++++++- assets/js/pages/groups/pages/members.js | 36 +++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/assets/js/components/groups/interface.js b/assets/js/components/groups/interface.js index 97b21f24..39024f08 100644 --- a/assets/js/components/groups/interface.js +++ b/assets/js/components/groups/interface.js @@ -225,5 +225,22 @@ ComunicWeb.components.groups.interface = { accept: accept }; ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); - } + }, + + /** + * Cancel a membership invitation + * + * @param {Number} groupID The ID of the target group + * @param {Number} userID The ID of the target user + * @param {Function} callback + */ + cancelInvitation: function(groupID, userID, callback){ + //Perform the request over the API + var apiURI = "groups/cancel_invitation"; + var params = { + groupID: groupID, + userID: userID + }; + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + }, }; \ No newline at end of file diff --git a/assets/js/pages/groups/pages/members.js b/assets/js/pages/groups/pages/members.js index f2946b82..e9da877a 100644 --- a/assets/js/pages/groups/pages/members.js +++ b/assets/js/pages/groups/pages/members.js @@ -238,7 +238,7 @@ ComunicWeb.pages.groups.pages.members = { if(member.level == "pending"){ //Disable membership level button - membershipLevelButton.style.display = true; + membershipLevelButton.disabled = true; //Create container var responseContainer = createElem2({ @@ -304,5 +304,39 @@ ComunicWeb.pages.groups.pages.members = { rejectRequest.addEventListener("click", function(e){respondRequest(false)}); } + //Check if the user was invited + else if(member.level == "invited"){ + + //Disable membership level button + membershipLevelButton.disabled = true; + + //Add a button to cancel invitation + var cancelInvitationButton = createElem2({ + appendTo: memberContainer, + type: "div", + class: "btn btn-danger", + innerHTML: "Cancel" + }); + + cancelInvitationButton.addEventListener("click", function(e){ + + //Peform the request on the APi + ComunicWeb.components.groups.interface.cancelInvitation(info.id, userInfo.userID, function(result){ + + cancelInvitationButton.style.visibility = "hidden"; + + //Check for errors + if(result.error){ + cancelInvitationButton.style.visibility = "visible"; + return notify("An error occurred while trying to cancel the invitation!", "danger"); + } + + //Remove the member + memberContainer.remove(); + }); + + }); + } + } } \ No newline at end of file