mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-25 02:18: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;
|
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
|
* Get the current status of a friendship relation
|
||||||
*
|
*
|
||||||
|
@ -98,26 +98,66 @@ ComunicWeb.pages.userPage.friendshipStatus = {
|
|||||||
else if(response.sent_request){
|
else if(response.sent_request){
|
||||||
|
|
||||||
//Offer the user to cancel a frienship request
|
//Offer the user to cancel a frienship request
|
||||||
createElem2({
|
var cancelRequest = createElem2({
|
||||||
appendTo: target,
|
appendTo: target,
|
||||||
type: "button",
|
type: "button",
|
||||||
class: "btn btn-xs btn-danger",
|
class: "btn btn-xs btn-danger",
|
||||||
innerHTML: "Cancel request"
|
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 !");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Display default message
|
//Reload this component
|
||||||
else {
|
ComunicWeb.pages.userPage.friendshipStatus.display(userID, target);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Display send request message
|
||||||
|
else if(response.are_friend == false) {
|
||||||
|
|
||||||
//Offer the user to send a frienship request
|
//Offer the user to send a frienship request
|
||||||
createElem2({
|
var sendRequestButton = createElem2({
|
||||||
appendTo: target,
|
appendTo: target,
|
||||||
type: "button",
|
type: "button",
|
||||||
class: "btn btn-xs btn-primary",
|
class: "btn btn-xs btn-primary",
|
||||||
innerHTML: "Send request"
|
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