2017-06-14 14:39:34 +00:00
|
|
|
/**
|
|
|
|
* 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]);
|
|
|
|
|
2017-06-17 08:09:37 +00:00
|
|
|
//Save conversation ID
|
2017-06-14 14:39:34 +00:00
|
|
|
infosBox.conversationID = infos.conversationID;
|
|
|
|
|
2017-06-17 08:09:37 +00:00
|
|
|
//Change box root class name
|
|
|
|
infosBox.rootElem.className += " direct-chat";
|
|
|
|
|
2017-06-14 14:39:34 +00:00
|
|
|
//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;
|
|
|
|
|
2017-06-17 08:09:37 +00:00
|
|
|
|
|
|
|
//Debug
|
|
|
|
infosBox.boxBody.innerHTML = "<div class='direct-chat-messages'>Hello world</p>";
|
|
|
|
|
|
|
|
//Add button to get conversation members
|
|
|
|
infosBox.membersButton = createElem("button");
|
|
|
|
infosBox.closeButton.parentNode.insertBefore(infosBox.membersButton, infosBox.closeButton);
|
|
|
|
infosBox.membersButton.type = "button";
|
|
|
|
infosBox.membersButton.className = "btn btn-box-tool";
|
|
|
|
infosBox.membersButton.setAttribute("data-toggle", "tooltip");
|
|
|
|
infosBox.membersButton.setAttribute("data-widget", "chat-pane-toggle");
|
|
|
|
infosBox.membersButton.title = "Conversation members";
|
|
|
|
|
|
|
|
//Add button icon
|
|
|
|
var buttonIcon = createElem("i", infosBox.membersButton);
|
|
|
|
buttonIcon.className = "fa fa-users";
|
|
|
|
|
|
|
|
//Add conversation members pane
|
|
|
|
var membersPane = createElem("div", infosBox.boxBody);
|
|
|
|
membersPane.className = "direct-chat-contacts";
|
|
|
|
|
|
|
|
//Add conversation members list
|
|
|
|
infosBox.membersList = createElem("ul", membersPane);
|
|
|
|
infosBox.membersList.className = "contacts-list";
|
|
|
|
|
2017-06-14 14:39:34 +00:00
|
|
|
//Return informations about the chat window
|
|
|
|
return infosBox;
|
|
|
|
|
|
|
|
},
|
2017-06-16 09:42:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the name of the converation at the top of the windows
|
|
|
|
*
|
|
|
|
* @param {String} newName The new name for the conversation window
|
|
|
|
* @param {Ojbect} infos INformations about the conversation window
|
|
|
|
* @return {Boolean} True for a success
|
|
|
|
*/
|
|
|
|
changeName: function(newName, infos){
|
|
|
|
|
|
|
|
//Empty name field
|
|
|
|
emptyElem(infos.boxTitle);
|
|
|
|
|
|
|
|
//Create conversation icon
|
|
|
|
var conversationIcon = createElem("i", infos.boxTitle);
|
|
|
|
conversationIcon.className = "fa fa-comments";
|
|
|
|
|
|
|
|
//Add conversation title
|
|
|
|
var conversationTitle = createElem("span", infos.boxTitle);
|
|
|
|
conversationTitle.innerHTML = " " + newName;
|
|
|
|
|
2017-06-17 08:09:37 +00:00
|
|
|
//Success
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update conversation members list
|
|
|
|
*
|
|
|
|
* @param {Object} conversation Informations about the conversation
|
|
|
|
* @return {Boolean} True for a success
|
|
|
|
*/
|
|
|
|
updateMembersList: function(conversation){
|
|
|
|
|
|
|
|
//First, make sure conversation members pane is empty
|
|
|
|
emptyElem(conversation.box.membersList);
|
|
|
|
|
|
|
|
//Then process each user
|
|
|
|
var i = 0;
|
|
|
|
for(i in conversation.infos.members){
|
|
|
|
if(conversation.membersInfos['user-'+conversation.infos.members[i]]){
|
|
|
|
var memberInfos = conversation.membersInfos['user-'+conversation.infos.members[i]];
|
|
|
|
|
|
|
|
//Display user informations
|
|
|
|
var userLi = createElem("li", conversation.box.membersList);
|
|
|
|
var userLink = createElem("a", userLi);
|
|
|
|
|
|
|
|
//Add user account image
|
|
|
|
var userImage = createElem("img", userLink);
|
|
|
|
userImage.className = "contacts-list-img";
|
|
|
|
userImage.src = memberInfos.accountImage;
|
|
|
|
|
|
|
|
//Add member informations
|
|
|
|
var memberInfosList = createElem2({
|
|
|
|
type: "div",
|
|
|
|
appendTo: userLink,
|
|
|
|
class: "contacts-list-info",
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add user name
|
|
|
|
var memberName = createElem2({
|
|
|
|
type: "span",
|
|
|
|
appendTo: memberInfosList,
|
|
|
|
class: "contacts-list-name",
|
|
|
|
innerHTML: memberInfos.firstName + " " + memberInfos.lastName,
|
|
|
|
});
|
|
|
|
|
|
|
|
//Check if members is a moderator or not of the conversation
|
|
|
|
var memberStatus = conversation.infos.ID_owner == memberInfos.userID ? "Moderator" : "Member";
|
|
|
|
|
|
|
|
//Add member status
|
|
|
|
var memberStatus = createElem2({
|
|
|
|
type: "span",
|
|
|
|
appendTo: memberInfosList,
|
|
|
|
class: "contats-list-msg",
|
|
|
|
innerHTML: memberStatus
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Enable slimscrooll
|
|
|
|
$(conversation.box.membersList).slimscroll({
|
|
|
|
height: "100%",
|
|
|
|
color: "#FFFFFF"
|
|
|
|
});
|
|
|
|
|
2017-06-16 09:42:28 +00:00
|
|
|
//Success
|
|
|
|
return true;
|
2017-06-17 09:20:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show conversation settings (button + pane)
|
|
|
|
*
|
|
|
|
* @param {Object} infos Informations about the conversation
|
|
|
|
* @return {Boolean} True for a success
|
|
|
|
*/
|
|
|
|
showConversationSettings: function(infos){
|
|
|
|
console.log(infos);
|
|
|
|
//Create and display conversation settings button wheel
|
|
|
|
infos.box.settingsButton = createElem2({
|
|
|
|
type: "button",
|
|
|
|
insertBefore: infos.box.membersButton,
|
|
|
|
class: "btn btn-box-tool",
|
|
|
|
type: "button"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add button icon
|
|
|
|
createElem2({
|
|
|
|
type: "i",
|
|
|
|
appendTo: infos.box.settingsButton,
|
|
|
|
class: "fa fa-gear",
|
|
|
|
});
|
|
|
|
|
|
|
|
//Create settings pane
|
|
|
|
var settingsPane = createElem2({
|
|
|
|
type: "div",
|
|
|
|
appendTo: infos.box.boxBody,
|
|
|
|
class: "conversation-settings-pane",
|
|
|
|
innerHTML: "<p>Welcome to settings world</p>",
|
|
|
|
});
|
|
|
|
|
|
|
|
//Make the settings button lives
|
|
|
|
infos.box.settingsButton.onclick = function(){
|
|
|
|
if(settingsPane.className.includes(" open"))
|
|
|
|
settingsPane.className = settingsPane.className.replace(" open", ""); //Close the pane
|
|
|
|
else
|
|
|
|
settingsPane.className += " open"; //Open the pane
|
|
|
|
};
|
|
|
|
|
|
|
|
//Success
|
|
|
|
return true;
|
|
|
|
},
|
2017-06-17 08:09:37 +00:00
|
|
|
|
2017-06-14 14:39:34 +00:00
|
|
|
}
|