From 7eb6bf383c494789f71fe7eaf0b7ca7e36e61ce0 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 31 May 2017 16:51:52 +0200 Subject: [PATCH] Splited friends component --- assets/js/common/functionsSchema.js | 16 +++- .../js/components/friendsList/friendsBar.js | 91 +++++++++++++++++++ .../js/components/friendsList/friendsList.js | 90 +----------------- 3 files changed, 109 insertions(+), 88 deletions(-) create mode 100644 assets/js/components/friendsList/friendsBar.js diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 992d2ff2..dbdb9cae 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -444,8 +444,20 @@ var ComunicWeb = { /** * Friends list */ - friendsList: { - //TODO : implement + friends: { + /** + * Friends list caching system + */ + list:{ + + }, + + /** + * Friends bar + */ + bar:{ + + }, } }, diff --git a/assets/js/components/friendsList/friendsBar.js b/assets/js/components/friendsList/friendsBar.js new file mode 100644 index 00000000..daf213dc --- /dev/null +++ b/assets/js/components/friendsList/friendsBar.js @@ -0,0 +1,91 @@ +/** + * Friends bar + * + * @author Pierre HUBERT + */ + +ComunicWeb.components.friends.bar = { + + /** + * Display friends list + * + * @return {Boolean} True for a success + */ + display: function(){ + //Log action + ComunicWeb.debug.logMessage("Initialize friends list."); + + //Check if friends list already exists or not + var friendsListContainer = byId("friendsList"); + + //We check if the friend list already exists or not + if(friendsListContainer){ + ComunicWeb.debug.logMessage("Notice: friend list already present on the page. Nothing to be done."); + return true; + } + + //Create and apply friends list element + var friendsListContainer = createElem("div"); + friendsListContainer.id = "friendsList"; + + //Check if "pageTarget" already exists or not + var pageTarget = byId("pageTarget"); + if(pageTarget){ + //Insert friends list just before pageTarget + byId("wrapper").insertBefore(friendsListContainer, pageTarget); + } + else{ + byId("wrapper").appendChild(friendsListContainer); //Just happend the menubar + } + + //Initializate friends list + this.init(friendsListContainer); + + //Success + return true; + }, + + /** + * Initializate a friend list + * + * @param {HTMLElement} friendsListContainer The container of the friend list + * @return {Boolean} True for a success + */ + init: function(friendsListContainer){ + + //First, create the table container + var listFriendsElem = createElem("table", friendsListContainer); + listFriendsElem.className = "table table-condensed"; + + //Refresh friends list + this.refresh(listFriendsElem); + + //Success + return true; + }, + + /** + * Refresh a friend list + * + * @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){ + + //Check for error + if(result.error){ + ComunicWeb.debug.logMessage("Couldn't get a new version of friends list !"); + return false; + } + + //Log information + ComunicWeb.debug.logMessage("Got a new version of friends list !"); + }); + }, +} \ No newline at end of file diff --git a/assets/js/components/friendsList/friendsList.js b/assets/js/components/friendsList/friendsList.js index 50685be8..fc311512 100644 --- a/assets/js/components/friendsList/friendsList.js +++ b/assets/js/components/friendsList/friendsList.js @@ -1,91 +1,9 @@ /** - * Friends list + * Friends list caching system * * @author Pierre HUBERT */ -ComunicWeb.components.friendsList = { - - /** - * Display friends list - * - * @return {Boolean} True for a success - */ - display: function(){ - //Log action - ComunicWeb.debug.logMessage("Initialize friends list."); - - //Check if friends list already exists or not - var friendsListContainer = byId("friendsList"); - - //We check if the friend list already exists or not - if(friendsListContainer){ - ComunicWeb.debug.logMessage("Notice: friend list already present on the page. Nothing to be done."); - return true; - } - - //Create and apply friends list element - var friendsListContainer = createElem("div"); - friendsListContainer.id = "friendsList"; - - //Check if "pageTarget" already exists or not - var pageTarget = byId("pageTarget"); - if(pageTarget){ - //Insert friends list just before pageTarget - byId("wrapper").insertBefore(friendsListContainer, pageTarget); - } - else{ - byId("wrapper").appendChild(friendsListContainer); //Just happend the menubar - } - - //Initializate friends list - this.init(friendsListContainer); - - //Success - return true; - }, - - /** - * Initializate a friend list - * - * @param {HTMLElement} friendsListContainer The container of the friend list - * @return {Boolean} True for a success - */ - init: function(friendsListContainer){ - - //First, create the table container - var listFriendsElem = createElem("table", friendsListContainer); - listFriendsElem.className = "table table-condensed"; - - //Refresh friends list - this.refresh(listFriendsElem); - - //Success - return true; - }, - - /** - * Refresh a friend list - * - * @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){ - - //Check for error - if(result.error){ - ComunicWeb.debug.logMessage("Couldn't get a new version of friends list !"); - return false; - } - - //Log information - ComunicWeb.debug.logMessage("Got a new version of friends list !"); - }); - }, -} \ No newline at end of file +ComunicWeb.components.friends.list = { + +}; \ No newline at end of file