Add a dropdown user menu to the top bar in static pages
This commit is contained in:
@@ -386,100 +386,25 @@ define([
|
||||
throw new Error("You must provide a `userName` object containing `setName` (function) " +
|
||||
"and `lastName` (object) if you want to display the user admin menu.");
|
||||
}
|
||||
var $displayedName = $('<span>', {'class': USERNAME_CLS});
|
||||
var accountName = Cryptpad.getStore().getLoginName ? Cryptpad.getStore().getLoginName() : null;
|
||||
var account = typeof accountName === "string";
|
||||
var $userAdminContent = $('<p>');
|
||||
if (account) {
|
||||
var $userAccount = $('<span>', {'class': 'userAccount'}).append(Messages.user_accountName + ': ' + accountName);
|
||||
$userAdminContent.append($userAccount);
|
||||
$userAdminContent.append($('<br>'));
|
||||
}
|
||||
var $userName = $('<span>', {'class': 'userDisplayName'});
|
||||
if (readOnly !== 1) {
|
||||
// Hide "Display name:" in read only mode
|
||||
$userName.append(Messages.user_displayName + ': ');
|
||||
}
|
||||
$userName.append($displayedName.clone());
|
||||
$userAdminContent.append($userName);
|
||||
var options = [{
|
||||
tag: 'p',
|
||||
attributes: {'class': 'accountData'},
|
||||
content: $userAdminContent.html()
|
||||
}];
|
||||
// Add the change display name button if not in read only mode
|
||||
if (readOnly !== 1) {
|
||||
options.push({
|
||||
tag: 'a',
|
||||
attributes: {'class': USERBUTTON_CLS},
|
||||
content: Messages.user_rename
|
||||
});
|
||||
}
|
||||
var parsed = Cryptpad.parsePadUrl(window.location.href);
|
||||
if (parsed && parsed.type && parsed.type !== 'drive') {
|
||||
options.push({
|
||||
tag: 'a',
|
||||
attributes: {
|
||||
'target': '_blank',
|
||||
'href': '/drive/'
|
||||
},
|
||||
content: Messages.login_accessDrive
|
||||
});
|
||||
}
|
||||
// Add login or logout button depending on the current status
|
||||
if (account) {
|
||||
options.push({
|
||||
tag: 'a',
|
||||
attributes: {'class': 'logout'},
|
||||
content: Messages.logoutButton
|
||||
});
|
||||
} else {
|
||||
options.push({
|
||||
tag: 'a',
|
||||
attributes: {'class': 'login'},
|
||||
content: Messages.login_login
|
||||
});
|
||||
options.push({
|
||||
tag: 'a',
|
||||
attributes: {'class': 'register'},
|
||||
content: Messages.login_register
|
||||
});
|
||||
}
|
||||
var $icon = $('<span>', {'class': 'fa fa-user'});
|
||||
var $userbig = $('<span>', {'class': 'big'}).append($displayedName.clone());
|
||||
var $userButton = $('<div>').append($icon).append($userbig);
|
||||
if (account) {
|
||||
$userbig.append($('<span>', {'class': 'account-name'}).text('(' + accountName + ')'));
|
||||
}
|
||||
var dropdownConfigUser = {
|
||||
text: $userButton.html(), // Button initial text
|
||||
options: options, // Entries displayed in the menu
|
||||
left: true, // Open to the left of the button
|
||||
|
||||
var userMenuCfg = {
|
||||
displayNameCls: USERNAME_CLS,
|
||||
changeNameButtonCls: USERBUTTON_CLS,
|
||||
};
|
||||
var $userAdmin = Cryptpad.createDropdown(dropdownConfigUser);
|
||||
if (readOnly !== 1) {
|
||||
userMenuCfg.displayName = 1;
|
||||
userMenuCfg.displayChangeName = 1;
|
||||
}
|
||||
var $userAdmin = Cryptpad.createUserAdminMenu(userMenuCfg);
|
||||
|
||||
$userAdmin.attr('id', 'userDropdown');
|
||||
$userContainer.append($userAdmin);
|
||||
|
||||
$userAdmin.find('a.logout').click(function (e) {
|
||||
Cryptpad.logout();
|
||||
window.location.href = '/';
|
||||
});
|
||||
$userAdmin.find('a.login').click(function (e) {
|
||||
sessionStorage.redirectTo = window.location.href;
|
||||
window.location.href = '/login/';
|
||||
});
|
||||
$userAdmin.find('a.register').click(function (e) {
|
||||
sessionStorage.redirectTo = window.location.href;
|
||||
window.location.href = '/register/';
|
||||
});
|
||||
|
||||
if (config.userName && config.userName.setName && config.userName.lastName) {
|
||||
$userAdmin.find('a.' + USERBUTTON_CLS).click(function (e) {
|
||||
Cryptpad.prompt(Messages.changeNamePrompt, config.userName.lastName.lastName || '', function (newName) {
|
||||
config.userName.setName(newName);
|
||||
});
|
||||
$userAdmin.find('a.' + USERBUTTON_CLS).click(function (e) {
|
||||
Cryptpad.prompt(Messages.changeNamePrompt, config.userName.lastName.lastName || '', function (newName) {
|
||||
config.userName.setName(newName);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return $userContainer;
|
||||
|
||||
Reference in New Issue
Block a user