From 1e003b13a88a94f42a87707e29b53b0c24f4c78e Mon Sep 17 00:00:00 2001 From: Yann Flory Date: Fri, 21 Oct 2016 15:17:15 +0200 Subject: [PATCH] ask anonymous, first-time users to set their name when they first join a pad --- customize.dist/translations/messages.fr.js | 1 + customize.dist/translations/messages.js | 2 +- www/code/main.js | 11 +++++++---- www/common/cryptpad-common.js | 3 +-- www/pad/main.js | 15 +++++++++------ www/slide/main.js | 11 +++++++---- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index 31b435f1e..3d4f85196 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -45,6 +45,7 @@ define(function () { out.userButton = 'UTILISATEUR'; out.userButtonTitle = "Changer votre nom d'utilisateur"; + out.changeNamePrompt = 'Changer votre nom (laisser vide pour rester anonyme) : '; out.renameButton = 'RENOMMER'; out.renameButtonTitle = 'Changer le titre utilisé par ce document dans la page d\'accueil de Cryptpad'; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 2b2a7a0cb..51c8f73a7 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -45,7 +45,7 @@ define(function () { out.userButton = 'USER'; out.userButtonTitle = 'Change your username'; - out.changeNamePrompt = 'Change your name: '; + out.changeNamePrompt = 'Change your name (leave empty to be anonymous): '; out.renameButton = 'RENAME'; out.renameButtonTitle = 'Change the title under which this document is listed on your home page'; diff --git a/www/code/main.js b/www/code/main.js index 1e4a11758..1fb9897b0 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -198,6 +198,7 @@ define([ console.error(err); return; } + module.userName.lastName = myUserName; onLocal(); }); }; @@ -321,12 +322,12 @@ define([ editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); } + // Store the object sent for the "change username" button so that we can update the field value correctly + var userNameButtonObject = module.userName = {}; /* add a "change username" button */ getLastName(function (err, lastName) { - var usernameCb = function (newName) { - setName (newName); - }; - var $username = Cryptpad.createButton('username', false, {lastName: lastName}, usernameCb); + userNameButtonObject.lastName = lastName; + var $username = module.$userNameButton = Cryptpad.createButton('username', false, userNameButtonObject, setName); $userBlock.append($username).hide(); }); @@ -555,6 +556,8 @@ define([ addToUserList(myData); if (typeof(lastName) === 'string' && lastName.length) { setName(lastName); + } else { + module.$userNameButton.click(); } onLocal(); }); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index b512ab54b..bd4519562 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -719,9 +719,8 @@ define([ title: Messages.userButton + '\n' + Messages.userButtonTitle }).html(''); if (data && typeof data.lastName !== "undefined" && callback) { - var lastName = data.lastName; button.click(function() { - common.prompt(Messages.changeNamePrompt, lastName, function (newName) { + common.prompt(Messages.changeNamePrompt, data.lastName, function (newName) { callback(newName); }); }); diff --git a/www/pad/main.js b/www/pad/main.js index 78b49fc8f..ea1d3d496 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -291,12 +291,13 @@ define([ name: myUserName }; addToUserList(myData); - editor.fire('change'); - Cryptpad.setAttribute('username', newName, function (err, data) { if (err) { console.error("Couldn't set username"); + return; } + module.userName.lastName = myUserName; + editor.fire('change'); }); }; @@ -535,12 +536,12 @@ define([ editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); } + // Store the object sent for the "change username" button so that we can update the field value correctly + var userNameButtonObject = module.userName = {}; /* add a "change username" button */ getLastName(function (err, lastName) { - var usernameCb = function (newName) { - setName (newName); - }; - var $username = Cryptpad.createButton('username', false, {lastName: lastName}, usernameCb); + userNameButtonObject.lastName = lastName; + var $username = module.$userNameButton = Cryptpad.createButton('username', false, userNameButtonObject, setName); $userBlock.append($username).hide(); }); @@ -638,6 +639,8 @@ define([ addToUserList(myData); if (typeof(lastName) === 'string' && lastName.length) { setName(lastName); + } else { + module.$userNameButton.click(); } realtimeOptions.onLocal(); }); diff --git a/www/slide/main.js b/www/slide/main.js index ef7246b18..e5ca84317 100644 --- a/www/slide/main.js +++ b/www/slide/main.js @@ -246,6 +246,7 @@ define([ console.error(err); return; } + module.userName.lastName = myUserName; onLocal(); }); }; @@ -398,12 +399,12 @@ define([ editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); } + // Store the object sent for the "change username" button so that we can update the field value correctly + var userNameButtonObject = module.userName = {}; /* add a "change username" button */ getLastName(function (err, lastName) { - var usernameCb = function (newName) { - setName (newName); - }; - var $username = Cryptpad.createButton('username', false, {lastName: lastName}, usernameCb); + userNameButtonObject.lastName = lastName; + var $username = module.$userNameButton = Cryptpad.createButton('username', false, userNameButtonObject, setName); $userBlock.append($username).hide(); }); @@ -655,6 +656,8 @@ define([ addToUserList(myData); if (typeof(lastName) === 'string' && lastName.length) { setName(lastName); + } else { + module.$userNameButton.click(); } onLocal(); });