2017-12-20 18:18:18 +00:00
|
|
|
/**
|
|
|
|
* Handle the update of the friendship status
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
|
|
|
ComunicWeb.pages.userPage.friendshipStatus = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the friendship status
|
|
|
|
*
|
|
|
|
* @param {Integer} userID The ID of the target user
|
|
|
|
* @param {HTMLElement} target The target element
|
|
|
|
*/
|
|
|
|
display: function(userID, target){
|
|
|
|
|
|
|
|
//Get the current status of the friendship
|
|
|
|
ComunicWeb.components.friends.list.getStatus(userID, function(response){
|
|
|
|
|
|
|
|
//Empty the target area
|
|
|
|
emptyElem(target);
|
|
|
|
target.innerHTML = "";
|
|
|
|
|
|
|
|
//Check for errors
|
|
|
|
if(response.error){
|
|
|
|
message = ComunicWeb.common.messages.createCalloutElem("Error", "Couldn't load friendship informations !", "danger");
|
|
|
|
target.appendChild(message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check if the user has received a friendship request
|
|
|
|
if(response.received_request){
|
|
|
|
|
|
|
|
//Offer the user to reject a frienship request
|
2017-12-21 18:09:53 +00:00
|
|
|
var rejectRequest = createElem2({
|
2017-12-20 18:18:18 +00:00
|
|
|
appendTo: target,
|
|
|
|
type: "button",
|
|
|
|
class: "btn btn-xs btn-danger",
|
|
|
|
innerHTML: "Reject request"
|
|
|
|
});
|
|
|
|
|
|
|
|
createElem2({
|
|
|
|
appendTo: target,
|
|
|
|
type: "span",
|
|
|
|
innerHTML: " ",
|
|
|
|
})
|
|
|
|
|
|
|
|
//Offer the user to accept a frienship request
|
2017-12-21 18:09:53 +00:00
|
|
|
var acceptRequest = createElem2({
|
2017-12-20 18:18:18 +00:00
|
|
|
appendTo: target,
|
|
|
|
type: "button",
|
|
|
|
class: "btn btn-xs btn-success",
|
|
|
|
innerHTML: "Accept request"
|
|
|
|
});
|
|
|
|
|
2017-12-21 18:09:53 +00:00
|
|
|
//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;
|
|
|
|
|
2017-12-20 18:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Check if user has sent a friendship request
|
|
|
|
else if(response.sent_request){
|
|
|
|
|
|
|
|
//Offer the user to cancel a frienship request
|
|
|
|
createElem2({
|
|
|
|
appendTo: target,
|
|
|
|
type: "button",
|
|
|
|
class: "btn btn-xs btn-danger",
|
|
|
|
innerHTML: "Cancel request"
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Display default message
|
|
|
|
else {
|
|
|
|
|
|
|
|
//Offer the user to send a frienship request
|
|
|
|
createElem2({
|
|
|
|
appendTo: target,
|
|
|
|
type: "button",
|
|
|
|
class: "btn btn-xs btn-primary",
|
|
|
|
innerHTML: "Send request"
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|