From fe71d9839ccebfb9ddf0c8e174efa0bda43da34f Mon Sep 17 00:00:00 2001 From: Pierre Date: Thu, 21 Dec 2017 19:09:53 +0100 Subject: [PATCH] Can accept a reject a friendship request --- assets/js/components/friends/friendsList.js | 2 +- assets/js/pages/userPage/friendshipStatus.js | 43 +++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/assets/js/components/friends/friendsList.js b/assets/js/components/friends/friendsList.js index 52e78fc6..2314c683 100644 --- a/assets/js/components/friends/friendsList.js +++ b/assets/js/components/friends/friendsList.js @@ -78,7 +78,7 @@ ComunicWeb.components.friends.list = { "friendID": friendID, }; - if(accept) + if(accept == true) params.accept = "true"; else params.accept = "false"; diff --git a/assets/js/pages/userPage/friendshipStatus.js b/assets/js/pages/userPage/friendshipStatus.js index 16379adf..46b64011 100644 --- a/assets/js/pages/userPage/friendshipStatus.js +++ b/assets/js/pages/userPage/friendshipStatus.js @@ -32,7 +32,7 @@ ComunicWeb.pages.userPage.friendshipStatus = { if(response.received_request){ //Offer the user to reject a frienship request - createElem2({ + var rejectRequest = createElem2({ appendTo: target, type: "button", class: "btn btn-xs btn-danger", @@ -46,13 +46,52 @@ ComunicWeb.pages.userPage.friendshipStatus = { }) //Offer the user to accept a frienship request - createElem2({ + var acceptRequest = createElem2({ appendTo: target, type: "button", class: "btn btn-xs btn-success", innerHTML: "Accept request" }); + //Prepare the buttons + acceptRequest.setAttribute("data-accept", "true"); + rejectRequest.setAttribute("data-accept", "false"); + + //Setup the action + var respondRequest = function(){ + + //Lock the buttons + acceptRequest.disabled = true; + rejectRequest.disabled = true; + + //Get the status of the request + var accept = this.getAttribute("data-accept") == "true"; + + //Perform the action + ComunicWeb.components.friends.list.respondRequest(userID, accept, function(response){ + + //Unlock the buttons + acceptRequest.disabled = false; + rejectRequest.disabled = false; + + //Check for errors + if(response.error){ + ComunicWeb.common.notificationSystem.showNotification("Couldn't update request status !", + "danger", 5); + } + + else { + //Reopen user page + openUserPage(userID); + } + + }); + + + } + acceptRequest.onclick = respondRequest; + rejectRequest.onclick = respondRequest; + } //Check if user has sent a friendship request