From b9cc47f05dd010123cf56cd946d6cf8934d75433 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 16 May 2018 07:00:06 +0200 Subject: [PATCH] Split refresh list method and create box method --- assets/js/pages/conversations/listPane.js | 41 +++++++++++++++++------ assets/js/pages/conversations/main.js | 29 +++++++++++----- 2 files changed, 51 insertions(+), 19 deletions(-) diff --git a/assets/js/pages/conversations/listPane.js b/assets/js/pages/conversations/listPane.js index 0180a9a2..2953c70f 100644 --- a/assets/js/pages/conversations/listPane.js +++ b/assets/js/pages/conversations/listPane.js @@ -43,15 +43,33 @@ ComunicWeb.pages.conversations.listPane = { class: "box-body no-padding" }); - //Loading message - var loadingMsg = createElem2({ - appendTo: boxBody, - type: "div", - class: "conv-list-loading-msg", - innerHTML: "Loading, please wait..." - }); - //Load the list of conversations + this.refresh_list(boxBody, args); + }, + + /** + * Refresh the list of conversations + * + * @param {HTMLElement} target The target for the list + * @param {Object} args Additionnal arguments + */ + refresh_list: function(target, args){ + + //Loading message, if required + if(target.childElementCount == 0){ + var loadingMsg = createElem2({ + appendTo: target, + type: "div", + class: "conv-list-loading-msg", + innerHTML: "Loading, please wait..." + }); + } + else + //Create empty division + var loadingMsg = document.createElement("div"); + + + //Perform a request over the interface ComunicWeb.components.conversations.interface.getList(function(result){ //Check for errors @@ -62,11 +80,12 @@ ComunicWeb.pages.conversations.listPane = { //Remove loading message loadingMsg.remove(); - emptyElem(boxBody); //Remove any previously shown list + emptyElem(target); //Remove any previously shown list //Display the list of conversations - ComunicWeb.pages.conversations.listPane._display_list(boxBody, result, args); + ComunicWeb.pages.conversations.listPane._display_list(target, result, args); }); + }, @@ -128,7 +147,7 @@ ComunicWeb.pages.conversations.listPane = { }); //Check if it is the current conversation - if(args.currConvID == info.ID) + if(args.getCurrentID() == info.ID) convLink.className = " selected"; //Add conversation last activity on the rigth diff --git a/assets/js/pages/conversations/main.js b/assets/js/pages/conversations/main.js index 6068aa94..7c224771 100644 --- a/assets/js/pages/conversations/main.js +++ b/assets/js/pages/conversations/main.js @@ -5,6 +5,7 @@ */ ComunicWeb.pages.conversations.main = { + /** * Open settings page * @@ -56,22 +57,34 @@ ComunicWeb.pages.conversations.main = { } //Check if a conversation has to be opened - var currConvID = 0; if(args.subfolder){ - //Determine conversation ID - var convID = args.subfolder; - if(convID.includes("/")) - convID = convID.split("/")[0]; - currConvID = Number(convID); //Open the conversation - conversationOpener(currConvID); + conversationOpener(ComunicWeb.pages.conversations.main.getCurrentConversationID()); } //Display the list of conversation ComunicWeb.pages.conversations.listPane.display(leftArea, { opener: conversationOpener, - currConvID: currConvID + getCurrentID: this.getCurrentConversationID }); + }, + + /** + * Determine the current conversation ID + * + * @return {Number} The ID of the current conversation (0 if none found) + */ + getCurrentConversationID: function(){ + + var id = location.toString().split("/conversations/"); + id = id[id.length - 1]; + + //Check if no ID is specified + if(id.length < 1) + return 0; + else + return Number(id); + } } \ No newline at end of file