Use the new toolbar and move the userlist code in a separate file
This commit is contained in:
@@ -3,7 +3,7 @@ define([
|
||||
'/bower_components/chainpad-crypto/crypto.js',
|
||||
'/bower_components/chainpad-netflux/chainpad-netflux.js',
|
||||
'/bower_components/textpatcher/TextPatcher.js',
|
||||
'/common/toolbar.js',
|
||||
'/common/toolbar2.js',
|
||||
'json.sortify',
|
||||
'/bower_components/chainpad-json-validator/json-ot.js',
|
||||
'/common/cryptpad-common.js',
|
||||
@@ -167,37 +167,11 @@ define([
|
||||
editor.setOption('readOnly', !bool);
|
||||
};
|
||||
|
||||
var userData = module.userData = {}; // List of pretty name of all users (mapped with their server ID)
|
||||
var userList; // List of users still connected to the channel (server IDs)
|
||||
var addToUserData = function(data) {
|
||||
var users = module.users;
|
||||
for (var attrname in data) { userData[attrname] = data[attrname]; }
|
||||
|
||||
if (users && users.length) {
|
||||
for (var userKey in userData) {
|
||||
if (users.indexOf(userKey) === -1) {
|
||||
delete userData[userKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(userList && typeof userList.onChange === "function") {
|
||||
userList.onChange(userData);
|
||||
}
|
||||
};
|
||||
var UserList;
|
||||
|
||||
var textColor;
|
||||
var backColor;
|
||||
|
||||
var myData = {};
|
||||
var myUserName = ''; // My "pretty name"
|
||||
var myID; // My server ID
|
||||
|
||||
var setMyID = function(info) {
|
||||
myID = info.myID || null;
|
||||
myUserName = myID;
|
||||
};
|
||||
|
||||
var config = {
|
||||
//initialState: Messages.codeInitialState,
|
||||
initialState: '{}',
|
||||
@@ -207,7 +181,6 @@ define([
|
||||
validateKey: secret.keys.validateKey || undefined,
|
||||
readOnly: readOnly,
|
||||
crypto: Crypto.createEncryptor(secret.keys),
|
||||
setMyID: setMyID,
|
||||
transformFunction: JsonOT.validate,
|
||||
network: Cryptpad.getNetwork()
|
||||
};
|
||||
@@ -228,7 +201,7 @@ define([
|
||||
var obj = {
|
||||
content: textValue,
|
||||
metadata: {
|
||||
users: userData,
|
||||
users: UserList.userData,
|
||||
defaultTitle: defaultName,
|
||||
slideOptions: slideOptions
|
||||
}
|
||||
@@ -264,28 +237,6 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
var setName = module.setName = function (newName) {
|
||||
if (typeof(newName) !== 'string') { return; }
|
||||
var myUserNameTemp = newName.trim();
|
||||
if(newName.trim().length > 32) {
|
||||
myUserNameTemp = myUserNameTemp.substr(0, 32);
|
||||
}
|
||||
myUserName = myUserNameTemp;
|
||||
myData[myID] = {
|
||||
name: myUserName,
|
||||
uid: Cryptpad.getUid(),
|
||||
};
|
||||
addToUserData(myData);
|
||||
Cryptpad.setAttribute('username', myUserName, function (err) {
|
||||
if (err) {
|
||||
console.log("Couldn't set username");
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
onLocal();
|
||||
});
|
||||
};
|
||||
|
||||
var getHeadingText = function () {
|
||||
var lines = editor.getValue().split(/\n/);
|
||||
|
||||
@@ -413,7 +364,7 @@ define([
|
||||
if (json.metadata.users) {
|
||||
var userData = json.metadata.users;
|
||||
// Update the local user data
|
||||
addToUserData(userData);
|
||||
UserList.addToUserData(userData);
|
||||
}
|
||||
if (json.metadata.defaultTitle) {
|
||||
updateDefaultTitle(json.metadata.defaultTitle);
|
||||
@@ -508,13 +459,11 @@ define([
|
||||
};
|
||||
|
||||
config.onInit = function (info) {
|
||||
userList = info.userList;
|
||||
UserList = Cryptpad.createUserList(info, config.onLocal, Cryptget, Cryptpad);
|
||||
|
||||
var configTb = {
|
||||
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
|
||||
userData: userData,
|
||||
readOnly: readOnly,
|
||||
ifrw: ifrw,
|
||||
displayed: ['title', 'useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
|
||||
userList: UserList.getToolbarConfig(),
|
||||
share: {
|
||||
secret: secret,
|
||||
channel: info.channel
|
||||
@@ -524,13 +473,16 @@ define([
|
||||
defaultName: defaultName,
|
||||
suggestName: suggestName
|
||||
},
|
||||
common: Cryptpad
|
||||
common: Cryptpad,
|
||||
readOnly: readOnly,
|
||||
ifrw: ifrw,
|
||||
realtime: info.realtime,
|
||||
network: info.network,
|
||||
$container: $bar
|
||||
};
|
||||
toolbar = module.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, info.userList, configTb);
|
||||
toolbar = module.toolbar = Toolbar.create(configTb);
|
||||
|
||||
var $rightside = $bar.find('.' + Toolbar.constants.rightside);
|
||||
$bar.find('.' + Toolbar.constants.username);
|
||||
module.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername));
|
||||
var $rightside = toolbar.$rightside;
|
||||
|
||||
var editHash;
|
||||
|
||||
@@ -733,8 +685,6 @@ define([
|
||||
if (!window.location.hash || window.location.hash === '#') {
|
||||
Cryptpad.replaceHash(editHash);
|
||||
}
|
||||
|
||||
Cryptpad.onDisplayNameChanged(setName);
|
||||
};
|
||||
|
||||
var unnotify = module.unnotify = function () {
|
||||
@@ -752,8 +702,6 @@ define([
|
||||
};
|
||||
|
||||
config.onReady = function (info) {
|
||||
module.users = info.userList.users;
|
||||
|
||||
if (module.realtime !== info.realtime) {
|
||||
var realtime = module.realtime = info.realtime;
|
||||
module.patchText = TextPatcher.create({
|
||||
@@ -816,33 +764,11 @@ define([
|
||||
Cryptpad.removeLoadingScreen();
|
||||
setEditable(true);
|
||||
initializing = false;
|
||||
//Cryptpad.log("Your document is ready");
|
||||
|
||||
onLocal(); // push local state to avoid parse errors later.
|
||||
Cryptpad.getLastName(function (err, lastName) {
|
||||
if (err) {
|
||||
console.log("Could not get previous name");
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
// Update the toolbar list:
|
||||
// Add the current user in the metadata if he has edit rights
|
||||
if (readOnly) { return; }
|
||||
if (typeof(lastName) === 'string') {
|
||||
setName(lastName);
|
||||
} else {
|
||||
myData[myID] = {
|
||||
name: "",
|
||||
uid: Cryptpad.getUid(),
|
||||
};
|
||||
addToUserData(myData);
|
||||
onLocal();
|
||||
module.$userNameButton.click();
|
||||
}
|
||||
if (isNew) {
|
||||
Cryptpad.selectTemplate('slide', info.realtime, Cryptget);
|
||||
}
|
||||
});
|
||||
|
||||
if (readOnly) { return; }
|
||||
UserList.getLastName(toolbar.$userNameButton, isNew);
|
||||
};
|
||||
|
||||
var cursorToPos = function(cursor, oldText) {
|
||||
|
||||
Reference in New Issue
Block a user