ComunicWeb/assets/js/components/menuBar/notAuthenticated.js

130 lines
3.8 KiB
JavaScript
Raw Normal View History

/**
* Not authenticated menu bar components
*
* @author Pierre HUBERT
*/
2021-12-30 09:23:47 +00:00
const NotAuthenticatedMenuBar = {
2017-05-24 16:05:09 +00:00
/**
* Add not-authenticated user specific elements
*
2019-05-11 14:19:13 +00:00
* @param {HTMLElement} menuHeader The container element of the Menubar
2017-05-24 16:05:09 +00:00
*/
2019-05-11 14:19:13 +00:00
addElements: function(menuHeader){
//Create main menu
var menuElem = createElem("div", menuHeader);
menuElem.className = "navbar navbar-static-top";
//Create nav element
var navElem = createElem("nav", menuElem);
navElem.className = "navbar navbar-static-top";
//Create conatiner
var container = createElem("div", navElem);
container.className = "container";
//Create navbar header
var navbarHeader = createElem("div", container);
navbarHeader.className = "navbar-header";
//Create site name link
var siteNameElem = createElem("a", navbarHeader);
siteNameElem.className = "navbar-brand";
siteNameElem.innerText = "Comunic";
siteNameElem.onclick = (function(){
ComunicWeb.common.page.openPage("home");
});
//Create navbar collapsed button
var navbarCollapsedButton = createElem("button", navbarHeader);
navbarCollapsedButton.type = "button";
navbarCollapsedButton.className = "navbar-toggle collapsed";
navbarCollapsedButton.setAttribute("data-toggle", "collapse");
navbarCollapsedButton.setAttribute("data-target", "#navbar-collapse");
//Create navbar icon
var navbarCollapsIcon = createElem("i", navbarCollapsedButton);
navbarCollapsIcon.className = "fa fa-bars";
2017-05-24 16:05:09 +00:00
//Create an auto-collapsed element
var navbarCollapse = createElem("div", container);
navbarCollapse.id = "navbar-collapse";
navbarCollapse.className = "navbar-collapse pull-right collapse";
//Create login form
var loginForm = createElem("form", navbarCollapse);
loginForm.className = "navbar-form navbar-left menubar-loginForm";
loginForm.setAttribute("role", "login");
//Add email address formGroup
var emailFormGroup = createElem("div", loginForm);
emailFormGroup.className = "form-group";
//Add email input
var emailInput = createElem("input", emailFormGroup);
emailInput.className = "form-control";
2018-02-23 10:46:21 +00:00
emailInput.placeholder = lang("_menu_bar_login_email");
2017-05-24 16:05:09 +00:00
emailInput.type = "email";
emailInput.value = ComunicWeb.components.mailCaching.get();
//Add password formGroup
var passwordFormGroup = createElem("div", loginForm);
passwordFormGroup.className = "form-group";
//Add password input
var passwordInput = createElem("input", passwordFormGroup);
passwordInput.className = "form-control";
2018-02-23 10:46:21 +00:00
passwordInput.placeholder = lang("_menu_bar_login_passwd");
2017-05-24 16:05:09 +00:00
passwordInput.type = "password";
//Add submit button formGroup
var submitFromGroup = createElem("div", loginForm);
submitFromGroup.className = "form-group";
//Add submit input
var submitInput = createElem("input", submitFromGroup);
submitInput.className = "form-control";
2018-02-23 10:46:21 +00:00
submitInput.value = lang("_menu_bar_login_btn");
2017-05-24 16:05:09 +00:00
submitInput.type = "submit";
//Add submit form behaviour
loginForm.onsubmit = function(){
//Enable screen overlay (use .remove() to remove)
var screenOverlay = ComunicWeb.common.page.showTransparentWaitSplashScreen();
//Try to login user; in case of failure redirect to login page
//What to do once user is logged in (or not)
var afterTryLogin = function(loginResult){
//First, remove overlay
screenOverlay.remove();
//Check if login failed
if(!loginResult){
//Redirect to login page
ComunicWeb.common.page.openPage("login", {
loginFailedMessage: true,
emailInput: emailInput.value,
});
//Return false
return false;
}
//Open home page
ComunicWeb.common.page.openPage("home");
};
//Try to login user
2017-06-03 14:51:22 +00:00
ComunicWeb.user.userLogin.loginUser(emailInput.value, passwordInput.value, true, afterTryLogin);
2017-05-24 16:05:09 +00:00
//Block form
return false;
}
2021-12-30 09:23:47 +00:00
MenubarBanner.addBanner(menuHeader)
2017-05-24 16:05:09 +00:00
}
}