From c736caceba303923bb46f90459661dd0909a086c Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 13 Sep 2016 12:24:06 +0200 Subject: [PATCH] Use a better default pad title --- customize.dist/messages.js | 6 ++++++ www/common/cryptpad-common.js | 23 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/customize.dist/messages.js b/customize.dist/messages.js index df5abbe44..90cba2818 100644 --- a/customize.dist/messages.js +++ b/customize.dist/messages.js @@ -73,5 +73,11 @@ define(function () { out.loginText = '

Your username and password are used to generate a unique key which is never known by our server.

\n' + '

Be careful not to forget your credentials, as they are impossible to recover

'; + out.type = {}; + out.type.pad = 'Pad'; + out.type.code = 'Code'; + out.type.poll = 'Poll'; + out.type.slide = 'Presentation'; + return out; }); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 4da9816af..e635223c1 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -193,6 +193,25 @@ define([ return ret; }; + var isNameAvailable = function (title, parsed, pads) { + return !pads.some(function (pad) { + // another pad is already using that title + if (pad.title === title) { + return true; + } + }); + }; + + // Create untitled documents when no name is given + var getDefaultName = function (parsed, recentPads) { + var type = parsed.type; + var untitledIndex = 1; + var name = (Messages.type)[type] + ' - ' + new Date().toString().split(' ').slice(0,4).join(' '); + if (isNameAvailable(name, parsed, recentPads)) { return name; } + while (!isNameAvailable(name + ' - ' + untitledIndex, parsed, recentPads)) { untitledIndex++; } + return name + ' - ' + untitledIndex; + }; + var makePad = function (href, title) { var now = ''+new Date(); return { @@ -379,6 +398,8 @@ define([ } }); + if (title === '') { title = getDefaultName(parsed, pads); } + cb(void 0, title); }); }; @@ -396,7 +417,7 @@ define([ var conflicts = pads.some(function (pad) { // another pad is already using that title if (pad.title === title) { - var p = parsePadUrl(href); + var p = parsePadUrl(pad.href); if (p.type === parsed.type && p.hash === parsed.hash) { // the duplicate pad has the same type and hash