Update display name in realtime across tabs and remember 'anonymous' name
This commit is contained in:
@@ -71,6 +71,7 @@ define([
|
||||
var userHashKey = common.userHashKey = 'User_hash';
|
||||
var userNameKey = common.userNameKey = 'User_name';
|
||||
var fileHashKey = common.fileHashKey = 'FS_hash';
|
||||
var displayNameKey = common.displayNameKey = 'cryptpad.username';
|
||||
|
||||
var login = common.login = function (hash, name, cb) {
|
||||
if (!hash) { throw new Error('expected a user hash'); }
|
||||
@@ -534,6 +535,25 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
// STORAGE: Display Name
|
||||
var getLastName = common.getLastName = function (cb) {
|
||||
common.getAttribute('username', function (err, userName) {
|
||||
cb(err, userName);
|
||||
});
|
||||
};
|
||||
var _onDisplayNameChanged = [];
|
||||
var onDisplayNameChanged = common.onDisplayNameChanged = function (h) {
|
||||
if (typeof(h) !== "function") { return; }
|
||||
if (_onDisplayNameChanged.indexOf(h) !== -1) { return; }
|
||||
_onDisplayNameChanged.push(h);
|
||||
};
|
||||
var changeDisplayName = common.changeDisplayName = function (newName) {
|
||||
_onDisplayNameChanged.forEach(function (h) {
|
||||
h(newName);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// STORAGE
|
||||
var forgetPad = common.forgetPad = function (href, cb) {
|
||||
var parsed = parsePadUrl(href);
|
||||
|
||||
@@ -375,11 +375,6 @@ define([
|
||||
|
||||
// User dropdown
|
||||
if (config.displayed.indexOf('useradmin') !== -1) {
|
||||
if (!config.userName || !config.userName.setName || !config.userName.lastName) {
|
||||
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 userMenuCfg = {
|
||||
displayNameCls: USERNAME_CLS,
|
||||
changeNameButtonCls: USERBUTTON_CLS,
|
||||
@@ -393,11 +388,23 @@ define([
|
||||
$userAdmin.attr('id', 'userDropdown');
|
||||
$userContainer.append($userAdmin);
|
||||
|
||||
$userAdmin.find('a.' + USERBUTTON_CLS).click(function (e) {
|
||||
Cryptpad.prompt(Messages.changeNamePrompt, config.userName.lastName.lastName || '', function (newName) {
|
||||
config.userName.setName(newName);
|
||||
var $userButton = $userAdmin.find('a.' + USERBUTTON_CLS);
|
||||
var renameAlertOpened;
|
||||
$userButton.click(function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
Cryptpad.getLastName(function (lastName) {
|
||||
Cryptpad.prompt(Messages.changeNamePrompt, lastName || '', function (newName) {
|
||||
if (newName === null && typeof(lastName) === "string") { return; }
|
||||
if (newName === null) { newName = ''; }
|
||||
Cryptpad.changeDisplayName(newName);
|
||||
//config.userName.setName(newName); TODO
|
||||
});
|
||||
});
|
||||
});
|
||||
Cryptpad.onDisplayNameChanged(function (newName) {
|
||||
Cryptpad.findCancelButton().click();
|
||||
});
|
||||
}
|
||||
|
||||
return $userContainer;
|
||||
|
||||
Reference in New Issue
Block a user