Renamed discussions to conversations

This commit is contained in:
Pierre
2017-06-07 19:24:48 +02:00
parent ee02b522bf
commit 07c6fc4be7
11 changed files with 152 additions and 146 deletions

View File

@ -0,0 +1,15 @@
/**
* Interface between the graphical conversation system and the API
*
* @author Pierre HUBERT
*/
ComunicWeb.components.conversations.interface = {
/**
* Create a conversation
*
* @param {Object} infos Informations about the conversation to create
* @param {Function} afterCreate What to do once the conversation is created
* @return {Boolean} True for a success
*/
}

View File

@ -0,0 +1,160 @@
/**
* Conversations list window
*
* @author Pierre HUBERT
*/
ComunicWeb.components.conversations.list = {
/**
* Display conversations list window
*
* @param {HTMLElement} nodeBefore The node before the destination
* @return {Boolean} True for a success
*/
display: function(nodeBefore){
//Log action
ComunicWeb.debug.logMessage("INFO : initialize conversation list box.");
//Create a window
var listBox = ComunicWeb.components.conversations.windows.create(nodeBefore);
//Change box title
listBox.boxTitle.innerHTML = "Conversations";
//Remove footer
listBox.boxFooter.remove();
//Add the create button
var createButton = createElem("button");
listBox.boxTools.insertBefore(createButton, listBox.boxTools.children[0]);
createButton.className = "btn btn-box-tool";
createButton.onclick = function(){
ComunicWeb.components.conversations.list.displayCreateForm(listBox);
}
//Button icon
var createButtonIcon = createElem("i", createButton);
createButtonIcon.className = "fa fa-pencil";
//Display conversations list
listBox.boxBody.innerHTML = "<p>Hello world</p>";
//Success
return true;
},
/**
* Display the form to create a new conversation
*
* @param {Object} listBox Informations about the listbox target
* @return {Boolean} True for a success
*/
displayCreateForm: function(listBox){
//Log action
ComunicWeb.debug.logMessage("INFO : initialize create conversation form");
//Hide boxy body contents
var boxBodyElem = listBox.boxBody.children;
for(i in boxBodyElem){
if(boxBodyElem[i].style)
boxBodyElem[i].style.display = "none";
}
//Change box title
listBox.boxTitle.innerHTML = "New conversation";
//Create and display conversation creation form
var createForm = createElem("div", listBox.boxBody);
//Choose users
//Create select user element
var usersElement = createFormGroup({
target: createForm,
label: "Users",
multiple: true,
placeholder: "Select users",
type: "select2"});
//Initialize user selector
ComunicWeb.components.userSelect.init(usersElement);
//Conversation name
var conversationNameInput = createFormGroup({
target: createForm,
label: "Conversation name",
placeholder: "Optionnal",
type: "text"});
//Follow disucssion
var followConversationInput = createFormGroup({
target: createForm,
label: "Follow conversation",
checked: true,
type: "checkbox"});
//Create button
var createButton = createElem("button", createForm);
createButton.className = "btn btn-primary";
createButton.style.width = "100%";
createButton.innerHTML = "Create conversation";
//Generate a summary object about all the informations we have got
var infos = {
listBox: listBox,
usersElement: usersElement,
conversationNameInput: conversationNameInput,
followConversationInput: followConversationInput,
};
//Make button lives
createButton.onclick = function(){
ComunicWeb.components.conversations.list.submitCreateConversationForm(infos);
};
//Success
return true;
},
/**
* Submit a create a conversation form
*
* @param {Object} infos Data to pass to the function
* * @info {Object} listBox Informations about the listbox creating the conversation
* * @info {HTMLElement} usersElement Pointer on userElement
* * @info {HTMLElement} conversationNameInput Pointer on the input of the form of the conversation
* * @info {HTMLElement} followConversationInput Pointer on the "follow conversation" checkbox
* @return {Boolean} True for a success
*/
submitCreateConversationForm: function(infos){
//First, get the list of users
var selectedUsers = ComunicWeb.components.userSelect.getResults(infos.usersElement);
//We check if less than one user was selected
if(selectedUsers.length < 1){
//Display an error notification
ComunicWeb.common.notificationSystem.showNotification("Please select at least one user!", "danger", 2);
return false;
}
//Add current user to the list
selectedUsers.push(ComunicWeb.user.userLogin.getUserID());
//Prepare the creation of the conversation
//Get all required informations
var conversationInformations = {
users: selectedUsers,
follow: infos.followConversationInput.checked,
conversationName: (infos.conversationNameInput.value == "" ? false : infos.conversationNameInput.value),
};
//Change box body style
var splashScreen = ComunicWeb.common.page.showTransparentWaitSplashScreen(infos.listBox.boxBody);
//Contact the interface to create the conversation
}
}

