mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 09:58:51 +00:00
Can create friendship relations
This commit is contained in:
parent
fe71d9839c
commit
e89ae955c2
@ -90,6 +90,48 @@ ComunicWeb.components.friends.list = {
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Send (create) a friendship request
|
||||
*
|
||||
* @param {Integer} friendID The friend ID to respond
|
||||
* @param {Function} afterResponse Specify an action to do next
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
sendRequest: function(friendID, afterResponse){
|
||||
//Prepare the API request
|
||||
var apiURI = "friends/sendRequest"
|
||||
var params = {
|
||||
"friendID": friendID,
|
||||
};
|
||||
|
||||
//Process request
|
||||
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, afterResponse);
|
||||
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove (ancel) a friendship request
|
||||
*
|
||||
* @param {Integer} friendID The target friendID
|
||||
* @param {Function} afterResponse Specify an action to do next
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
removeRequest: function(friendID, afterResponse){
|
||||
//Prepare the API request
|
||||
var apiURI = "friends/removeRequest"
|
||||
var params = {
|
||||
"friendID": friendID,
|
||||
};
|
||||
|
||||
//Process request
|
||||
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, afterResponse);
|
||||
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the current status of a friendship relation
|
||||
*
|
||||
|
@ -98,26 +98,66 @@ ComunicWeb.pages.userPage.friendshipStatus = {
|
||||
else if(response.sent_request){
|
||||
|
||||
//Offer the user to cancel a frienship request
|
||||
createElem2({
|
||||
var cancelRequest = createElem2({
|
||||
appendTo: target,
|
||||
type: "button",
|
||||
class: "btn btn-xs btn-danger",
|
||||
innerHTML: "Cancel request"
|
||||
});
|
||||
|
||||
cancelRequest.onclick = function(){
|
||||
|
||||
//Lock button
|
||||
this.disabled = true;
|
||||
|
||||
//Send the request
|
||||
ComunicWeb.components.friends.list.removeRequest(userID, function(response){
|
||||
|
||||
//Check for errors
|
||||
if(response.error){
|
||||
ComunicWeb.common.notificationSystem.showNotification("An error occured while trying to remove the request !");
|
||||
}
|
||||
|
||||
//Reload this component
|
||||
ComunicWeb.pages.userPage.friendshipStatus.display(userID, target);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Display default message
|
||||
else {
|
||||
//Display send request message
|
||||
else if(response.are_friend == false) {
|
||||
|
||||
//Offer the user to send a frienship request
|
||||
createElem2({
|
||||
var sendRequestButton = createElem2({
|
||||
appendTo: target,
|
||||
type: "button",
|
||||
class: "btn btn-xs btn-primary",
|
||||
innerHTML: "Send request"
|
||||
});
|
||||
|
||||
sendRequestButton.onclick = function(){
|
||||
|
||||
//Lock button
|
||||
this.disabled = true;
|
||||
|
||||
//Send the request
|
||||
ComunicWeb.components.friends.list.sendRequest(userID, function(response){
|
||||
|
||||
//Check for errors
|
||||
if(response.error){
|
||||
ComunicWeb.common.notificationSystem.showNotification("An error occured while trying to send the request !");
|
||||
}
|
||||
|
||||
//Reload this component
|
||||
ComunicWeb.pages.userPage.friendshipStatus.display(userID, target);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user