Fix display name in useradmin (friends app)

pull/1/head
yflory 7 years ago
parent e6188bfb63
commit 438e7e6cf9

@ -56,14 +56,15 @@ define(function () {
edPublic: Cryptpad.getProxy().edPublic
};
addToUserData(myData);
Cryptpad.setAttribute('username', exp.myUserName, function (err) {
/*Cryptpad.setAttribute('username', exp.myUserName, function (err) {
if (err) {
console.log("Couldn't set username");
console.error(err);
return;
}
if (typeof cb === "function") { cb(); }
});
});*/
if (typeof cb === "function") { cb(); }
};
exp.getLastName = function ($changeNameButton, isNew) {

@ -166,6 +166,24 @@ define([
return $.inArray(i, b) > -1;
});
};
var updateDisplayName = function (toolbar, config) {
// Change username in useradmin dropdown
var name = Cryptpad.getDisplayName();
if (config.displayed.indexOf('useradmin') !== -1) {
var $userAdminElement = toolbar.$userAdmin;
var $userElement = $userAdminElement.find('.' + USERNAME_CLS);
$userElement.show();
if (config.readOnly === 1) {
$userElement.addClass(READONLY_CLS).text(Messages.readonly);
}
else {
if (!name) {
name = Messages.anonymous;
}
$userElement.removeClass(READONLY_CLS).text(name);
}
}
};
var avatars = {};
var updateUserList = function (toolbar, config) {
// Make sure the elements are displayed
@ -174,7 +192,6 @@ define([
var userList = config.userList.list.users;
var userData = config.userList.data;
var userNetfluxId = config.userList.userNetfluxId;
var numberOfUsers = userList.length;
@ -256,22 +273,7 @@ define([
var $spansmall = $('<span>').html(fa_editusers + ' ' + numberOfEditUsers + '&nbsp;&nbsp; ' + fa_viewusers + ' ' + numberOfViewUsers);
$userButtons.find('.buttonTitle').html('').append($spansmall);
// Change username in useradmin dropdown
if (config.displayed.indexOf('useradmin') !== -1) {
var $userAdminElement = toolbar.$userAdmin;
var $userElement = $userAdminElement.find('.' + USERNAME_CLS);
$userElement.show();
if (config.readOnly === 1) {
$userElement.addClass(READONLY_CLS).text(Messages.readonly);
}
else {
var name = userData[userNetfluxId] && userData[userNetfluxId].name;
if (!name) {
name = Messages.anonymous;
}
$userElement.removeClass(READONLY_CLS).text(name);
}
}
updateDisplayName(toolbar, config);
};
var initUserList = function (toolbar, config) {
@ -815,7 +817,15 @@ define([
if (newName === null && typeof(lastName) === "string") { return; }
if (newName === null) { newName = ''; }
else { Cryptpad.feedback('NAME_CHANGED'); }
Cryptpad.changeDisplayName(newName, true);
Cryptpad.setAttribute('username', newName, function (err) {
if (err) {
console.log("Couldn't set username");
console.error(err);
return;
}
updateDisplayName(toolbar, config);
Cryptpad.changeDisplayName(newName, true);
});
});
});
});
@ -823,6 +833,8 @@ define([
Cryptpad.findCancelButton().click();
});
updateDisplayName(toolbar, config);
return $userAdmin;
};

Loading…
Cancel
Save