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

225 lines
6.1 KiB
JavaScript
Raw Normal View History

/**
* Menubar for authenticated users complements
*
* @author Pierre HUBERT
*/
ComunicWeb.components.menuBar.authenticated = {
/**
* Add authenticated user specific elements
*
* @param {HTMLElement} container The container element of the Menubar
*/
addElements: function(container){
//Create an auto-collapsed element
var navbarCollapse = createElem("div", container);
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
this.addSearchForm(navbarCollapseElemList);
//Navbar right elements
var navbarRight = createElem("div", container);
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
2017-05-26 09:38:37 +00:00
this.addUserName(navbarRightElemList);
2017-05-25 13:06:01 +00:00
2017-06-03 13:41:04 +00:00
//Add friends list button
this.addFriendListButton(navbarRightElemList);
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);
},
/**
* 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
//Add conversations link
2018-05-20 12:39:55 +00:00
var conversationsButton = createElem2({
appendTo: dropdownContent,
type: "li"
});
var conversationsLink = createElem2({
appendTo: conversationsButton,
type: "a",
innerHTML: "Conversations"
});
conversationsButton.onclick = function(){
openPage("conversations");
};
2018-05-13 12:06:32 +00:00
2018-07-02 06:07:59 +00:00
//Add groups link
var groupsButton = createElem2({
appendTo: dropdownContent,
type: "li"
});
createElem2({
appendTo: groupsButton,
type: "a",
innerHTML: "Groups"
});
groupsButton.onclick = function(){
openPage("groups");
}
2018-04-12 14:17:41 +00:00
//Add settings link
var settingsButton = createElem2({
appendTo: dropdownContent,
type: "li"
});
var settingsLink = createElem2({
appendTo: settingsButton,
type: "a",
innerHTML: "Settings"
});
settingsButton.onclick = function(){
openPage("settings");
};
//Add logout link
var logoutButton = createElem("li", dropdownContent);
var logoutButtonLink = createElem("a", logoutButton);
2018-03-11 15:55:44 +00:00
logoutButtonLink.innerHTML = lang("_menu_bar_action_logout");
2017-05-25 11:57:38 +00:00
logoutButton.onclick = function(){openPage("logout")};
2017-05-25 13:06:01 +00:00
//Return dropdown content element
return dropdownContent;
},
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(){
openUserPage(userIDorPath(userInfos));
}
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){
//Create form element
2017-05-26 10:01:54 +00:00
var searchForm = createElem("li", navbarElem);
2017-05-27 09:57:05 +00:00
searchForm.className = "dropdown navbar-form navbar-left messages-menu";
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.searchForm.init(searchInput, dropdownContainer);
2017-05-26 09:38:37 +00:00
}
};