diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 04e548d8..bead7442 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -352,6 +352,11 @@ var ComunicWeb = { * Remove all entries from user informations cache */ emptyUserInfosCache: function(){}, + + /** + * Given a query, search for users and return the result + */ + search: function(query, afterSearch){}, }, }, diff --git a/assets/js/user/userInfos.js b/assets/js/user/userInfos.js index bb0e6903..4a34ad5d 100644 --- a/assets/js/user/userInfos.js +++ b/assets/js/user/userInfos.js @@ -136,4 +136,33 @@ ComunicWeb.user.userInfos = { return true; }, + + /** + * Given a query, search for users and return the result + * + * @param {String} query The query to search + * @param {Function} afterSearch What to do once we got results + * @return {Boolean} True for a success + */ + search: function(query, afterSearch){ + //Perform a request on the server + apiURI = "user/search"; + params = { + query: query, + }; + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, function(response){ + + //Continue only in case of success + if(response.error){ + afterSearch(false); + return false; + } + + //Preload users informations + ComunicWeb.user.userInfos.getMultipleUsersInfos(response, function(usersInfos){ + //Go to next action + afterSearch(usersInfos); + }); + }); + } } \ No newline at end of file