From ba5273eafe0bb8900bfb48f13371aa2037ad09ce Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 17 Jun 2017 11:33:15 +0200 Subject: [PATCH] Created conversation creation form --- assets/js/components/conversations/list.js | 45 +++-------------- assets/js/components/conversations/utils.js | 54 ++++++++++++++++++++- 2 files changed, 59 insertions(+), 40 deletions(-) diff --git a/assets/js/components/conversations/list.js b/assets/js/components/conversations/list.js index 47dca4df..5baefe43 100644 --- a/assets/js/components/conversations/list.js +++ b/assets/js/components/conversations/list.js @@ -69,52 +69,19 @@ ComunicWeb.components.conversations.list = { //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"; + //Create the form + var form = ComunicWeb.components.conversations.utils.createConversationForm(listBox.boxBody); //Generate a summary object about all the informations we have got var infos = { listBox: listBox, - usersElement: usersElement, - conversationNameInput: conversationNameInput, - followConversationInput: followConversationInput, + usersElement: form.usersElement, + conversationNameInput: form.conversationNameInput, + followConversationInput: form.followConversationInput, }; //Make button lives - createButton.onclick = function(){ + form.createButton.onclick = function(){ ComunicWeb.components.conversations.list.submitCreateConversationForm(infos); }; diff --git a/assets/js/components/conversations/utils.js b/assets/js/components/conversations/utils.js index 20c3973c..82eb18eb 100644 --- a/assets/js/components/conversations/utils.js +++ b/assets/js/components/conversations/utils.js @@ -52,7 +52,59 @@ ComunicWeb.components.conversations.utils = { //Success return true; - } + }, + + /** + * Create and display a conversation creation / edition form + * + * @param {HTMLElement} target The target of the creation form + * @return {Object} Informations about the form + */ + createConversationForm: function(target){ + + //Create form object + var form = {}; + + //Create and display conversation creation form + form.rootElem = createElem("div", target); + + //Choose users + //Create select user element + form.usersElement = createFormGroup({ + target: form.rootElem, + label: "Users", + multiple: true, + placeholder: "Select users", + type: "select2"}); + + //Initialize user selector + ComunicWeb.components.userSelect.init(form.usersElement); + //Conversation name + form.conversationNameInput = createFormGroup({ + target: form.rootElem, + label: "Conversation name", + placeholder: "Optionnal", + type: "text"}); + + //Follow disucssion + form.followConversationInput = createFormGroup({ + target: form.rootElem, + label: "Follow conversation", + checked: true, + type: "checkbox"}); + + //Create button + form.createButton = createElem2({ + type: "button", + appendTo: form.rootElem, + class: "btn btn-primary", + innerHTML: "Create conversation" + }); + form.createButton.style.width = "100%"; + + //Return result + return form; + }, } \ No newline at end of file