mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 01:48:50 +00:00
Progress on search user component
This commit is contained in:
parent
0effce56c2
commit
32cf8601f7
@ -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
|
||||
|
19
assets/js/common/helpers.js
Normal file
19
assets/js/common/helpers.js
Normal 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;
|
||||
}
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
});
|
||||
},
|
||||
}
|
@ -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]);
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user