Merge branch 'rememberName' of github.com:xwiki-labs/cryptpad into rememberName

This commit is contained in:
ansuz 2016-09-23 16:40:07 +02:00
commit ed9acf1c00
5 changed files with 32 additions and 18 deletions

View File

@ -60,14 +60,6 @@
margin-right: 5px; margin-right: 5px;
padding-left: 5px; padding-left: 5px;
} }
.cryptpad-changeName {
float: left;
cursor: pointer;
}
.cryptpad-changeName button {
padding: 0;
margin-right: 5px;
}
.cryptpad-toolbar-leftside { .cryptpad-toolbar-leftside {
float: left; float: left;
} }
@ -87,4 +79,7 @@
margin-right: 20px; margin-right: 20px;
font-weight: bold; font-weight: bold;
text-transform: uppercase; text-transform: uppercase;
} }
.cryptpad-toolbar-username {
font-style: italic;
};

View File

@ -186,7 +186,7 @@ define([
name: myUserName name: myUserName
}; };
addToUserList(myData); addToUserList(myData);
Cryptpad.setPadAttribute('username', myUserName, function (err, data) { Cryptpad.setAttribute('username', myUserName, function (err, data) {
if (err) { if (err) {
console.log("Couldn't set username"); console.log("Couldn't set username");
console.error(err); console.error(err);
@ -197,7 +197,7 @@ define([
}; };
var getLastName = function (cb) { var getLastName = function (cb) {
Cryptpad.getPadAttribute('username', function (err, userName) { Cryptpad.getAttribute('username', function (err, userName) {
cb(err, userName || ''); cb(err, userName || '');
}); });
}; };

View File

@ -318,6 +318,12 @@ define([
cb(err, data); cb(err, data);
}); });
}; };
var setAttribute = common.setAttribute = function (attr, value, cb, legacy) {
getStore(legacy).set(["cryptpad", attr].join('.'), value, function (err, data) {
cb(err, data);
});
};
// STORAGE // STORAGE
var getPadAttribute = common.getPadAttribute = function (attr, cb, legacy) { var getPadAttribute = common.getPadAttribute = function (attr, cb, legacy) {
@ -325,6 +331,12 @@ define([
cb(err, data); cb(err, data);
}); });
}; };
var getAttribute = common.getAttribute = function (attr, cb, legacy) {
getStore(legacy).get(["cryptpad", attr].join('.'), function (err, data) {
cb(err, data);
});
};
// STORAGE // STORAGE
/* fetch and migrate your pad history from localStorage */ /* fetch and migrate your pad history from localStorage */

View File

@ -27,6 +27,9 @@ define([
var SPINNER_CLS = Bar.constants.spinner = 'cryptpad-spinner'; var SPINNER_CLS = Bar.constants.spinner = 'cryptpad-spinner';
var USERNAME_CLS = Bar.constants.username = 'cryptpad-toolbar-username';
var READONLY_CLS = Bar.constants.readonly = 'cryptpad-readonly';
/** Key in the localStore which indicates realtime activity should be disallowed. */ /** Key in the localStore which indicates realtime activity should be disallowed. */
// TODO remove? will never be used in cryptpad // TODO remove? will never be used in cryptpad
var LOCALSTORAGE_DISALLOW = Bar.constants.localstorageDisallow = 'cryptpad-disallow'; var LOCALSTORAGE_DISALLOW = Bar.constants.localstorageDisallow = 'cryptpad-disallow';
@ -121,16 +124,16 @@ define([
return (i > 0) ? list.slice(0, -2) : list; return (i > 0) ? list.slice(0, -2) : list;
}; };
var createChangeName = function($container, userList, buttonID) { var createChangeName = function($container, buttonID) {
var $span = $('<span>', { var $span = $('<span>', {
id: uid(), id: uid(),
}); });
var $button = $('<button>', { var $button = $('<button>', {
id: buttonID, id: buttonID,
'class': USERNAME_BUTTON_GROUP, 'class': 'rightside-button',
}).text(Messages.changeNameButton); }).text(Messages.changeNameButton);
$(userList).append($button); $container.append($button);
$button.after($span); $button.after($span);
return $span[0]; return $span[0];
}; };
@ -157,7 +160,7 @@ define([
var innerHTML; var innerHTML;
var numberOfViewUsers = numberOfUsers - userList.length; var numberOfViewUsers = numberOfUsers - userList.length;
if (readOnly === 1) { if (readOnly === 1) {
innerHTML = '<span class="cryptpad-readonly">' + Messages.readonly + '</span>'; innerHTML = '<span class="' + READONLY_CLS + '">' + Messages.readonly + '</span>';
if (userList.length === 0) { if (userList.length === 0) {
innerHTML += Messages.nobodyIsEditing; innerHTML += Messages.nobodyIsEditing;
} else if (userList.length === 1) { } else if (userList.length === 1) {
@ -178,6 +181,9 @@ define([
} }
} }
innerHTML += getViewers(numberOfViewUsers); innerHTML += getViewers(numberOfViewUsers);
if (userData[myUserName] && userData[myUserName].name) {
innerHTML = '<span class="' + USERNAME_CLS + '">' + userData[myUserName].name + '</span> | ' + innerHTML;
}
listElement.innerHTML = innerHTML; listElement.innerHTML = innerHTML;
}; };
@ -226,7 +232,8 @@ define([
// Check if the user is allowed to change his name // Check if the user is allowed to change his name
if(changeNameID) { if(changeNameID) {
// Create the button and update the element containing the user list // Create the button and update the element containing the user list
userListElement = createChangeName($container, userListElement, changeNameID); //userListElement = createChangeName($container, userListElement, changeNameID);
createChangeName(toolbar.find('.' + RIGHTSIDE_CLS), changeNameID);
} }
var connected = false; var connected = false;

View File

@ -269,7 +269,7 @@ define([
}; };
var getLastName = function (cb) { var getLastName = function (cb) {
Cryptpad.getPadAttribute('username', function (err, userName) { Cryptpad.getAttribute('username', function (err, userName) {
cb(err, userName || ''); cb(err, userName || '');
}); });
}; };
@ -287,7 +287,7 @@ define([
addToUserList(myData); addToUserList(myData);
editor.fire('change'); editor.fire('change');
Cryptpad.setPadAttribute('username', newName, function (err, data) { Cryptpad.setAttribute('username', newName, function (err, data) {
if (err) { if (err) {
console.error("Couldn't set username"); console.error("Couldn't set username");
} }