mirror of
https://github.com/pierre42100/ComunicWeb
synced 2025-06-19 12:25:16 +00:00
User select functionnal
This commit is contained in:
@ -502,6 +502,13 @@ var ComunicWeb = {
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* User selector
|
||||
*/
|
||||
userSelect:{
|
||||
//TODO : implement
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
78
assets/js/components/userSelect/userSelect.js
Normal file
78
assets/js/components/userSelect/userSelect.js
Normal file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
* User selector (using select2)
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
ComunicWeb.components.userSelect = {
|
||||
|
||||
/**
|
||||
* Initialize user selector for an element of the page
|
||||
*
|
||||
* @param {HTMLElement} inputSelect The target select input
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
init: function(inputSelect){
|
||||
|
||||
//Log action
|
||||
ComunicWeb.debug.logMessage("INFO : Initialize user selector");
|
||||
|
||||
$(inputSelect).select2({
|
||||
ajax: {
|
||||
transport: function(params, success, failure){
|
||||
|
||||
//Check if some data were passed or not
|
||||
if(!params.data.term)
|
||||
return false;
|
||||
|
||||
//Retrive users list
|
||||
ComunicWeb.user.userInfos.search(params.data.term, function(usersInfos){
|
||||
|
||||
if(usersInfos.error)
|
||||
return; // Doesn't do anything failure();
|
||||
else{
|
||||
//Prepare results processing
|
||||
returnData = {
|
||||
results: []
|
||||
}
|
||||
|
||||
//Processing results
|
||||
for(i in usersInfos){
|
||||
returnData.results.push({
|
||||
id: usersInfos[i].userID,
|
||||
text: usersInfos[i].firstName + " " + usersInfos[i].lastName,
|
||||
accountImage: usersInfos[i].accountImage,
|
||||
});
|
||||
}
|
||||
|
||||
//Return result
|
||||
success(returnData);
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
delay: 250,
|
||||
},
|
||||
|
||||
//Format result displaying
|
||||
templateResult: ComunicWeb.components.userSelect.formatUser,
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Format the display of a user
|
||||
*
|
||||
* @param {Object} infos Informations about the user
|
||||
* @return {String} The formated informations
|
||||
*/
|
||||
formatUser: function(infos){
|
||||
console.log(infos);
|
||||
|
||||
if(!infos.id)
|
||||
return infos.id;
|
||||
|
||||
return $("<img src='"+infos.accountImage+"' class='user-select-image' /> <span>" + infos.text + "</span>");
|
||||
},
|
||||
|
||||
};
|
@ -27,6 +27,18 @@ ComunicWeb.pages.home.home = {
|
||||
});
|
||||
loginButton.innerHTML="Logout";
|
||||
targetElement.appendChild(loginButton);
|
||||
|
||||
//Create select user element
|
||||
var formGroup = createElem("div", targetElement);
|
||||
formGroup.className = "form-group";
|
||||
var selectElement = createElem("select", formGroup);
|
||||
selectElement.className = "form-control select2";
|
||||
selectElement.setAttribute("multiple", "multiple");
|
||||
selectElement.setAttribute("data-placeholder", "Select users");
|
||||
|
||||
//Initialize user selector
|
||||
ComunicWeb.components.userSelect.init(selectElement);
|
||||
|
||||
}
|
||||
else{
|
||||
//Display landing page
|
||||
|
Reference in New Issue
Block a user