From adb5696a52ba199f953821e788e9b994c9b31f3a Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 10 Jun 2017 09:42:09 +0200 Subject: [PATCH] Make an API request --- .../js/components/conversations/interface.js | 30 +++++++++++++++++++ assets/js/components/conversations/list.js | 17 +++++++++++ assets/js/components/conversations/manager.js | 2 +- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/assets/js/components/conversations/interface.js b/assets/js/components/conversations/interface.js index a1564179..a2d87084 100644 --- a/assets/js/components/conversations/interface.js +++ b/assets/js/components/conversations/interface.js @@ -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; + } } \ No newline at end of file diff --git a/assets/js/components/conversations/list.js b/assets/js/components/conversations/list.js index de50f5dc..08d8c7d3 100644 --- a/assets/js/components/conversations/list.js +++ b/assets/js/components/conversations/list.js @@ -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"); + }) } } \ No newline at end of file diff --git a/assets/js/components/conversations/manager.js b/assets/js/components/conversations/manager.js index d4f84ae9..0b1debf0 100644 --- a/assets/js/components/conversations/manager.js +++ b/assets/js/components/conversations/manager.js @@ -78,5 +78,5 @@ ComunicWeb.components.conversations.manager = { addButton.onclick = function(){ ComunicWeb.components.conversations.list.display(this); } - } + }, } \ No newline at end of file