User can update following state of its friends from friends list

This commit is contained in:
Pierre 2018-03-11 16:16:00 +01:00
parent a7c4445b03
commit a4ec170d8a
5 changed files with 110 additions and 3 deletions

View File

@ -575,6 +575,13 @@ var ComunicWeb = {
*/ */
utils: { utils: {
//TODO : implement //TODO : implement
},
/**
* Friends actions
*/
actions: {
//TODO : implement
} }
}, },

View File

@ -0,0 +1,44 @@
/**
* Friends actions
*
* @author Pierre HUBERT
*/
ComunicWeb.components.friends.actions = {
/**
* Refresh informations of a single personnal friend
*
* @param {number} friendID The ID of the target friend
* @param {HTMLElement} target The target element
*/
refresh_single_personnal: function(friendID, target){
//Get informations about the friendship
ComunicWeb.components.friends.interface.get_single_friend(friendID, function(r){
//Check for errors
if(r.error){
ComunicWeb.common.notificationSystem.showNotification("Could not get informations about a friendship !", "danger");
return;
}
//Get informations about the user
ComunicWeb.user.userInfos.getUserInfos(friendID, function(user){
//Check for errors
if(user.error){
ComunicWeb.common.notificationSystem.showNotification("Could get informations about a friend !", "danger");
return;
}
//Refresh the UI
ComunicWeb.components.friends.ui.show_personnal_friend(target, r, user);
});
});
}
};

View File

@ -6,6 +6,25 @@
ComunicWeb.components.friends.interface = { ComunicWeb.components.friends.interface = {
/**
* Get single friend informations
*
* @param {number} friendID The ID of the target friend
* @param {function} callback Callback function
*/
get_single_friend: function(friendID, callback){
//Prepare the API request
var apiURI = "friends/get_single_infos";
var params = {
friendID: friendID
};
//Perform API request
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
},
/** /**
* Get the list of friends of the current user * Get the list of friends of the current user
* *

View File

@ -109,9 +109,8 @@ ComunicWeb.components.friends.ui = {
} }
else { else {
//Display again the friend //Update friendship informations
friend.accepted = 1; ComunicWeb.components.friends.actions.refresh_single_personnal(friendID, friendContener);
ComunicWeb.components.friends.ui.show_personnal_friend(friendContener, friend, user);
} }
}); });
@ -125,8 +124,45 @@ ComunicWeb.components.friends.ui = {
else { else {
//Display following state //Display following state
var followButton = createElem2({
appendTo: friendContener,
type: "button",
class: "btn btn-primary"
});
if(friend.following == 0){
followButton.innerHTML = "Follow";
followButton.setAttribute("data-set-following", "true");
}
else {
followButton.innerHTML = "Following";
followButton.setAttribute("data-set-following", "false");
}
add_space(friendContener);
//Check if the user can post text on user page //Check if the user can post text on user page
followButton.onclick = function(){
//Check if the request is to follow or not the user
var follow = this.getAttribute("data-set-following") == "true";
//Lock button
followButton.disabled = true;
//Perform callback action
ComunicWeb.components.friends.list.setFollowing(friendID, follow, function(r){
//Check for errors
if(r.error){
ComunicWeb.common.notificationSystem.showNotification("Could not update follow state !", "danger");
}
//Update friendship informations
ComunicWeb.components.friends.actions.refresh_single_personnal(friendID, friendContener);
});
}
} }

View File

@ -218,6 +218,7 @@ class Dev {
"js/components/friends/listModal.js", "js/components/friends/listModal.js",
"js/components/friends/interface.js", "js/components/friends/interface.js",
"js/components/friends/utils.js", "js/components/friends/utils.js",
"js/components/friends/actions.js",
//Private conversations //Private conversations
"js/components/conversations/manager.js", "js/components/conversations/manager.js",