2017-05-21 15:55:19 +00:00
|
|
|
/**
|
2017-05-24 12:31:56 +00:00
|
|
|
* Menu bar object - common methods
|
2017-05-21 15:55:19 +00:00
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
2017-05-24 12:31:56 +00:00
|
|
|
ComunicWeb.components.menuBar.common = {
|
2017-05-21 15:55:19 +00:00
|
|
|
/**
|
|
|
|
* Display menu bar
|
|
|
|
*
|
|
|
|
* @return {Boolean} True for a success
|
|
|
|
*/
|
|
|
|
display: function(){
|
|
|
|
//Log message
|
|
|
|
ComunicWeb.debug.logMessage("Display menu bar");
|
|
|
|
|
|
|
|
//Try to get menubar element
|
|
|
|
var menuBar = byId("menuBar");
|
|
|
|
|
|
|
|
//We check if the menubar is present or not on the page
|
|
|
|
if(menuBar){
|
2017-05-24 16:48:52 +00:00
|
|
|
|
|
|
|
//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;
|
|
|
|
}
|
|
|
|
|
2017-05-21 15:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//So we have to initializate it
|
|
|
|
//Create menubar element
|
2017-05-21 16:10:55 +00:00
|
|
|
var menuBar = createElem("header");
|
2017-05-21 15:55:19 +00:00
|
|
|
byId("wrapper").insertBefore(menuBar, byId("wrapper").childNodes[0]);
|
|
|
|
menuBar.id = "menuBar";
|
2019-05-11 14:19:13 +00:00
|
|
|
menuBar.className = "main-header";
|
2017-05-21 15:55:19 +00:00
|
|
|
|
|
|
|
//Initializate the menubar
|
|
|
|
return this.init(menuBar);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializate a menubar
|
|
|
|
*
|
2017-05-21 16:10:55 +00:00
|
|
|
* @param {HTMLElement} menuContainer The menu container
|
2017-05-21 15:55:19 +00:00
|
|
|
* @return {Boolan} True for a success
|
|
|
|
*/
|
2017-05-21 16:10:55 +00:00
|
|
|
init: function(menuContainer){
|
2017-05-21 15:55:19 +00:00
|
|
|
//Log action
|
2017-05-21 16:10:55 +00:00
|
|
|
ComunicWeb.debug.logMessage("Info: Initializate a menuBar in element : '"+menuContainer.id+"'");
|
2019-05-11 14:19:13 +00:00
|
|
|
|
2017-05-24 12:31:56 +00:00
|
|
|
|
2017-05-24 16:48:52 +00:00
|
|
|
//Save login information in menubar before continuing
|
2018-07-20 07:23:32 +00:00
|
|
|
menuContainer.setAttribute("forActiveUser", signed_in());
|
2017-05-24 16:48:52 +00:00
|
|
|
|
2017-05-24 12:31:56 +00:00
|
|
|
//Call specific menu
|
2018-07-20 07:23:32 +00:00
|
|
|
if(signed_in()){
|
2017-05-25 11:50:32 +00:00
|
|
|
//Call authenticated menubar
|
2019-05-11 14:19:13 +00:00
|
|
|
ComunicWeb.components.menuBar.authenticated.addElements(menuContainer);
|
2017-05-24 12:31:56 +00:00
|
|
|
}
|
2019-05-11 14:19:13 +00:00
|
|
|
else {
|
2017-05-25 11:50:32 +00:00
|
|
|
//Call not-logged-in menubar
|
2019-05-11 14:19:13 +00:00
|
|
|
ComunicWeb.components.menuBar.notAuthenticated.addElements(menuContainer);
|
2017-05-24 12:31:56 +00:00
|
|
|
}
|
2017-05-21 15:55:19 +00:00
|
|
|
},
|
2017-05-24 16:48:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
}
|
2017-05-21 15:55:19 +00:00
|
|
|
};
|