move 'getDefaultName' out of 'common-hash'
This commit is contained in:
parent
d7906f9132
commit
096b0fb44a
@ -1,9 +1,8 @@
|
|||||||
define([
|
define([
|
||||||
'/common/common-util.js',
|
'/common/common-util.js',
|
||||||
'/customize/messages.js',
|
|
||||||
'/bower_components/chainpad-crypto/crypto.js',
|
'/bower_components/chainpad-crypto/crypto.js',
|
||||||
'/bower_components/tweetnacl/nacl-fast.min.js'
|
'/bower_components/tweetnacl/nacl-fast.min.js'
|
||||||
], function (Util, Messages, Crypto) {
|
], function (Util, Crypto) {
|
||||||
var Nacl = window.nacl;
|
var Nacl = window.nacl;
|
||||||
|
|
||||||
var Hash = window.CryptPad_Hash = {};
|
var Hash = window.CryptPad_Hash = {};
|
||||||
@ -515,20 +514,6 @@ Version 1
|
|||||||
'/' + curvePublic.replace(/\//g, '-') + '/';
|
'/' + curvePublic.replace(/\//g, '-') + '/';
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create untitled documents when no name is given
|
|
||||||
var getLocaleDate = function () {
|
|
||||||
if (window.Intl && window.Intl.DateTimeFormat) {
|
|
||||||
var options = {weekday: "short", year: "numeric", month: "long", day: "numeric"};
|
|
||||||
return new window.Intl.DateTimeFormat(undefined, options).format(new Date());
|
|
||||||
}
|
|
||||||
return new Date().toString().split(' ').slice(0,4).join(' ');
|
|
||||||
};
|
|
||||||
Hash.getDefaultName = function (parsed) {
|
|
||||||
var type = parsed.type;
|
|
||||||
var name = (Messages.type)[type] + ' - ' + getLocaleDate();
|
|
||||||
return name;
|
|
||||||
};
|
|
||||||
|
|
||||||
Hash.isValidHref = function (href) {
|
Hash.isValidHref = function (href) {
|
||||||
// Non-empty href?
|
// Non-empty href?
|
||||||
if (!href) { return; }
|
if (!href) { return; }
|
||||||
|
|||||||
@ -648,7 +648,6 @@ define([
|
|||||||
data.href = parsed.getUrl({present: parsed.present});
|
data.href = parsed.getUrl({present: parsed.present});
|
||||||
|
|
||||||
if (typeof (data.title) !== "string") { return cb('Missing title'); }
|
if (typeof (data.title) !== "string") { return cb('Missing title'); }
|
||||||
if (data.title.trim() === "") { data.title = Hash.getDefaultName(parsed); }
|
|
||||||
|
|
||||||
if (common.initialPath) {
|
if (common.initialPath) {
|
||||||
if (!data.path) {
|
if (!data.path) {
|
||||||
|
|||||||
@ -507,7 +507,7 @@ define([
|
|||||||
roHref: roHref,
|
roHref: roHref,
|
||||||
atime: now,
|
atime: now,
|
||||||
ctime: now,
|
ctime: now,
|
||||||
title: title || Hash.getDefaultName(Hash.parsePadUrl(href)),
|
title: title || UserObject.getDefaultName(Hash.parsePadUrl(href)),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -805,6 +805,8 @@ define([
|
|||||||
var p = Hash.parsePadUrl(href);
|
var p = Hash.parsePadUrl(href);
|
||||||
var h = p.hashData;
|
var h = p.hashData;
|
||||||
|
|
||||||
|
if (title.trim() === "") { title = UserObject.getDefaultName(p); }
|
||||||
|
|
||||||
if (AppConfig.disableAnonymousStore && !store.loggedIn) { return void cb(); }
|
if (AppConfig.disableAnonymousStore && !store.loggedIn) { return void cb(); }
|
||||||
if (p.type === "debug") { return void cb(); }
|
if (p.type === "debug") { return void cb(); }
|
||||||
|
|
||||||
|
|||||||
@ -694,7 +694,7 @@ define([
|
|||||||
// Fix creation time
|
// Fix creation time
|
||||||
if (!el.ctime) { el.ctime = el.atime; }
|
if (!el.ctime) { el.ctime = el.atime; }
|
||||||
// Fix title
|
// Fix title
|
||||||
if (!el.title) { el.title = Hash.getDefaultName(parsed); }
|
if (!el.title) { el.title = exp.getDefaultName(parsed); }
|
||||||
// Fix channel
|
// Fix channel
|
||||||
if (!el.channel) {
|
if (!el.channel) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -50,9 +50,10 @@ define([
|
|||||||
'/common/outer/local-store.js',
|
'/common/outer/local-store.js',
|
||||||
'/customize/application_config.js',
|
'/customize/application_config.js',
|
||||||
'/common/test.js',
|
'/common/test.js',
|
||||||
|
'/common/userObject.js',
|
||||||
], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, _SFrameChannel,
|
], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, _SFrameChannel,
|
||||||
_FilePicker, _Share, _Messaging, _Notifier, _Hash, _Util, _Realtime,
|
_FilePicker, _Share, _Messaging, _Notifier, _Hash, _Util, _Realtime,
|
||||||
_Constants, _Feedback, _LocalStore, _AppConfig, _Test) {
|
_Constants, _Feedback, _LocalStore, _AppConfig, _Test, _UserObject) {
|
||||||
CpNfOuter = _CpNfOuter;
|
CpNfOuter = _CpNfOuter;
|
||||||
Cryptpad = _Cryptpad;
|
Cryptpad = _Cryptpad;
|
||||||
Crypto = Utils.Crypto = _Crypto;
|
Crypto = Utils.Crypto = _Crypto;
|
||||||
@ -68,6 +69,7 @@ define([
|
|||||||
Utils.Constants = _Constants;
|
Utils.Constants = _Constants;
|
||||||
Utils.Feedback = _Feedback;
|
Utils.Feedback = _Feedback;
|
||||||
Utils.LocalStore = _LocalStore;
|
Utils.LocalStore = _LocalStore;
|
||||||
|
Utils.UserObject = _UserObject;
|
||||||
AppConfig = _AppConfig;
|
AppConfig = _AppConfig;
|
||||||
Test = _Test;
|
Test = _Test;
|
||||||
|
|
||||||
@ -271,7 +273,7 @@ define([
|
|||||||
Utils.crypto = Utils.Crypto.createEncryptor(Utils.secret.keys);
|
Utils.crypto = Utils.Crypto.createEncryptor(Utils.secret.keys);
|
||||||
var parsed = Utils.Hash.parsePadUrl(window.location.href);
|
var parsed = Utils.Hash.parsePadUrl(window.location.href);
|
||||||
if (!parsed.type) { throw new Error(); }
|
if (!parsed.type) { throw new Error(); }
|
||||||
var defaultTitle = Utils.Hash.getDefaultName(parsed);
|
var defaultTitle = Utils.UserObject.getDefaultName(parsed);
|
||||||
var edPublic, curvePublic, notifications, isTemplate;
|
var edPublic, curvePublic, notifications, isTemplate;
|
||||||
var forceCreationScreen = cfg.useCreationScreen &&
|
var forceCreationScreen = cfg.useCreationScreen &&
|
||||||
sessionStorage[Utils.Constants.displayPadCreationScreen];
|
sessionStorage[Utils.Constants.displayPadCreationScreen];
|
||||||
@ -1176,7 +1178,7 @@ define([
|
|||||||
|
|
||||||
// Update metadata values and send new metadata inside
|
// Update metadata values and send new metadata inside
|
||||||
parsed = Utils.Hash.parsePadUrl(window.location.href);
|
parsed = Utils.Hash.parsePadUrl(window.location.href);
|
||||||
defaultTitle = Utils.Hash.getDefaultName(parsed);
|
defaultTitle = Utils.UserObject.getDefaultName(parsed);
|
||||||
hashes = Utils.Hash.getHashes(secret);
|
hashes = Utils.Hash.getHashes(secret);
|
||||||
readOnly = false;
|
readOnly = false;
|
||||||
updateMeta();
|
updateMeta();
|
||||||
|
|||||||
@ -15,8 +15,24 @@ define([
|
|||||||
var TEMPLATE = module.TEMPLATE = "template";
|
var TEMPLATE = module.TEMPLATE = "template";
|
||||||
var SHARED_FOLDERS = module.SHARED_FOLDERS = "sharedFolders";
|
var SHARED_FOLDERS = module.SHARED_FOLDERS = "sharedFolders";
|
||||||
|
|
||||||
|
// Create untitled documents when no name is given
|
||||||
|
var getLocaleDate = function () {
|
||||||
|
if (window.Intl && window.Intl.DateTimeFormat) {
|
||||||
|
var options = {weekday: "short", year: "numeric", month: "long", day: "numeric"};
|
||||||
|
return new window.Intl.DateTimeFormat(undefined, options).format(new Date());
|
||||||
|
}
|
||||||
|
return new Date().toString().split(' ').slice(0,4).join(' ');
|
||||||
|
};
|
||||||
|
module.getDefaultName = function (parsed) {
|
||||||
|
var type = parsed.type;
|
||||||
|
var name = (Messages.type)[type] + ' - ' + getLocaleDate();
|
||||||
|
return name;
|
||||||
|
};
|
||||||
|
|
||||||
module.init = function (files, config) {
|
module.init = function (files, config) {
|
||||||
var exp = {};
|
var exp = {};
|
||||||
|
exp.getDefaultName = module.getDefaultName;
|
||||||
|
|
||||||
var sframeChan = config.sframeChan;
|
var sframeChan = config.sframeChan;
|
||||||
|
|
||||||
var FILES_DATA = module.FILES_DATA = exp.FILES_DATA = Constants.storageKey;
|
var FILES_DATA = module.FILES_DATA = exp.FILES_DATA = Constants.storageKey;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user