From 174ad6779a877736453d34e66067fe5e760cc594 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 31 May 2017 17:12:51 +0200 Subject: [PATCH] Progress on friend bar --- assets/js/common/page.js | 2 +- .../{friendsList => friends}/friendsBar.js | 33 ++++++---- assets/js/components/friends/friendsList.js | 65 +++++++++++++++++++ .../js/components/friendsList/friendsList.js | 9 --- corePage/config/dev.config.php | 3 +- 5 files changed, 89 insertions(+), 23 deletions(-) rename assets/js/components/{friendsList => friends}/friendsBar.js (75%) create mode 100644 assets/js/components/friends/friendsList.js delete mode 100644 assets/js/components/friendsList/friendsList.js diff --git a/assets/js/common/page.js b/assets/js/common/page.js index 0d003d46..4c24fbbe 100644 --- a/assets/js/common/page.js +++ b/assets/js/common/page.js @@ -187,7 +187,7 @@ ComunicWeb.common.page = { //We load specific components for logged in users if(ComunicWeb.user.userLogin.getUserLoginState()){ //We load frieds list (if user is logged in) - ComunicWeb.components.friendsList.display(); + ComunicWeb.components.friends.bar.display(); } } diff --git a/assets/js/components/friendsList/friendsBar.js b/assets/js/components/friends/friendsBar.js similarity index 75% rename from assets/js/components/friendsList/friendsBar.js rename to assets/js/components/friends/friendsBar.js index daf213dc..46771788 100644 --- a/assets/js/components/friendsList/friendsBar.js +++ b/assets/js/components/friends/friendsBar.js @@ -65,27 +65,36 @@ ComunicWeb.components.friends.bar = { }, /** - * Refresh a friend list + * Refresh the listbar * * @param {HTMLElement} listFriendsElem The element that contains the list of friens * @return {Boolean} True for a success */ refresh: function(listFriendsElem){ - //First, perform an API request - var apiURI = "friends/getList"; - var params = {}; - - //Perform request - ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, function(result){ - + //Refresh it + ComunicWeb.components.friends.list.refresh(function(list){ //Check for error - if(result.error){ - ComunicWeb.debug.logMessage("Couldn't get a new version of friends list !"); + if(!list){ + //Log information + ComunicWeb.debug.logMessage("ERROR : Can't refresh menubar without the latest list !"); + + //Error return false; } - //Log information - ComunicWeb.debug.logMessage("Got a new version of friends list !"); + //Get users list to get information about them + usersID = {}; + for(i in list){ + //Extract user id + var processID = list[i].ID_friend; + + usersID["user_"+processID] = processID; + } + + //Get users ID informations + ComunicWeb.user.userInfos.getMultipleUsersInfos(usersID, function(usersInfo){ + console.log(usersInfo); + }); }); }, } \ No newline at end of file diff --git a/assets/js/components/friends/friendsList.js b/assets/js/components/friends/friendsList.js new file mode 100644 index 00000000..b16e901d --- /dev/null +++ b/assets/js/components/friends/friendsList.js @@ -0,0 +1,65 @@ +/** + * Friends list caching system + * + * @author Pierre HUBERT + */ + +ComunicWeb.components.friends.list = { + /** + * Last list cached + */ + __list: {}, + + /** + * Refresh the list + * + * @param {Function} afterRefreshList What to do next + * @return {Boolean} True for a success + */ + refresh: function(afterRefreshList){ + + //First, perform an API request + var apiURI = "friends/getList"; + var params = {}; + + //Perform request + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, function(result){ + + //Check for error + if(result.error){ + ComunicWeb.debug.logMessage("Couldn't get a new version of friends list !"); + + //Perform next action... + afterRefreshList(false); + + //Error + return false; + } + + //Log information + ComunicWeb.debug.logMessage("Got a new version of friends list !"); + + //Cache the new list + ComunicWeb.components.friends.list.__list = result; + + //Perform next action + afterRefreshList(result); + + //Success + return true; + }); + + //It is a success + return true; + }, + + /** + * Get the list + * + * @return {Object} The list + */ + get: function(){ + //Return the list + return this.__list; + } +}; \ No newline at end of file diff --git a/assets/js/components/friendsList/friendsList.js b/assets/js/components/friendsList/friendsList.js deleted file mode 100644 index fc311512..00000000 --- a/assets/js/components/friendsList/friendsList.js +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Friends list caching system - * - * @author Pierre HUBERT - */ - -ComunicWeb.components.friends.list = { - -}; \ No newline at end of file diff --git a/corePage/config/dev.config.php b/corePage/config/dev.config.php index 27ccbb75..b70edf64 100644 --- a/corePage/config/dev.config.php +++ b/corePage/config/dev.config.php @@ -68,7 +68,8 @@ $config['JSfiles'] = array( "%PATH_ASSETS%js/components/menuBar/common.js", "%PATH_ASSETS%js/components/menuBar/notAuthenticated.js", "%PATH_ASSETS%js/components/menuBar/authenticated.js", - "%PATH_ASSETS%js/components/friendsList/friendsList.js", + "%PATH_ASSETS%js/components/friends/friendsList.js", + "%PATH_ASSETS%js/components/friends/friendsBar.js", //User scripts "%PATH_ASSETS%js/user/loginTokens.js",