From fa225319fc57a96bfe7af059b7097352c5f3ca02 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 11 Jun 2017 15:14:23 +0200 Subject: [PATCH] Can get and cache conversations list --- .../js/components/conversations/interface.js | 58 ++++++++++++++++++- assets/js/components/conversations/list.js | 23 +++++++- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/assets/js/components/conversations/interface.js b/assets/js/components/conversations/interface.js index a2d87084..664b8525 100644 --- a/assets/js/components/conversations/interface.js +++ b/assets/js/components/conversations/interface.js @@ -5,6 +5,62 @@ */ ComunicWeb.components.conversations.interface = { + + /** + * @var {Object} __conversationsList Cached list of conversations + */ + __conversationsList: false, + + /** + * Get and return the list of available conversations + * + * @param {Function} onceGotList What to do next + * @param {Boolean} force Force the list to be loaded even if present in the cache + * @return {Boolean} True for a success + */ + getList: function(onceGotList, force){ + + //First, check if the list is already present in the cache or not + if(this.__conversationsList && !force){ + //Perform next action now + onceGotList(this.__conversationsList); + } + + //Else, prepare an API request + var apiURI = "conversations/getList"; + var params = {}; //No params required now + + //Perform the API request + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, function(results){ + + //Check for error + if(results.error){ + //Log error + ComunicWeb.debug.logMessage("ERROR : couldn't get conversations list !"); + + //Perform next action + onceGotList(results); + } + else { + //Process the list + var conversationsList = {}; + for(i in results){ + conversationsList["conversation-"+results[i].ID] = results[i]; + } + + //Save the list in the cache + ComunicWeb.components.conversations.interface.__conversationsList = conversationsList; + + //Perform next action + onceGotList(conversationsList); + } + + }); + + //Success + return true; + }, + /** * Create a conversation * @@ -41,5 +97,5 @@ ComunicWeb.components.conversations.interface = { //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 185ab480..cbfb5408 100644 --- a/assets/js/components/conversations/list.js +++ b/assets/js/components/conversations/list.js @@ -31,6 +31,7 @@ ComunicWeb.components.conversations.list = { createButton.className = "btn btn-box-tool"; createButton.onclick = function(){ ComunicWeb.components.conversations.list.displayCreateForm(listBox); + this.remove(); } //Button icon @@ -38,7 +39,7 @@ ComunicWeb.components.conversations.list = { createButtonIcon.className = "fa fa-pencil"; //Get and display conversations list - //TODO : implement + this.showConversationsList(); //Success return true; @@ -180,5 +181,23 @@ ComunicWeb.components.conversations.list = { //Open the conversation (under construction) console.log("Open conversation ID: " + response.conversationID); }) - } + }, + + /** + * Show the conversations list + * + * @return {Boolean} True for a success + */ + showConversationsList: function(){ + + //Get and show the conversation list + ComunicWeb.components.conversations.interface.getList(function(){ + + console.log("OK --------------------"); + + }, true); + + //Success + return true; + }, } \ No newline at end of file