Progress on search user component

This commit is contained in:
Pierre 2017-05-27 11:57:05 +02:00
parent 0effce56c2
commit 32cf8601f7
6 changed files with 82 additions and 9 deletions

View File

@ -57,7 +57,7 @@ ComunicWeb.common.api.makeAPIrequest = function(apiURI, params, requireLoginToke
//We check if we got any error
if(result.error){
//Log error
ComunicWeb.debug.logMessage("Got an error in a XHR request! " + result.toString());
ComunicWeb.debug.logMessage("Got an error in a XHR request! \n Request URL: "+requestURL+" \n Response : "+apiXHR.responseText);
}
//We can do the next step

View File

@ -0,0 +1,19 @@
/**
* Helpers
*
* @author Pierre HUBERT
*/
/**
* Returns the path pointing on an asset
*
* @param {String} assetURI Optionnal, the URI of the asset
* @return {String} The full URL path of the asset
*/
function path_assets(assetURI){
if(!assetURI)
assetURI = "";
return ComunicWeb.__config.assetsURL+assetURI;
}

View File

@ -104,7 +104,7 @@ ComunicWeb.components.menuBar.authenticated = {
userNameElem.innerHTML = "Loading...";
//Make a request to get informations about the user
ComunicWeb.user.getUserInfos.getUserInfos("current", (function(userInfos){
ComunicWeb.user.userInfos.getUserInfos("current", (function(userInfos){
//Change user name
userNameElem.innerHTML = userInfos.firstName + " "+ userInfos.lastName;
@ -124,7 +124,7 @@ ComunicWeb.components.menuBar.authenticated = {
addSearchForm: function(navbarElem){
//Create form element
var searchForm = createElem("li", navbarElem);
searchForm.className = "dropdown navbar-form navbar-left notifications-menu";
searchForm.className = "dropdown navbar-form navbar-left messages-menu";
searchForm.setAttribute("role", "search");
//Create form group

View File

@ -74,19 +74,71 @@ ComunicWeb.components.searchForm = {
params = {
query: textInput.value,
};
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, function(){
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, function(response){
//Continue only in case of success
if(response.error)
return false;
//Remove any remainging element in searchResultBox
console.log("result");
emptyElem(searchBoxContainer);
//Create menu list
var menuList = createElem("ul", searchBoxContainer);
menuList.className = "menu";
//Process each result
for(i in response){
//Retrieve userID
var userID = response[i];
//Display user informations
ComunicWeb.components.searchForm.displayUser(userID, menuList);
}
//Enable slimscroll
/*$(menuList).slimScroll({
$(menuList).slimScroll({
height: '200px',
}));*/
});
});
},
/**
* Display a user on the result list
*
* @param {Integer} userID The ID of the user to display
* @param {HTMLElement} menuList The target list menu
* @return {Boolean} True for a success
*/
displayUser: function(userID, menuList){
//Create user element
var userListElement = createElem("li", menuList);
var userLinkElement = createElem("a", userListElement);
//User account image
var userAccountImageContainer = createElem("div", userLinkElement);
userAccountImageContainer.className = "pull-left";
var userImage = createElem("img", userAccountImageContainer);
userImage.className = "img-circle";
userImage.alt = "User image";
userImage.src = path_assets("img/defaultAvatar.png");
//User name
var usernameElem = createElem("h4", userLinkElement);
usernameElem.innerHTML = "Loading...";
//Get informations about user
ComunicWeb.user.userInfos.getUserInfos(userID, function(userInfos){
//Apply informations
userImage.src = userInfos.accountImage;
usernameElem.innerHTML = userInfos.firstName + " " + userInfos.lastName;
});
},
}

View File

@ -4,7 +4,7 @@
* @author Pierre HUBERT
*/
ComunicWeb.user.getUserInfos = {
ComunicWeb.user.userInfos = {
/**
* @var {String} User infos cache
@ -30,6 +30,7 @@ ComunicWeb.user.getUserInfos = {
}
else{
ComunicWeb.debug.logMessage("ERROR : getUserInfos not implemented for other user than the current one !");
return false;
}
//Specify what to do next
@ -40,7 +41,7 @@ ComunicWeb.user.getUserInfos = {
}
//Save result
ComunicWeb.user.getUserInfos.usersInfos[""+userID] = result[0];
ComunicWeb.user.userInfos.usersInfos[""+userID] = result[0];
//Return result
afterGetUserInfos(result[0]);

View File

@ -82,6 +82,7 @@ $config['JSfiles'] = array(
//Create shortcuts for common functions
"%PATH_ASSETS%js/common/shorcuts.js",
"%PATH_ASSETS%js/common/helpers.js",
//Init script
"%PATH_ASSETS%js/init.js",