Use a better default pad title

pull/1/head
yflory 8 years ago
parent 217e664d4c
commit c736caceba

@ -73,5 +73,11 @@ define(function () {
out.loginText = '<p>Your username and password are used to generate a unique key which is never known by our server.</p>\n' + out.loginText = '<p>Your username and password are used to generate a unique key which is never known by our server.</p>\n' +
'<p>Be careful not to forget your credentials, as they are impossible to recover</p>'; '<p>Be careful not to forget your credentials, as they are impossible to recover</p>';
out.type = {};
out.type.pad = 'Pad';
out.type.code = 'Code';
out.type.poll = 'Poll';
out.type.slide = 'Presentation';
return out; return out;
}); });

@ -193,6 +193,25 @@ define([
return ret; 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 makePad = function (href, title) {
var now = ''+new Date(); var now = ''+new Date();
return { return {
@ -379,6 +398,8 @@ define([
} }
}); });
if (title === '') { title = getDefaultName(parsed, pads); }
cb(void 0, title); cb(void 0, title);
}); });
}; };
@ -396,7 +417,7 @@ define([
var conflicts = pads.some(function (pad) { var conflicts = pads.some(function (pad) {
// another pad is already using that title // another pad is already using that title
if (pad.title === title) { if (pad.title === title) {
var p = parsePadUrl(href); var p = parsePadUrl(pad.href);
if (p.type === parsed.type && p.hash === parsed.hash) { if (p.type === parsed.type && p.hash === parsed.hash) {
// the duplicate pad has the same type and hash // the duplicate pad has the same type and hash

Loading…
Cancel
Save