Conversation window can be opened and closed

This commit is contained in:
Pierre
2017-06-14 16:39:34 +02:00
parent 3e5ce7c97a
commit fa5cbdf9a6
7 changed files with 153 additions and 8 deletions

View File

@ -54,6 +54,21 @@ ComunicWeb.components.conversations.cachingOpened = {
//Save the new values
var conversationsString = conversations.join(";");
sessionStorage.setItem(this.__varName, conversationsString);
//Success
return true;
},
/**
* Check is a conversation ID is open or not
*
* @param {Integer} conversationID The ID of the conversation to check
* @return {Boolean} Depends of the presence of the conversation
*/
isopen: function(conversationID){
var conversations = this.getAll();
return conversations.includes(conversationID.toString());
},
/**

View File

@ -0,0 +1,42 @@
/**
* Conversation chat window functions
*
* @author Pierre HUBERT
*/
ComunicWeb.components.conversations.chatWindows = {
/**
* Create a new chat window
*
* @param {Object} infos Informations required for the new chat window
* @info {HTMLElement} target The target of the new chat window
* @info {Integer} conversationID The ID of the target conversation
* @return {Object} Informations about the new chat window
*/
create: function(infos){
//Log action
ComunicWeb.debug.logMessage("Create a new chat window");
//First, create the generic conversation window
var infosBox = ComunicWeb.components.conversations.windows.create(infos.target.children[0]);
infosBox.conversationID = infos.conversationID;
//Adapt close button behaviour
infosBox.closeFunction = function(){
//Remove root element
infosBox.rootElem.remove();
//Remove the conversation from opened ones
ComunicWeb.components.conversations.cachingOpened.remove(infosBox.conversationID);
}
infosBox.closeButton.onclick = infosBox.closeFunction;
//Return informations about the chat window
return infosBox;
},
}

View File

@ -5,6 +5,12 @@
*/
ComunicWeb.components.conversations.manager = {
/**
* @var {String} The ID of the conversation contener
*/
__conversationsContenerID: "conversationsElem",
/**
* Display conversations manager
*
@ -13,7 +19,7 @@ ComunicWeb.components.conversations.manager = {
display: function(){
//Try to get conversation manager
var conversationsContainerElem = byId("conversationsElem");
var conversationsContainerElem = byId(this.__conversationsContenerID);
//Check if element exists or not
if(conversationsContainerElem){
@ -27,7 +33,7 @@ ComunicWeb.components.conversations.manager = {
//Create conversations manager element
var conversationsContainerElem = createElem("div");
conversationsContainerElem.id = "conversationsElem";
conversationsContainerElem.id = this.__conversationsContenerID;
//Insert the element at the right place
var pageTarget = byId("pageTarget");
@ -100,11 +106,23 @@ ComunicWeb.components.conversations.manager = {
return false;
}
//Check if the conversation is already open or not
if(ComunicWeb.components.conversations.cachingOpened.isopen(conversationID)){
ComunicWeb.debug.logMessage("The conversation " + conversationID + " is already opened !");
return false;
}
//Log action
ComunicWeb.debug.logMessage("Opening conversation " + conversationID);
//Save conversation ID in session storage
ComunicWeb.components.conversations.cachingOpened.add(conversationID);
//Create a conversation windows
ComunicWeb.components.conversations.chatWindows.create({
target: byId(this.__conversationsContenerID),
conversationID: conversationID
});
//Success
return true;

View File

@ -0,0 +1,11 @@
/**
* Conversation service file
*
* Ensure that the content of the conversations is up to date
*
* @author Pierre HUBER
*/
ComunicWeb.components.conversations.service = {
}

View File

@ -56,6 +56,7 @@ ComunicWeb.components.conversations.windows = {
var boxElements ={
rootElem: conversationBox,
closeFunction: closeBox,
closeButton: closeButton,
boxTitle: boxTitle,
boxTools: boxTools,
boxBody: boxBody,