From 633c4f9400ce9a7cd7f9e19b28a11b2582796801 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 24 May 2017 18:48:52 +0200 Subject: [PATCH] Fixed menubar issue with login management --- assets/js/common/page.js | 4 ++++ assets/js/common/utils.js | 23 +++++++++++++++++- assets/js/components/menuBar/common.js | 33 ++++++++++++++++++++++++-- assets/js/pages/logout.js | 7 ++++-- 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/assets/js/common/page.js b/assets/js/common/page.js index 7fafcd5a..21f124ec 100644 --- a/assets/js/common/page.js +++ b/assets/js/common/page.js @@ -168,6 +168,10 @@ ComunicWeb.common.page = { //Set wrapper class pageTarget.className = "content-wrapper"; + //Ask adminLTE to fix layout + if($.AdminLTE.layout) + $.AdminLTE.layout.fix(); + //Set body class document.body.className="hold-transition skin-blue layout-top-nav"; diff --git a/assets/js/common/utils.js b/assets/js/common/utils.js index fd1400fe..6d0fde93 100644 --- a/assets/js/common/utils.js +++ b/assets/js/common/utils.js @@ -25,12 +25,33 @@ function createElem(nodeType, appendTo){ * Get an HTML element specified by an ID * * @param {String} nodeName The ID of the element - * @return {HTMLElement} The elemnt / False for a failure + * @return {HTMLElement} The element / False for a failure */ function byId(nodeName){ return document.getElementById(nodeName); } +/** + * Remove all nodes of a specified HTML element + * + * @param {HTMLElement} container The container to empty + * @return {Boolean} True for a success + */ +function emptyElem(container){ + //Get children references + var children = container.childNodes; + + //Process each child + for(i in children){ + if(children[i].remove) + children[i].remove(); + } + + + //Success + return true; +} + /** * Check a given email address * diff --git a/assets/js/components/menuBar/common.js b/assets/js/components/menuBar/common.js index 72e0e36a..9a129b95 100644 --- a/assets/js/components/menuBar/common.js +++ b/assets/js/components/menuBar/common.js @@ -19,8 +19,18 @@ ComunicWeb.components.menuBar.common = { //We check if the menubar is present or not on the page if(menuBar){ - ComunicWeb.debug.logMessage("Info: The menubar is already present on the page"); - return true; + + //We check if menubar is made for a logged user when not any is logged in or vice-versa + if(menuBar.getAttribute("forActiveUser") !== ComunicWeb.user.userLogin.getUserLoginState().toString()){ + //Remove previously created menuBar + this.reset(menuBar); + } + else { + //Nothing to be done + ComunicWeb.debug.logMessage("Info: The menubar is already present on the page"); + return true; + } + } //So we have to initializate it @@ -84,6 +94,9 @@ ComunicWeb.components.menuBar.common = { //Now we need to know if user is logged in or not var userLoggedIn = ComunicWeb.user.userLogin.getUserLoginState(); + //Save login information in menubar before continuing + menuContainer.setAttribute("forActiveUser", userLoggedIn); + //Call specific menu if(userLoggedIn){ //Not implemented yet @@ -93,4 +106,20 @@ ComunicWeb.components.menuBar.common = { ComunicWeb.components.menuBar.notAuthenticated.addElements(containerElem); } }, + + /** + * Reset a specified menubar + * + * @param {HTMLElement} menuBar The menuBar to reset + * @return {Boolean} True for a success + */ + reset: function(menuBar){ + + //Log action + ComunicWeb.debug.logMessage("Cleaning a menuBar element."); + + //Perform action + return emptyElem(menuBar); + + } }; \ No newline at end of file diff --git a/assets/js/pages/logout.js b/assets/js/pages/logout.js index 33428076..5c6b3f68 100644 --- a/assets/js/pages/logout.js +++ b/assets/js/pages/logout.js @@ -21,10 +21,13 @@ ComunicWeb.pages.logout = { ComunicWeb.user.userLogin.logoutUser(); //Show a success notification - ComunicWeb.common.notificationSystem.showNotification("Good bye, you were sucessfully logouted !", "sucess", 5); + ComunicWeb.common.notificationSystem.showNotification("Good bye, you sucessfully terminated your session !", "sucess", 5); //Open login page - ComunicWeb.common.page.openPage("login"); + ComunicWeb.common.page.openPage("home"); + + //Remove overlay + screenOverlay.remove(); }, }; \ No newline at end of file