Make an API request

This commit is contained in:
Pierre 2017-06-10 09:42:09 +02:00
parent 07c6fc4be7
commit adb5696a52
3 changed files with 48 additions and 1 deletions

View File

@ -9,7 +9,37 @@ ComunicWeb.components.conversations.interface = {
* Create a conversation * Create a conversation
* *
* @param {Object} infos Informations about the conversation to create * @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 * @param {Function} afterCreate What to do once the conversation is created
* @return {Boolean} True for a success * @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;
}
} }

View File

@ -156,5 +156,22 @@ ComunicWeb.components.conversations.list = {
var splashScreen = ComunicWeb.common.page.showTransparentWaitSplashScreen(infos.listBox.boxBody); var splashScreen = ComunicWeb.common.page.showTransparentWaitSplashScreen(infos.listBox.boxBody);
//Contact the interface to create the conversation //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");
})
} }
} }

View File

@ -78,5 +78,5 @@ ComunicWeb.components.conversations.manager = {
addButton.onclick = function(){ addButton.onclick = function(){
ComunicWeb.components.conversations.list.display(this); ComunicWeb.components.conversations.list.display(this);
} }
} },
} }