Can get and cache conversations list

This commit is contained in:
Pierre 2017-06-11 15:14:23 +02:00
parent b0f6e5d2e0
commit fa225319fc
2 changed files with 78 additions and 3 deletions

View File

@ -5,6 +5,62 @@
*/ */
ComunicWeb.components.conversations.interface = { 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 * Create a conversation
* *
@ -41,5 +97,5 @@ ComunicWeb.components.conversations.interface = {
//Success //Success
return true; return true;
} },
} }

View File

@ -31,6 +31,7 @@ ComunicWeb.components.conversations.list = {
createButton.className = "btn btn-box-tool"; createButton.className = "btn btn-box-tool";
createButton.onclick = function(){ createButton.onclick = function(){
ComunicWeb.components.conversations.list.displayCreateForm(listBox); ComunicWeb.components.conversations.list.displayCreateForm(listBox);
this.remove();
} }
//Button icon //Button icon
@ -38,7 +39,7 @@ ComunicWeb.components.conversations.list = {
createButtonIcon.className = "fa fa-pencil"; createButtonIcon.className = "fa fa-pencil";
//Get and display conversations list //Get and display conversations list
//TODO : implement this.showConversationsList();
//Success //Success
return true; return true;
@ -180,5 +181,23 @@ ComunicWeb.components.conversations.list = {
//Open the conversation (under construction) //Open the conversation (under construction)
console.log("Open conversation ID: " + response.conversationID); 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;
},
} }