From e376c789a63f227ceb45e947cd657aa76fb108ca Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 13 May 2018 14:36:40 +0200 Subject: [PATCH] Display the list of conversations --- assets/js/pages/conversations/listPane.js | 109 ++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/assets/js/pages/conversations/listPane.js b/assets/js/pages/conversations/listPane.js index 6067fbc2..84ef2d7f 100644 --- a/assets/js/pages/conversations/listPane.js +++ b/assets/js/pages/conversations/listPane.js @@ -49,6 +49,115 @@ ComunicWeb.pages.conversations.listPane = { class: "conv-list-loading-msg", innerHTML: "Loading, please wait..." }); + + //Load the list of conversations + ComunicWeb.components.conversations.interface.getList(function(result){ + + //Check for errors + if(result.error){ + loadingMsg.innerHTML = "An error occured !"; + return; + } + + //Remove loading message + loadingMsg.remove(); + + //Display the list of conversations + ComunicWeb.pages.conversations.listPane._display_list(boxBody, result); + }); + }, + + + /** + * Display the list of conversations + * + * @param {HTMLElement} target The target for the list + * @param {Object} list The list of conversations + */ + _display_list: function(target, list){ + + //Create the conversations container + var conversationsContainer = createElem2({ + appendTo: target, + type: "ul", + class: "nav nav-pills nav-stacked" + }); + + //Process the list of conversations + for (const num in list) { + if (list.hasOwnProperty(num)) { + const conversation = list[num]; + + //Display conversation element + this._display_entry(conversationsContainer, conversation); + } + } + + }, + + /** + * Display a single conversation entry + * + * @param {HTMLElement} target The target for the conversation + * @param {Object} info Information about the conversation to display + */ + _display_entry: function(target, info){ + + //Create conversation container element + var convContainer = createElem2({ + appendTo: target, + type: "li" + }); + + //Create conversation link element + var convLink = createElem2({ + appendTo: convContainer, + type: "a" + }); + + //Add conversation last activity on the rigth + var lastActivityContainer = createElem2({ + appendTo: convLink, + type: "small", + class: "pull-right last-activity", + innerHTML: " " + }); + + //Add last activity + createElem2({ + appendTo: lastActivityContainer, + type: "span", + innerHTML: ComunicWeb.common.date.timeDiffToStr(info.last_active) + }); + + //Add conversation name + var conversationName = createElem2({ + appendTo: convLink, + type: "strong", + innerHTML: "Loading..." + }); + ComunicWeb.components.conversations.utils.getName(info, function(name){ + conversationName.innerHTML = name; + }); + + //Append the number of members of the conversation + var membersNumberContainer = createElem2({ + appendTo: convLink, + type: "p", + class: "number-members-conversation" + }); + + var membersNumberContainerSmall = createElem2({ + appendTo: membersNumberContainer, + type: "small", + innerHTML: " " + }); + createElem2({ + appendTo: membersNumberContainerSmall, + type: "span", + innerHTML: (info.members.length === 1 ? "1 member" : info.members.length + " members") + }); + } } \ No newline at end of file