diff --git a/assets/js/common/utils.js b/assets/js/common/utils.js index 74de5f0e..e315840c 100644 --- a/assets/js/common/utils.js +++ b/assets/js/common/utils.js @@ -33,6 +33,7 @@ function createElem(nodeType, appendTo){ * @info {HTMLElement} title The title of the new element * @info {HTMLElement} src The src attribute of the new element * @info {HTMLElement} type The type of the new element + * @info {HTMLElement} value The value of the new element * @info {HTMLElement} innerHTML Specify the html content of the newly created element * @return {HTMLElement} The newly created element */ @@ -68,6 +69,10 @@ function createElem2(infos){ if(infos.type) newElem.type = infos.type; + //Specify element value + if(infos.value) + newElem.value = infos.value; + //Specify node content if(infos.innerHTML) newElem.innerHTML = infos.innerHTML; diff --git a/assets/js/components/conversations/chatWindows.js b/assets/js/components/conversations/chatWindows.js index 44788343..b430be34 100644 --- a/assets/js/components/conversations/chatWindows.js +++ b/assets/js/components/conversations/chatWindows.js @@ -207,6 +207,7 @@ ComunicWeb.components.conversations.chatWindows = { settingsForm.conversationNameInput.value = infos.infos.name; //Update conversation members + ComunicWeb.components.userSelect.pushEntries(settingsForm.usersElement, infos.infos.members); //Update follow conversation checkbox diff --git a/assets/js/components/userSelect/userSelect.js b/assets/js/components/userSelect/userSelect.js index ab835e02..e9dcc793 100644 --- a/assets/js/components/userSelect/userSelect.js +++ b/assets/js/components/userSelect/userSelect.js @@ -100,5 +100,46 @@ ComunicWeb.components.userSelect = { //Return result IDs return usersID; + }, + + /** + * Push entries to user select element + * + * @param {HTMLElement} inputSelect The target element (select2 initialized) + * @param {array} usersID The ID of the users to push in select2 element + * @return {Boolean} True for a success + */ + pushEntries(inputSelect, usersID){ + + //Get informations about the entries + getMultipleUsersInfos(usersID, function(usersInfos){ + + //Check for errors + if(usersInfos.error){ + //Log error + ComunicWeb.debug.logMessage("Error ! Couldn't fill select2 element because a request on the server failed !"); + return false; + } + + //In case of success + var i; + for(i in usersInfos){ + + //Create the new option + var option = createElem2({ + type: "option", + value: usersInfos[i].userID, + innerHTML: usersInfos[i].firstName + " " + usersInfos[i].lastName, + }); + option.setAttribute("selected", "true"); + + //Apply the new option + $(inputSelect).append(option); + $(inputSelect).trigger("change"); + } + }) + + //Success + return true; } }; \ No newline at end of file