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