mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 12:09:21 +00:00
User can update following state of its friends from friends list
This commit is contained in:
parent
a7c4445b03
commit
a4ec170d8a
@ -575,6 +575,13 @@ var ComunicWeb = {
|
||||
*/
|
||||
utils: {
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
* Friends actions
|
||||
*/
|
||||
actions: {
|
||||
//TODO : implement
|
||||
}
|
||||
},
|
||||
|
||||
|
44
assets/js/components/friends/actions.js
Normal file
44
assets/js/components/friends/actions.js
Normal 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);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
};
|
@ -6,6 +6,25 @@
|
||||
|
||||
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
|
||||
*
|
||||
|
@ -109,9 +109,8 @@ ComunicWeb.components.friends.ui = {
|
||||
}
|
||||
else {
|
||||
|
||||
//Display again the friend
|
||||
friend.accepted = 1;
|
||||
ComunicWeb.components.friends.ui.show_personnal_friend(friendContener, friend, user);
|
||||
//Update friendship informations
|
||||
ComunicWeb.components.friends.actions.refresh_single_personnal(friendID, friendContener);
|
||||
}
|
||||
|
||||
});
|
||||
@ -125,8 +124,45 @@ ComunicWeb.components.friends.ui = {
|
||||
else {
|
||||
|
||||
//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
|
||||
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);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -218,6 +218,7 @@ class Dev {
|
||||
"js/components/friends/listModal.js",
|
||||
"js/components/friends/interface.js",
|
||||
"js/components/friends/utils.js",
|
||||
"js/components/friends/actions.js",
|
||||
|
||||
//Private conversations
|
||||
"js/components/conversations/manager.js",
|
||||
|
Loading…
Reference in New Issue
Block a user