2017-01-29 14:49:21 +00:00
|
|
|
/**
|
|
|
|
* User informations functions
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
2017-05-27 09:57:05 +00:00
|
|
|
ComunicWeb.user.userInfos = {
|
2017-01-29 14:49:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var {String} User infos cache
|
|
|
|
*/
|
2017-05-19 16:17:32 +00:00
|
|
|
usersInfos: {},
|
2017-01-29 14:49:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get user informations
|
|
|
|
*
|
|
|
|
* @param {String} userID User on which to make request (current to get connected user)
|
2017-05-19 16:17:32 +00:00
|
|
|
* @param {function} afterGetUserInfos What to do once user informations are available
|
2017-05-27 10:12:39 +00:00
|
|
|
* @return {Boolean} True for a success
|
2017-01-29 14:49:21 +00:00
|
|
|
*/
|
2017-05-19 16:17:32 +00:00
|
|
|
getUserInfos: function(userID, afterGetUserInfos){
|
2017-05-27 10:12:39 +00:00
|
|
|
|
|
|
|
//If requested user is the current user, replace "current" with userID
|
|
|
|
if(userID === "current")
|
|
|
|
userID = ComunicWeb.user.userLogin.__userID;
|
|
|
|
|
2017-05-19 16:17:32 +00:00
|
|
|
//First, check if informations are already available in the cache
|
2017-05-27 10:16:08 +00:00
|
|
|
if(this.usersInfos["user-"+userID]){
|
|
|
|
afterGetUserInfos(this.usersInfos["user-"+userID]); //Then return these informations now
|
2017-05-27 10:12:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-05-19 16:17:32 +00:00
|
|
|
|
|
|
|
//Else we have to perform an API request
|
2017-05-27 10:12:39 +00:00
|
|
|
var apiURI = "user/getInfos";
|
|
|
|
var params = {
|
|
|
|
userID: userID
|
|
|
|
};
|
2017-05-19 16:17:32 +00:00
|
|
|
|
|
|
|
//Specify what to do next
|
|
|
|
var onceGetUserInfos = function(result){
|
|
|
|
if(result.error){
|
|
|
|
ComunicWeb.debug.logMessage("ERROR : couldn't get infos about user ID : "+userID+" !");
|
2017-05-27 10:12:39 +00:00
|
|
|
|
|
|
|
//Returns the error to the next function
|
|
|
|
afterGetUserInfos(result);
|
|
|
|
|
2017-05-19 16:17:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-05-27 10:12:39 +00:00
|
|
|
else {
|
|
|
|
//Save result
|
2017-05-27 10:16:08 +00:00
|
|
|
ComunicWeb.user.userInfos.usersInfos["user-"+userID] = result[0];
|
2017-05-19 16:17:32 +00:00
|
|
|
|
2017-05-27 10:12:39 +00:00
|
|
|
//Return result
|
|
|
|
afterGetUserInfos(result[0]);
|
|
|
|
}
|
2017-05-19 16:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Perform request
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, onceGetUserInfos);
|
|
|
|
|
|
|
|
//Everything is OK
|
|
|
|
return true;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Empty user informations cache
|
|
|
|
* Remove all entries from user informations cache
|
|
|
|
*
|
2017-05-25 13:47:03 +00:00
|
|
|
* @return {Boolean} True for a success
|
2017-05-19 16:17:32 +00:00
|
|
|
*/
|
|
|
|
emptyUserInfosCache: function(){
|
|
|
|
this.userInfos = undefined; //Mark user info cache as undefined
|
|
|
|
this.userInfos = {}; //Create a new variable
|
2017-05-25 13:47:03 +00:00
|
|
|
|
|
|
|
return true;
|
2017-05-19 16:17:32 +00:00
|
|
|
},
|
2017-01-29 14:49:21 +00:00
|
|
|
}
|