ComunicWeb/assets/js/components/menuBar/authenticated.js

376 lines
9.0 KiB
JavaScript
Raw Permalink Normal View History

/**
* Menubar for authenticated users complements
*
* @author Pierre HUBERT
*/
2021-12-30 09:23:47 +00:00
const AuthenticatedMenuBar = {
/**
* Dropdown menu links list
*/
dropdownMenuLinksList: [
//Conversations
{
innerLang: "menu_bar_action_conversations",
2019-01-11 10:54:22 +00:00
targetPage: "conversations",
icon: "fa-comments-o"
},
//Groups list
{
innerLang: "menu_bar_action_groups",
targetPage: "groups",
2019-01-11 10:54:22 +00:00
icon: "fa-group"
},
//Dark theme
{
innerLang: "menu_bar_action_dark_theme",
2021-12-30 09:23:47 +00:00
onclick: function(b){AuthenticatedMenuBar.darkThemeButtonClicked(true, b)},
oninit: function(b){AuthenticatedMenuBar.darkThemeButtonClicked(false, b)},
icon: "fa-sun-o"
},
//Settings list
{
innerLang: "menu_bar_action_settings",
2019-01-11 10:54:22 +00:00
targetPage: "settings",
icon: "fa-gear"
},
//Logout link
{
innerLang: "_menu_bar_action_logout",
2019-01-11 10:54:22 +00:00
targetPage: "logout",
icon: "fa-sign-out"
}
],
/**
* Add authenticated user specific elements
*
* @param {HTMLElement} container The container element of the Menubar
*/
addElements: function(container){
2019-05-11 14:19:13 +00:00
2021-12-30 09:23:47 +00:00
// Site name
2019-05-11 14:19:13 +00:00
createElem2({
appendTo: container,
type: "a",
class: "logo",
internalHref: "#",
innerHTML: "<span class='logo-mini'>C</span><span class='logo-lg'>Comunic</span>"
});
// Navbar
var navBar = createElem2({
appendTo: container,
type: "nav",
class: "navbar navbar-static-top"
});
// Sidebar toggle
createElem2({
appendTo: navBar,
type: "a",
class: "sidebar-toggle",
href: "#",
}).setAttribute("data-toggle", "offcanvas");
//Create an auto-collapsed element
2019-05-11 14:19:13 +00:00
var navbarCollapse = createElem("div", navBar);
navbarCollapse.id = "navbar-collapse";
2017-05-26 09:38:37 +00:00
navbarCollapse.className = "navbar-collapse pull-left collapse";
//Create navbar elements list
2017-05-26 09:38:37 +00:00
var navbarCollapseElemList = createElem("ul", navbarCollapse);
navbarCollapseElemList.className = "nav navbar-nav";
//Add search form
2019-05-11 15:03:09 +00:00
//this.addSearchForm(navbarCollapseElemList);
2017-05-26 09:38:37 +00:00
//Navbar right elements
2019-05-11 14:19:13 +00:00
var navbarRight = createElem("div", navBar);
2017-05-26 09:38:37 +00:00
navbarRight.className = "navbar-custom-menu";
var navbarRightElemList = createElem("ul", navbarRight);
navbarRightElemList.className = "nav navbar-nav";
2017-05-25 13:06:01 +00:00
//Add user name
2019-05-16 16:14:02 +00:00
//this.addUserName(navbarRightElemList);
2017-05-25 13:06:01 +00:00
2018-08-03 13:27:56 +00:00
//Alternate latest posts button
this.addAlternateLatestPostsButton(navbarRightElemList);
2017-06-03 13:41:04 +00:00
//Add friends list button
2019-05-16 16:14:02 +00:00
//this.addFriendListButton(navbarRightElemList);
2017-06-03 13:41:04 +00:00
2018-02-18 18:12:17 +00:00
//Add notifications dropdown
ComunicWeb.components.notifications.dropdown.display(navbarRightElemList);
//Add dropdown menu
2017-05-26 09:38:37 +00:00
this.addDropdown(navbarRightElemList);
2021-12-30 09:23:47 +00:00
// Banner
const banner = MenubarBanner.addBanner(undefined)
if(banner) {
container.parentNode.insertBefore(banner, container.nextElementSibling)
banner.classList.add("content-wrapper")
}
},
/**
* Add dropdown menu
*
* @param {HTMLElement} navbarElem The target navbarlist element
2017-05-25 13:06:01 +00:00
* @return {HTMLElement} The dropdown content element
*/
addDropdown: function(navbarElem){
//Create dropdown menu
var dropdown = createElem("li", navbarElem);
2017-05-26 09:38:37 +00:00
dropdown.className = "dropdown dropdown-user-menu-action";
//Add dropdown button
var dropdownButton = createElem("a", dropdown);
dropdownButton.className = "dropdown-toggle";
dropdownButton.setAttribute("data-toggle", "dropdown");
2017-05-25 12:06:37 +00:00
//Add dropdown button icon
var dropdownButtonIcon = createElem("i", dropdownButton);
dropdownButtonIcon.className = "fa fa-gear";
2017-05-25 13:06:01 +00:00
//Add space
2017-05-25 12:06:37 +00:00
dropdownButton.innerHTML += " ";
//Add dropdown button arrow
var dropdownButtonArrow = createElem("span", dropdownButton);
dropdownButtonArrow.className = "caret";
//Create dropdown menu content
var dropdownContent = createElem("ul", dropdown);
dropdownContent.className = "dropdown-menu"
dropdownContent.setAttribute("role", "menu");
2018-05-13 12:06:32 +00:00
//Process links list
2019-01-11 10:54:22 +00:00
var addMenuOption = function(entry){
2018-07-02 06:07:59 +00:00
var linkButton = createElem2({
appendTo: dropdownContent,
type: "li"
});
var link = createElem2({
appendTo: linkButton,
type: "a",
2019-01-11 10:54:22 +00:00
href: entry.href,
innerLang: entry.innerLang,
innerHTML: entry.innerHTML,
innerHTMLprefix: entry.icon ? "<i class='fa " + entry.icon + "'></i> " : undefined,
});
if(entry.targetPage){
linkButton.onclick = function(){
openPage(entry.targetPage);
};
}
2018-04-12 14:17:41 +00:00
2019-01-11 10:54:22 +00:00
if(entry.target)
link.setAttribute("target", entry.target);
if(entry.onclick){
linkButton.addEventListener("click", function(){
entry.onclick(link);
});
}
2019-01-10 14:44:39 +00:00
if(entry.oninit){
entry.oninit(link);
}
2019-01-11 10:54:22 +00:00
};
2019-01-11 10:54:22 +00:00
this.dropdownMenuLinksList.forEach(addMenuOption);
//Add divider
createElem2({
appendTo: dropdownContent,
type: "li",
class: "divider"
});
2019-01-11 10:54:22 +00:00
2021-02-20 10:13:42 +00:00
BottomLinks().forEach(addMenuOption);
2017-05-25 13:06:01 +00:00
//Return dropdown content element
return dropdownContent;
},
2019-01-10 14:44:39 +00:00
/**
* Called this method each time the dark theme button
* is clicked
2019-01-10 14:44:39 +00:00
*
* @param {Boolean} invert Specify whether dark theme mode should
* be inverted or not
* @param {HTMLElement} button Button element that has been
* clicked
2019-01-10 14:44:39 +00:00
*/
darkThemeButtonClicked: function(invert, button){
2019-01-10 14:44:39 +00:00
if(invert)
ComunicWeb.components.darkTheme.setEnabled(!ComunicWeb.components.darkTheme.isEnabled());
2019-01-10 14:44:39 +00:00
//Update icon
button.getElementsByTagName("i")[0].className =
"fa " + (ComunicWeb.components.darkTheme.isEnabled() ? "fa-moon-o" : "fa-sun-o");
2019-01-10 14:44:39 +00:00
},
2018-08-03 13:27:56 +00:00
/**
* Add alternate latest posts button
* (if the screen is too small to display "Comunic")
*
2019-01-10 14:44:39 +00:00
* @param {HTMLElement} target The target for the button
2018-08-03 13:27:56 +00:00
*/
addAlternateLatestPostsButton: function(target){
//Create button
var button = createElem2({
type: "li",
appendTo: target,
class: "alternate-latest-posts-button"
});
//Create link
var link = createElem("a", button);
createElem2({
type: "i",
appendTo: link,
class: "fa fa-history"
});
//Makes link lives
link.addEventListener("click", function(){
openPage("latest");
});
},
2017-06-03 13:41:04 +00:00
/**
* Add friendsList toggle button
*
* @param {HTMLElement} navbarElem The target navbarlist element
* @return {HTMLElement} The button element
*/
addFriendListButton: function(navbarElem){
//Create button
var friendButton = createElem("li", navbarElem);
friendButton.className = "friendToggleButton";
//Create link
var friendButtonLink = createElem("a", friendButton);
var friendIcon = createElem("i", friendButtonLink);
friendIcon.className = "fa fa-users";
//Makes link live
friendButtonLink.onclick = function(){
ComunicWeb.components.friends.bar.toggleShowHide();
};
return friendButtonLink;
},
2017-05-25 13:06:01 +00:00
/**
* Add user name element
*
* @param {HTMLElement} navbarElem The target navbarlist element
* @return {HTMLElement} The user element
*/
addUserName: function(navbarElem){
//Create user element
var userelement = createElem("li", navbarElem);
userelement.className = "user-menu";
//Add user link element
var userlinkelement = createElem("a", userelement);
//Add user image
var userimage = createElem("img", userlinkelement);
userimage.className = "user-image";
userimage.src = ComunicWeb.__config.assetsURL + "img/defaultAvatar.png";
//Add user name
var userNameElem = createElem("span", userlinkelement);
2017-05-26 09:38:37 +00:00
userNameElem.className = "hidden-xs";
2018-03-11 15:55:44 +00:00
userNameElem.innerHTML = lang("_loading");
2017-05-25 13:06:01 +00:00
//Make a request to get informations about the user
2017-05-27 09:57:05 +00:00
ComunicWeb.user.userInfos.getUserInfos("current", (function(userInfos){
2017-05-25 13:25:39 +00:00
//Change user name
userNameElem.innerHTML = userInfos.firstName + " "+ userInfos.lastName;
//Change avatar url
userimage.src = userInfos.accountImage;
2018-01-02 18:11:29 +00:00
userlinkelement.onclick = function(){
2018-07-14 12:18:21 +00:00
openUserPage(userInfos);
2018-01-02 18:11:29 +00:00
}
2017-05-27 13:35:10 +00:00
}), true);
2017-05-25 13:06:01 +00:00
},
2017-05-26 09:38:37 +00:00
/**
* Add search form element
*
* @param {HTMLElement} navbarElem The target navbarlist element
* @return {HTMLElement} The user element
*/
addSearchForm: function(navbarElem){
2018-08-01 04:44:01 +00:00
//Create form element (large screens)
2017-05-26 10:01:54 +00:00
var searchForm = createElem("li", navbarElem);
2018-08-01 04:44:01 +00:00
searchForm.className = "dropdown navbar-form navbar-left messages-menu hidden-xs";
2017-05-26 09:38:37 +00:00
searchForm.setAttribute("role", "search");
//Create form group
var formGroup = createElem("div", searchForm);
formGroup.className = "form-group";
//Create search input
var searchInput = createElem("input", formGroup);
searchInput.className = "form-control";
2018-03-11 15:55:44 +00:00
searchInput.placeholder = lang("_menu_bar_search_placeholder");
2017-05-26 09:38:37 +00:00
searchInput.type = "text";
searchInput.id = "navbar-search-input";
2017-05-26 10:01:54 +00:00
2017-05-26 14:11:41 +00:00
//Create dropdown container
var dropdownContainer = createElem("ul", searchForm);
dropdownContainer.className = "dropdown-menu";
//Initializate menu
ComunicWeb.components.search.form.init(searchInput, dropdownContainer);
2018-08-01 04:44:01 +00:00
//Create search link (small screen)
var searchLinkLi = createElem2({
appendTo: navbarElem,
type: "li",
class: "navbar-left visible-xs"
2018-08-01 04:44:01 +00:00
});
var searchLink = createElem2({
appendTo: searchLinkLi,
type: "a",
innerHTML: "Search"
});
searchLink.addEventListener("click", function(){
openPage("search");
$(navbarElem.parentNode).collapse("toggle");
2018-08-01 04:44:01 +00:00
});
2017-05-26 09:38:37 +00:00
}
};