mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-26 13:59:23 +00:00
Can update following state
This commit is contained in:
parent
ac86fbcb25
commit
a49e068637
@ -63,6 +63,33 @@ ComunicWeb.components.friends.list = {
|
||||
return this.__list;
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the follow status of a user
|
||||
*
|
||||
* @param {Integer} friendID The friend ID to respond
|
||||
* @param {Boolean} follow Specify whether the user has to be followed or not
|
||||
* @param {Function} callback Specify an action to do next
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
setFollowing: function(friendID, follow, callback){
|
||||
//Prepare the API request
|
||||
var apiURI = "friends/setFollowing"
|
||||
var params = {
|
||||
"friendID": friendID,
|
||||
};
|
||||
|
||||
if(follow == true)
|
||||
params.follow = "true";
|
||||
else
|
||||
params.follow = "false";
|
||||
|
||||
//Process request
|
||||
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
||||
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Respond a friendship request
|
||||
*
|
||||
|
@ -160,6 +160,49 @@ ComunicWeb.pages.userPage.friendshipStatus = {
|
||||
|
||||
}
|
||||
|
||||
//Offer user to follow other user
|
||||
else {
|
||||
|
||||
//Setup button
|
||||
var followButton = createElem2({
|
||||
appendTo: target,
|
||||
type: "button",
|
||||
class: "btn btn-primary btn-block",
|
||||
});
|
||||
|
||||
if(response.following){
|
||||
followButton.innerHTML = "Following";
|
||||
followButton.setAttribute("data-following", "true");
|
||||
}
|
||||
else {
|
||||
followButton.innerHTML = "Follow";
|
||||
followButton.setAttribute("data-following", "false");
|
||||
}
|
||||
|
||||
//Make the follow button live
|
||||
followButton.onclick = function(){
|
||||
|
||||
//Lock button
|
||||
this.disabled = true;
|
||||
|
||||
//Check if the user has to be followed or not (reverse current state)
|
||||
var follow = this.getAttribute("data-following") == "false";
|
||||
|
||||
ComunicWeb.components.friends.list.setFollowing(userID, follow, function(response){
|
||||
|
||||
//Check for errors
|
||||
if(response.error){
|
||||
ComunicWeb.common.notificationSystem.showNotification("An error occured while trying to update following status !");
|
||||
}
|
||||
|
||||
//Reload this component
|
||||
ComunicWeb.pages.userPage.friendshipStatus.display(userID, target);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -59,5 +59,19 @@ ComunicWeb.pages.userPage.profileInfos = {
|
||||
class: "profile-username text-center",
|
||||
innerHTML: infos.firstName + " " + infos.lastName
|
||||
});
|
||||
|
||||
//Add user status informations (if required)
|
||||
if(signed_in()){
|
||||
if(userID() != infos.userID){
|
||||
var userStatus = createElem2({
|
||||
appendTo: boxBody,
|
||||
type: "div",
|
||||
innerHTML: "Loading...",
|
||||
});
|
||||
userStatus.style.textAlign = "center";
|
||||
ComunicWeb.pages.userPage.friendshipStatus.display(infos.userID, userStatus);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user