View File

@ -0,0 +1,82 @@
/**
* Conversations manager
*
* @author Pierre HUBERT
*/
ComunicWeb.components.conversations.manager = {
/**
* Display conversations manager
*
* @return {Boolean} True for a success
*/
display: function(){
//Try to get conversation manager
var conversationsContainerElem = byId("conversationsElem");
//Check if element exists or not
if(conversationsContainerElem){
ComunicWeb.debug.logMessage("NOTICE : couldn't initializate conversation manager because a conversation manager is already on the page");
return true;
}
//Else inform user and create conversation manager
ComunicWeb.debug.logMessage("INFO : initializate conversation manager");
//Create conversations manager element
var conversationsContainerElem = createElem("div");
conversationsContainerElem.id = "conversationsElem";
//Insert the element at the right place
var pageTarget = byId("pageTarget");
if(pageTarget){
//Insert disucssion element before it
byId("wrapper").insertBefore(conversationsContainerElem, pageTarget);
}
else{
//Just apply the element
byId("wrapper").appendChild(conversationsContainerElem);
}
//Initializate conversation element
this.init(conversationsContainerElem);
//Success
return true;
},
/**
* Initializate conversations element
*
* @param {HTMLElement} conversationsContainerElem The container of the conversation element
* @return {Boolean} True for a success
*/
init: function(conversationsContainerElem){
//First, add the "open a conversation" new
this.addOpenConversationButton(conversationsContainerElem);
},
/**
* Add the "open conversation" button
*
* @param {HTMLElement} targetElem The target of the button
* @return {Boolean} True for a success
*/
addOpenConversationButton: function(targetElem){
//Create the button
var addButton = createElem("button", targetElem);
addButton.className = "btn btn-primary open-conversation-button";
addButton.innerHTML = "Open a conversation";
//Temporary behavior
addButton.onclick = function(){
ComunicWeb.components.conversations.list.display(this);
}
}
}

View File

@ -0,0 +1,69 @@
/**
* Conversations windows manager
*
* @author Pierre HUBERT
*/
ComunicWeb.components.conversations.windows = {
/**
* Create a new conversation window
*
* @param {HTMLElement} nodeBefore The node before the destination window
* @return {Object} Differents elements of the window
*/
create: function(nodeBefore){
//Create listbox element
var conversationBox = createElem("div", nodeBefore.parentNode);
conversationBox.className = "box box-primary";
//Create close box function
var closeBox = function(){
conversationBox.remove();
}
//Create box header
var boxHeader = createElem("div", conversationBox);
boxHeader.className = "box-header with-border";
//Add box title
var boxTitle = createElem("h3", boxHeader);
boxTitle.className = "box-title";
//Box tools
var boxTools = createElem("div", boxHeader);
boxTools.className = "box-tools pull-right";
//Close button
var closeButton = createElem("button", boxTools);
closeButton.className = "btn btn-box-tool";
closeButton.onclick = closeBox;
//Close icon
var closeIcon = createElem("i", closeButton);
closeIcon.className = "fa fa-times";
//Box body
var boxBody = createElem("div", conversationBox);
boxBody.className = "box-body";
//Box footer
var boxFooter = createElem("div", conversationBox);
boxFooter.className = "box-footer";
//Prepare return
var boxElements ={
rootElem: conversationBox,
closeFunction: closeBox,
boxTitle: boxTitle,
boxTools: boxTools,
boxBody: boxBody,
boxFooter: boxFooter,
};
//Return elements
return boxElements;
}
}