From cd4e6ddcb1c1ddbeb016d89df30d78a97cfac249 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 23 Jan 2019 15:45:19 +0100 Subject: [PATCH] Show call button on conversation of two people when available --- .../css/components/conversations/windows.css | 8 +++ assets/js/components/calls/controller.js | 23 ++++++++ .../components/conversations/chatWindows.js | 53 +++++++++++++++---- 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/assets/css/components/conversations/windows.css b/assets/css/components/conversations/windows.css index 375fc95b..e2b15e58 100644 --- a/assets/css/components/conversations/windows.css +++ b/assets/css/components/conversations/windows.css @@ -4,6 +4,10 @@ * @author Pierre HUBERT */ + +/** + * Main definition + */ #conversationsElem .box { width: 250px; height: 350px; @@ -15,6 +19,10 @@ margin-bottom: 0px; } +#conversationsElem .chat-window .box-title { + font-size: 15px !important; +} + /** * Conversations create message form */ diff --git a/assets/js/components/calls/controller.js b/assets/js/components/calls/controller.js index 06b9bbfc..89ee9fcb 100644 --- a/assets/js/components/calls/controller.js +++ b/assets/js/components/calls/controller.js @@ -42,6 +42,29 @@ ComunicWeb.components.calls.controller = { }); }); + }, + + /** + * Access calls configuration + * + * @return Cached calls configuration + */ + getConfig() { + return ComunicWeb.components.calls.__config; + }, + + /** + * Check if the call feature is available or not + */ + isAvailable: function(){ + + //If do not have any call configuration, it is not possible to + //make calls + if(this.getConfig() == null) + return false; + + //Read configuration + return this.getConfig().enabled; } } \ No newline at end of file diff --git a/assets/js/components/conversations/chatWindows.js b/assets/js/components/conversations/chatWindows.js index 0469bd14..f4a008fa 100644 --- a/assets/js/components/conversations/chatWindows.js +++ b/assets/js/components/conversations/chatWindows.js @@ -56,7 +56,7 @@ ComunicWeb.components.conversations.chatWindows = { infosBox.conversationID = infos.conversationID; //Change box root class name - infosBox.rootElem.className += " direct-chat direct-chat-primary"; + infosBox.rootElem.className += " chat-window direct-chat direct-chat-primary"; //Adapt close button behaviour infosBox.closeFunction = function(){ @@ -84,18 +84,21 @@ ComunicWeb.components.conversations.chatWindows = { }); //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 = createElem2({ + type: "button", + insertBefore: infosBox.closeButton, + elemType: "button", + class: "btn btn-box-tool", + title: "Conversation members" + }); 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"; @@ -319,6 +322,9 @@ ComunicWeb.components.conversations.chatWindows = { return false; }; + //Add call button (if possible) + ComunicWeb.components.conversations.chatWindows.showCallButton(conversationInfos); + }); }); @@ -563,16 +569,43 @@ ComunicWeb.components.conversations.chatWindows = { return true; }, + /** + * Add a call button to the conversation, if possible + * + * @param {Object} conversation Information about the conversation + */ + showCallButton: function(conversation){ + + //Check if calls are disabled + if(!ComunicWeb.components.calls.controller.isAvailable()) + return; + + //Check if it is a conversation with two members + if(conversation.infos.members.length != 2) + return; //Currently the call feature is offered just + //for conversation of two people + + //Add the call button + let button = createElem2({ + insertBefore: conversation.box.boxTools.firstChild, + type: "button", + class: "btn btn-box-tool", + innerHTML: "" + }); + conversation.box.callButton = button; + + }, + /** * Process submited update conversation form * - * @param {Object} conversation Informations about the conversation + * @param {Object} conversation Information about the conversation * @return {Boolean} True for a success */ submitUpdateForm: function(conversation){ - //Then, get informations about the input + //Then, get information about the input var newValues = { conversationID: conversation.infos.ID, following: conversation.settingsForm.followConversationInput.checked, @@ -621,7 +654,7 @@ ComunicWeb.components.conversations.chatWindows = { /** * Submit a new message form * - * @param {Object} convInfos Informations about the conversation + * @param {Object} convInfos Information about the conversation * @return {Boolean} True for a success */ submitMessageForm: function(convInfos){ @@ -673,7 +706,7 @@ ComunicWeb.components.conversations.chatWindows = { /** * Reset a create a message form * - * @param {Object} infos Informations about the conversation + * @param {Object} infos Information about the conversation * @return {Boolean} True for a success */ resetCreateMessageForm: function(infos){