mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 20:19:21 +00:00
Make an API request
This commit is contained in:
parent
07c6fc4be7
commit
adb5696a52
@ -9,7 +9,37 @@ ComunicWeb.components.conversations.interface = {
|
||||
* Create a conversation
|
||||
*
|
||||
* @param {Object} infos Informations about the conversation to create
|
||||
* * @info {Array} users A list of the members of the conversation
|
||||
* * @info {Boolan} follow Defines if the current user wants to follow the conversation or not
|
||||
* * @info {Mixed} conversationName The name of the conversation
|
||||
* @param {Function} afterCreate What to do once the conversation is created
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
createConversation: function(infos, afterCreate){
|
||||
|
||||
//Prepare an API request
|
||||
var apiURI = "conversations/create";
|
||||
var params = {
|
||||
name: infos.conversationName,
|
||||
follow : infos.follow,
|
||||
users: infos.users,
|
||||
};
|
||||
|
||||
//Perform the API request
|
||||
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, function(result){
|
||||
|
||||
//Check for errors
|
||||
if(result.error){
|
||||
//Log error
|
||||
ComunicWeb.debug.logMessage("ERROR ! Couldn't create a conversation!");
|
||||
}
|
||||
|
||||
//Perform next action
|
||||
afterCreate(result);
|
||||
|
||||
});
|
||||
|
||||
//Success
|
||||
return true;
|
||||
}
|
||||
}
|
@ -156,5 +156,22 @@ ComunicWeb.components.conversations.list = {
|
||||
var splashScreen = ComunicWeb.common.page.showTransparentWaitSplashScreen(infos.listBox.boxBody);
|
||||
|
||||
//Contact the interface to create the conversation
|
||||
ComunicWeb.components.conversations.interface.createConversation(conversationInformations, function(response){
|
||||
|
||||
//First, remove splash screen
|
||||
splashScreen.remove();
|
||||
|
||||
//Check for errors
|
||||
if(response.error){
|
||||
//Make an error notification
|
||||
notifMessage = "An error occured while trying to create conversation. Please try again.";
|
||||
ComunicWeb.common.notificationSystem.showNotification(notifMessage, "danger", 3);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Success
|
||||
alert("success");
|
||||
})
|
||||
}
|
||||
}
|
@ -78,5 +78,5 @@ ComunicWeb.components.conversations.manager = {
|
||||
addButton.onclick = function(){
|
||||
ComunicWeb.components.conversations.list.display(this);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue
Block a user