|
|
@ -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
|
|
|
|