Merge branch 'staging' of github.com:xwiki-labs/cryptpad into accounting
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
data-main-favicon="/customize/main-favicon.png"
|
||||
data-alt-favicon="/customize/alt-favicon.png"
|
||||
id="favicon" />
|
||||
<link rel="stylesheet" href="/bower_components/components-font-awesome/css/font-awesome.min.css">
|
||||
<link rel="stylesheet" href="/customize/main.css" />
|
||||
<style>
|
||||
html, body {
|
||||
@@ -45,5 +46,14 @@
|
||||
<div id="iframe-container">
|
||||
<iframe id="pad-iframe"></iframe><script src="/common/noscriptfix.js"></script>
|
||||
</div>
|
||||
<div id="loading">
|
||||
<div class="loadingContainer">
|
||||
<img class="cryptofist" src="/customize/cryptofist_small.png" />
|
||||
<div class="spinnerContainer">
|
||||
<span class="fa fa-spinner fa-pulse fa-4x fa-fw"></span>
|
||||
</div>
|
||||
<p data-localization="loading"></p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
define([
|
||||
'/api/config',
|
||||
'/customize/messages.js?app=' + window.location.pathname.split('/').filter(function (x) { return x; }).join('.'),
|
||||
'/customize/fsStore.js',
|
||||
'/common/fsStore.js',
|
||||
'/bower_components/chainpad-crypto/crypto.js?v=0.1.5',
|
||||
'/bower_components/alertifyjs/dist/js/alertify.js',
|
||||
'/bower_components/spin.js/spin.min.js',
|
||||
'/common/clipboard.js',
|
||||
'/customize/fsStore.js',
|
||||
'/customize/application_config.js',
|
||||
|
||||
'/bower_components/jquery/dist/jquery.min.js',
|
||||
@@ -621,6 +620,28 @@ define([
|
||||
};
|
||||
|
||||
// STORAGE
|
||||
var findWeaker = common.findWeaker = function (href, recents) {
|
||||
var rHref = href || getRelativeHref(window.location.href);
|
||||
var parsed = parsePadUrl(rHref);
|
||||
if (!parsed.hash) { return false; }
|
||||
var weaker;
|
||||
recents.some(function (pad) {
|
||||
var p = parsePadUrl(pad.href);
|
||||
if (p.type !== parsed.type) { return; } // Not the same type
|
||||
if (p.hash === parsed.hash) { return; } // Same hash, not stronger
|
||||
var pHash = parseHash(p.hash);
|
||||
var parsedHash = parseHash(parsed.hash);
|
||||
if (!parsedHash || !pHash) { return; }
|
||||
if (pHash.version !== parsedHash.version) { return; }
|
||||
if (pHash.channel !== parsedHash.channel) { return; }
|
||||
if (pHash.mode === 'view' && parsedHash.mode === 'edit') {
|
||||
weaker = pad.href;
|
||||
return true;
|
||||
}
|
||||
return;
|
||||
});
|
||||
return weaker;
|
||||
};
|
||||
var findStronger = common.findStronger = function (href, recents) {
|
||||
var rHref = href || getRelativeHref(window.location.href);
|
||||
var parsed = parsePadUrl(rHref);
|
||||
@@ -862,26 +883,27 @@ define([
|
||||
return Messages.tips[keys[rdm]];
|
||||
};
|
||||
common.addLoadingScreen = function (loadingText) {
|
||||
var $loading, $container;
|
||||
if ($('#' + LOADING).length) {
|
||||
$('#' + LOADING).show();
|
||||
return;
|
||||
$loading = $('#' + LOADING).show();
|
||||
if (loadingText) {
|
||||
$('#' + LOADING).find('p').text(loadingText);
|
||||
}
|
||||
$container = $loading.find('.loadingContainer');
|
||||
} else {
|
||||
var $loading = $('<div>', {id: LOADING});
|
||||
$container = $('<div>', {'class': 'loadingContainer'});
|
||||
$container.append('<img class="cryptofist" src="/customize/cryptofist_small.png" />');
|
||||
var $spinner = $('<div>', {'class': 'spinnerContainer'});
|
||||
var loadingSpinner = common.spinner($spinner).show();
|
||||
var $text = $('<p>').text(loadingText || Messages.loading);
|
||||
$container.append($spinner).append($text);
|
||||
$loading.append($container);
|
||||
$('body').append($loading);
|
||||
}
|
||||
var $loading = $('<div>', {id: LOADING});
|
||||
var $container = $('<div>', {'class': 'loadingContainer'});
|
||||
$container.append('<img class="cryptofist" src="/customize/cryptofist_small.png" />');
|
||||
var $spinner = $('<div>', {'class': 'spinnerContainer'});
|
||||
var loadingSpinner = common.spinner($spinner).show();
|
||||
var $text = $('<p>').text(loadingText || Messages.loading);
|
||||
$container.append($spinner).append($text);
|
||||
$loading.append($container);
|
||||
$('body').append($loading);
|
||||
if (Messages.tips) {
|
||||
var $loadingTip = $('<div>', {'id': 'loadingTip'});
|
||||
var $tip = $('<span>', {'class': 'tips'}).text(getRandomTip()).appendTo($loadingTip);
|
||||
console.log($('body').height());
|
||||
console.log($container.height());
|
||||
console.log($('body'));
|
||||
console.log($container);
|
||||
$loadingTip.css({
|
||||
'top': $('body').height()/2 + $container.height()/2 + 20 + 'px'
|
||||
});
|
||||
|
||||
@@ -6,10 +6,10 @@ define([
|
||||
|
||||
var Messages = {};
|
||||
|
||||
var ROOT = "root";
|
||||
var UNSORTED = "unsorted";
|
||||
var TRASH = "trash";
|
||||
var TEMPLATE = "template";
|
||||
var ROOT = module.ROOT = "root";
|
||||
var UNSORTED = module.UNSORTED = "unsorted";
|
||||
var TRASH = module.TRASH = "trash";
|
||||
var TEMPLATE = module.TEMPLATE = "template";
|
||||
|
||||
var init = module.init = function (files, config) {
|
||||
var Cryptpad = config.Cryptpad;
|
||||
|
||||
245
www/common/fsStore.js
Normal file
245
www/common/fsStore.js
Normal file
@@ -0,0 +1,245 @@
|
||||
define([
|
||||
'/bower_components/chainpad-listmap/chainpad-listmap.js',
|
||||
'/bower_components/chainpad-crypto/crypto.js?v=0.1.5',
|
||||
'/bower_components/textpatcher/TextPatcher.amd.js',
|
||||
'/common/fileObject.js',
|
||||
'/bower_components/jquery/dist/jquery.min.js',
|
||||
], function (Listmap, Crypto, TextPatcher, FO) {
|
||||
/*
|
||||
This module uses localStorage, which is synchronous, but exposes an
|
||||
asyncronous API. This is so that we can substitute other storage
|
||||
methods.
|
||||
|
||||
To override these methods, create another file at:
|
||||
/customize/storage.js
|
||||
*/
|
||||
var $ = window.jQuery;
|
||||
|
||||
var Store = {};
|
||||
var store;
|
||||
|
||||
var initStore = function (filesOp, storeObj, exp) {
|
||||
var ret = {};
|
||||
|
||||
var safeSet = function (key, val) {
|
||||
storeObj[key] = val;
|
||||
};
|
||||
|
||||
// Store uses nodebacks...
|
||||
ret.set = function (key, val, cb) {
|
||||
safeSet(key, val);
|
||||
cb();
|
||||
};
|
||||
|
||||
// implement in alternative store
|
||||
ret.setBatch = function (map, cb) {
|
||||
Object.keys(map).forEach(function (key) {
|
||||
safeSet(key, map[key]);
|
||||
});
|
||||
cb(void 0, map);
|
||||
};
|
||||
|
||||
ret.setDrive = function (key, val, cb) {
|
||||
storeObj.drive[key] = val;
|
||||
cb();
|
||||
};
|
||||
|
||||
var safeGet = function (key) {
|
||||
return storeObj[key];
|
||||
};
|
||||
|
||||
ret.get = function (key, cb) {
|
||||
cb(void 0, safeGet(key));
|
||||
};
|
||||
|
||||
// implement in alternative store
|
||||
ret.getBatch = function (keys, cb) {
|
||||
var res = {};
|
||||
keys.forEach(function (key) {
|
||||
res[key] = safeGet(key);
|
||||
});
|
||||
cb(void 0, res);
|
||||
};
|
||||
|
||||
ret.getDrive = function (key, cb) {
|
||||
cb(void 0, storeObj.drive[key]);
|
||||
};
|
||||
|
||||
var safeRemove = function (key) {
|
||||
delete storeObj[key];
|
||||
};
|
||||
|
||||
ret.remove = function (key, cb) {
|
||||
safeRemove(key);
|
||||
cb();
|
||||
};
|
||||
|
||||
// implement in alternative store
|
||||
ret.removeBatch = function (keys, cb) {
|
||||
keys.forEach(function (key) {
|
||||
safeRemove(key);
|
||||
});
|
||||
cb();
|
||||
};
|
||||
|
||||
ret.keys = function (cb) {
|
||||
cb(void 0, Object.keys(storeObj));
|
||||
};
|
||||
|
||||
ret.addPad = function (href, path, name) {
|
||||
filesOp.addPad(href, path, name);
|
||||
};
|
||||
|
||||
ret.forgetPad = function (href, cb) {
|
||||
filesOp.forgetPad(href);
|
||||
cb();
|
||||
};
|
||||
|
||||
ret.addTemplate = function (href) {
|
||||
filesOp.addTemplate(href);
|
||||
};
|
||||
|
||||
ret.listTemplates = function () {
|
||||
return filesOp.listTemplates();
|
||||
};
|
||||
|
||||
ret.getProxy = function () {
|
||||
return exp;
|
||||
};
|
||||
|
||||
ret.getLoginName = function () {
|
||||
return storeObj.login_name;
|
||||
};
|
||||
|
||||
ret.repairDrive = function () {
|
||||
filesOp.fixFiles();
|
||||
};
|
||||
|
||||
ret.getEmptyObject = function () {
|
||||
return filesOp.getStructure();
|
||||
};
|
||||
|
||||
ret.replaceHref = function (o, n) {
|
||||
return filesOp.replaceHref(o, n);
|
||||
};
|
||||
|
||||
var changeHandlers = ret.changeHandlers = [];
|
||||
|
||||
ret.change = function (f) {};
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
var onReady = function (f, proxy, Cryptpad, exp) {
|
||||
var fo = exp.fo = FO.init(proxy.drive, {
|
||||
Cryptpad: Cryptpad
|
||||
});
|
||||
|
||||
//storeObj = proxy;
|
||||
store = initStore(fo, proxy, exp);
|
||||
if (typeof(f) === 'function') {
|
||||
f(void 0, store);
|
||||
}
|
||||
|
||||
if (typeof(proxy.allowUserFeedback) !== 'boolean') {
|
||||
proxy.allowUserFeedback = true;
|
||||
}
|
||||
|
||||
proxy.on('change', [Cryptpad.displayNameKey], function (o, n, p) {
|
||||
if (typeof(n) !== "string") { return; }
|
||||
Cryptpad.changeDisplayName(n);
|
||||
});
|
||||
};
|
||||
|
||||
var initialized = false;
|
||||
|
||||
var init = function (f, Cryptpad) {
|
||||
if (!Cryptpad || initialized) { return; }
|
||||
initialized = true;
|
||||
var hash = Cryptpad.getUserHash() || localStorage.FS_hash || Cryptpad.createRandomHash();
|
||||
if (!hash) {
|
||||
throw new Error('[Store.init] Unable to find or create a drive hash. Aborting...');
|
||||
}
|
||||
var secret = Cryptpad.getSecrets(hash);
|
||||
var listmapConfig = {
|
||||
data: {},
|
||||
websocketURL: Cryptpad.getWebsocketURL(),
|
||||
channel: secret.channel,
|
||||
readOnly: false,
|
||||
validateKey: secret.keys.validateKey || undefined,
|
||||
crypto: Crypto.createEncryptor(secret.keys),
|
||||
userName: 'fs',
|
||||
logLevel: 1,
|
||||
};
|
||||
|
||||
var exp = {};
|
||||
|
||||
window.addEventListener('storage', function (e) {
|
||||
var key = e.key;
|
||||
if (e.key !== Cryptpad.userHashKey) { return; }
|
||||
var o = e.oldValue;
|
||||
var n = e.newValue;
|
||||
if (!o && n) {
|
||||
window.location.reload();
|
||||
} else if (o && !n) {
|
||||
$(window).on('keyup', function (e) {
|
||||
if (e.keyCode === 27) {
|
||||
Cryptpad.removeLoadingScreen();
|
||||
}
|
||||
});
|
||||
Cryptpad.logout();
|
||||
Cryptpad.addLoadingScreen();
|
||||
Cryptpad.errorLoadingScreen(Cryptpad.Messages.onLogout, true);
|
||||
if (exp.info) {
|
||||
exp.info.network.disconnect();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var rt = window.rt = Listmap.create(listmapConfig);
|
||||
|
||||
exp.proxy = rt.proxy;
|
||||
rt.proxy.on('create', function (info) {
|
||||
exp.info = info;
|
||||
if (!Cryptpad.getUserHash()) {
|
||||
localStorage.FS_hash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
|
||||
}
|
||||
}).on('ready', function () {
|
||||
if (store) { return; } // the store is already ready, it is a reconnection
|
||||
if (!rt.proxy.drive || typeof(rt.proxy.drive) !== 'object') { rt.proxy.drive = {}; }
|
||||
var drive = rt.proxy.drive;
|
||||
// Creating a new anon drive: import anon pads from localStorage
|
||||
if (!drive[Cryptpad.storageKey] || !Cryptpad.isArray(drive[Cryptpad.storageKey])) {
|
||||
Cryptpad.getLegacyPads(function (err, data) {
|
||||
drive[Cryptpad.storageKey] = data;
|
||||
onReady(f, rt.proxy, Cryptpad, exp);
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Drive already exist: return the existing drive, don't load data from legacy store
|
||||
onReady(f, rt.proxy, Cryptpad, exp);
|
||||
})
|
||||
.on('disconnect', function (info) {
|
||||
// We only manage errors during the loading screen here. Other websocket errors are handled by the apps
|
||||
if (info.error) {
|
||||
if (typeof Cryptpad.storeError === "function") {
|
||||
Cryptpad.storeError();
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
Store.ready = function (f, Cryptpad) {
|
||||
if (store) { // Store.ready probably called twice, store already ready
|
||||
if (typeof(f) === 'function') {
|
||||
f(void 0, store);
|
||||
}
|
||||
} else {
|
||||
init(f, Cryptpad);
|
||||
}
|
||||
};
|
||||
|
||||
return Store;
|
||||
});
|
||||
190
www/common/mergeDrive.js
Normal file
190
www/common/mergeDrive.js
Normal file
@@ -0,0 +1,190 @@
|
||||
require.config({ paths: { 'json.sortify': '/bower_components/json.sortify/dist/JSON.sortify' } });
|
||||
define([
|
||||
'/common/cryptpad-common.js',
|
||||
'/common/cryptget.js',
|
||||
'/common/fileObject.js',
|
||||
'json.sortify'
|
||||
], function (Cryptpad, Crypt, FO, Sortify) {
|
||||
var exp = {};
|
||||
|
||||
var getType = function (el) {
|
||||
if (el === null) { return "null"; }
|
||||
return Array.isArray(el) ? "array" : typeof(el);
|
||||
};
|
||||
|
||||
var findAvailableKey = function (obj, key) {
|
||||
if (typeof (obj[key]) === "undefined") { return key; }
|
||||
var i = 1;
|
||||
var nkey = key;
|
||||
while (typeof (obj[nkey]) !== "undefined") {
|
||||
nkey = key + '_' + i;
|
||||
i++;
|
||||
}
|
||||
return nkey;
|
||||
};
|
||||
|
||||
var copy = function (el) {
|
||||
if (typeof (el) !== "object") { return el; }
|
||||
return JSON.parse(JSON.stringify(el));
|
||||
};
|
||||
|
||||
var deduplicate = function (array) {
|
||||
var a = array.slice();
|
||||
for(var i=0; i<a.length; i++) {
|
||||
for(var j=i+1; j<a.length; j++) {
|
||||
if(a[i] === a[j] || (
|
||||
typeof(a[i]) === "object" && Sortify(a[i]) === Sortify(a[j]))) {
|
||||
a.splice(j--, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return a;
|
||||
};
|
||||
|
||||
// Merge obj2 into obj1
|
||||
// If keepOld is true, obj1 values are kept in case of conflicti
|
||||
// Not used ATM
|
||||
var merge = function (obj1, obj2, keepOld) {
|
||||
if (typeof (obj1) !== "object" || typeof (obj2) !== "object") { return; }
|
||||
Object.keys(obj2).forEach(function (k) {
|
||||
var v = obj2[k];
|
||||
// If one of them is not an object or if we have a map and a array, don't override, create a new key
|
||||
if (!obj1[k] || typeof(obj1[k]) !== "object" || typeof(obj2[k]) !== "object" ||
|
||||
(getType(obj1[k]) !== getType(obj2[k]))) {
|
||||
// We don't want to override the values in the object (username, preferences)
|
||||
// These values should be the ones stored in the first object
|
||||
if (keepOld) { return; }
|
||||
if (obj1[k] === obj2[k]) { return; }
|
||||
var nkey = findAvailableKey(obj1, k);
|
||||
obj1[nkey] = copy(obj2[k]);
|
||||
return;
|
||||
}
|
||||
// Else, they're both maps or both arrays
|
||||
if (getType(obj1[k]) === "array" && getType(obj2[k]) === "array") {
|
||||
var c = obj1[k].concat(obj2[k]);
|
||||
obj1[k] = deduplicate(c);
|
||||
return;
|
||||
}
|
||||
merge(obj1[k], obj2[k], keepOld);
|
||||
});
|
||||
};
|
||||
|
||||
var createFromPath = function (proxy, oldFo, path, href) {
|
||||
var root = proxy.drive;
|
||||
|
||||
var error = function (msg) {
|
||||
console.error(msg || "Unable to find that path", path);
|
||||
};
|
||||
|
||||
if (path[0] === FO.TRASH && path.length === 4) {
|
||||
href = oldFo.getTrashElementData(path);
|
||||
path.pop();
|
||||
}
|
||||
|
||||
var p, next, nextRoot;
|
||||
path.forEach(function (p, i) {
|
||||
if (!root) { return; }
|
||||
if (typeof(p) === "string") {
|
||||
if (getType(root) !== "object") { root = undefined; error(); return; }
|
||||
if (i === path.length - 1) {
|
||||
root[findAvailableKey(root, p)] = href;
|
||||
return;
|
||||
}
|
||||
next = getType(path[i+1]);
|
||||
nextRoot = getType(root[p]);
|
||||
if (nextRoot !== "undefined") {
|
||||
if (next === "string" && nextRoot === "object" || next === "number" && nextRoot === "array") {
|
||||
root = root[p];
|
||||
return;
|
||||
}
|
||||
p = findAvailableKey(root, p);
|
||||
}
|
||||
if (next === "number") {
|
||||
root[p] = [];
|
||||
root = root[p];
|
||||
return;
|
||||
}
|
||||
root[p] = {};
|
||||
root = root[p];
|
||||
return;
|
||||
}
|
||||
// Path contains a non-string element: it's an array index
|
||||
if (typeof(p) !== "number") { root = undefined; error(); return; }
|
||||
if (getType(root) !== "array") { root = undefined; error(); return; }
|
||||
if (i === path.length - 1) {
|
||||
if (root.indexOf(href) === -1) { root.push(href); }
|
||||
return;
|
||||
}
|
||||
next = getType(path[i+1]);
|
||||
if (next === "number") {
|
||||
error('2 consecutives arrays in the user object');
|
||||
root = undefined;
|
||||
//root.push([]);
|
||||
//root = root[root.length - 1];
|
||||
return;
|
||||
}
|
||||
root.push({});
|
||||
root = root[root.length - 1];
|
||||
return;
|
||||
});
|
||||
};
|
||||
|
||||
var mergeAnonDrive = exp.anonDriveIntoUser = function (proxy, cb) {
|
||||
// Make sure we have an FS_hash and we don't use it, otherwise just stop the migration and cb
|
||||
if (!localStorage.FS_hash || !Cryptpad.isLoggedIn()) {
|
||||
if (typeof(cb) === "function") { cb(); }
|
||||
}
|
||||
// Get the content of FS_hash and then merge the objects, remove the migration key and cb
|
||||
var todo = function (err, doc) {
|
||||
if (err) { console.error("Cannot migrate recent pads", err); return; }
|
||||
var parsed;
|
||||
try { parsed = JSON.parse(doc); } catch (e) { console.error("Cannot parsed recent pads", e); return; }
|
||||
if (parsed) {
|
||||
//merge(proxy, parsed, true);
|
||||
var oldFo = FO.init(parsed.drive, {
|
||||
Cryptpad: Cryptpad
|
||||
});
|
||||
var newData = Cryptpad.getStore().getProxy();
|
||||
var newFo = newData.fo;
|
||||
var newRecentPads = proxy.drive[Cryptpad.storageKey];
|
||||
var newFiles = newFo.getFilesDataFiles();
|
||||
var oldFiles = oldFo.getFilesDataFiles();
|
||||
oldFiles.forEach(function (href) {
|
||||
// Do not migrate a pad if we already have it, it would create a duplicate in the drive
|
||||
if (newFiles.indexOf(href) !== -1) { return; }
|
||||
// If we have a stronger version, do not add the current href
|
||||
if (Cryptpad.findStronger(href, newRecentPads)) { return; }
|
||||
// If we have a weaker version, replace the href by the new one
|
||||
// NOTE: if that weaker version is in the trash, the strong one will be put in unsorted
|
||||
var weaker = Cryptpad.findWeaker(href, newRecentPads);
|
||||
if (weaker) {
|
||||
// Update RECENTPADS
|
||||
newRecentPads.some(function (pad) {
|
||||
if (pad.href === weaker) {
|
||||
pad.href = href;
|
||||
return true;
|
||||
}
|
||||
return;
|
||||
});
|
||||
// Update the file in the drive
|
||||
newFo.replaceHref(weaker, href);
|
||||
return;
|
||||
}
|
||||
// Here it means we have a new href, so we should add it to the drive at its old location
|
||||
var paths = oldFo.findFile(href);
|
||||
if (paths.length === 0) { return; }
|
||||
createFromPath(proxy, oldFo, paths[0], href);
|
||||
// Also, push the file data in our array
|
||||
var data = oldFo.getFileData(href);
|
||||
if (data) {
|
||||
newRecentPads.push(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (typeof(cb) === "function") { cb(); }
|
||||
};
|
||||
Crypt.get(localStorage.FS_hash, todo);
|
||||
};
|
||||
|
||||
return exp;
|
||||
});
|
||||
@@ -9,6 +9,7 @@
|
||||
data-main-favicon="/customize/main-favicon.png"
|
||||
data-alt-favicon="/customize/alt-favicon.png"
|
||||
id="favicon" />
|
||||
<link rel="stylesheet" href="/bower_components/components-font-awesome/css/font-awesome.min.css">
|
||||
<link rel="stylesheet" href="/customize/main.css" />
|
||||
<script data-bootload="main.js" data-main="/common/boot.js" src="/bower_components/requirejs/require.js"></script>
|
||||
<style>
|
||||
@@ -33,5 +34,14 @@
|
||||
</head>
|
||||
<body>
|
||||
<iframe id="pad-iframe"></iframe><script src="/common/noscriptfix.js"></script>
|
||||
<div id="loading">
|
||||
<div class="loadingContainer">
|
||||
<img class="cryptofist" src="/customize/cryptofist_small.png" />
|
||||
<div class="spinnerContainer">
|
||||
<span class="fa fa-spinner fa-pulse fa-4x fa-fw"></span>
|
||||
</div>
|
||||
<p data-localization="loading"></p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -8,8 +8,9 @@ define([
|
||||
'/common/fileObject.js',
|
||||
'/common/toolbar.js',
|
||||
'/customize/application_config.js',
|
||||
'/common/cryptget.js'
|
||||
], function (Listmap, Crypto, TextPatcher, JSONSortify, Cryptpad, FO, Toolbar, AppConfig, Get) {
|
||||
'/common/cryptget.js',
|
||||
'/common/mergeDrive.js'
|
||||
], function (Listmap, Crypto, TextPatcher, JSONSortify, Cryptpad, FO, Toolbar, AppConfig, Get, Merge) {
|
||||
var module = window.MODULE = {};
|
||||
|
||||
var Messages = Cryptpad.Messages;
|
||||
@@ -2056,26 +2057,12 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
// TODO: move that function and use a more generic API?
|
||||
var migrateAnonDrive = function (proxy, cb) {
|
||||
if (sessionStorage.migrateAnonDrive) {
|
||||
// Make sure we have an FS_hash and we don't use it, otherwise just stop the migration and cb
|
||||
if (!localStorage.FS_hash || !APP.loggedIn) {
|
||||
Merge.anonDriveIntoUser(proxy, function () {
|
||||
delete sessionStorage.migrateAnonDrive;
|
||||
if (typeof(cb) === "function") { cb(); }
|
||||
}
|
||||
// Get the content of FS_hash and then merge the objects, remove the migration key and cb
|
||||
var todo = function (err, doc) {
|
||||
if (err) { logError("Cannot migrate recent pads", err); return; }
|
||||
var parsed;
|
||||
try { parsed = JSON.parse(doc); } catch (e) { logError("Cannot parsed recent pads", e); }
|
||||
if (parsed) {
|
||||
$.extend(true, proxy, parsed);
|
||||
}
|
||||
delete sessionStorage.migrateAnonDrive;
|
||||
if (typeof(cb) === "function") { cb(); }
|
||||
};
|
||||
Get.get(localStorage.FS_hash, todo);
|
||||
});
|
||||
} else {
|
||||
if (typeof(cb) === "function") { cb(); }
|
||||
}
|
||||
|
||||
@@ -76,18 +76,21 @@ define([
|
||||
if (result.proxy && !result.proxy.login_name) {
|
||||
result.proxy.login_name = result.userName;
|
||||
}
|
||||
Cryptpad.login(result.userHash, result.userName, function () {
|
||||
if (sessionStorage.redirectTo) {
|
||||
var h = sessionStorage.redirectTo;
|
||||
var parser = document.createElement('a');
|
||||
parser.href = h;
|
||||
if (parser.origin === window.location.origin) {
|
||||
delete sessionStorage.redirectTo;
|
||||
window.location.href = h;
|
||||
return;
|
||||
|
||||
Cryptpad.whenRealtimeSyncs(result.realtime, function() {
|
||||
Cryptpad.login(result.userHash, result.userName, function () {
|
||||
if (sessionStorage.redirectTo) {
|
||||
var h = sessionStorage.redirectTo;
|
||||
var parser = document.createElement('a');
|
||||
parser.href = h;
|
||||
if (parser.origin === window.location.origin) {
|
||||
delete sessionStorage.redirectTo;
|
||||
window.location.href = h;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
window.location.href = '/drive/';
|
||||
window.location.href = '/drive/';
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<title>CryptPad</title>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="/bower_components/components-font-awesome/css/font-awesome.min.css">
|
||||
<link rel="icon" type="image/png"
|
||||
href="/customize/main-favicon.png"
|
||||
data-main-favicon="/customize/main-favicon.png"
|
||||
@@ -56,5 +57,14 @@
|
||||
</head>
|
||||
<body>
|
||||
<iframe id="pad-iframe"></iframe><script src="/common/noscriptfix.js"></script>
|
||||
<div id="loading">
|
||||
<div class="loadingContainer">
|
||||
<img class="cryptofist" src="/customize/cryptofist_small.png" />
|
||||
<div class="spinnerContainer">
|
||||
<span class="fa fa-spinner fa-pulse fa-4x fa-fw"></span>
|
||||
</div>
|
||||
<p data-localization="loading"></p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -143,3 +143,13 @@
|
||||
<button data-localization-title="poll_commit" id="commit"><span class="fa fa-check"></span></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="loading">
|
||||
<div class="loadingContainer">
|
||||
<img class="cryptofist" src="/customize/cryptofist_small.png" />
|
||||
<div class="spinnerContainer">
|
||||
<span class="fa fa-spinner fa-pulse fa-4x fa-fw"></span>
|
||||
</div>
|
||||
<p data-localization="loading"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
define([
|
||||
'/common/cryptpad-common.js',
|
||||
'/common/cryptget.js',
|
||||
'/common/mergeDrive.js',
|
||||
'/bower_components/file-saver/FileSaver.min.js',
|
||||
'/bower_components/jquery/dist/jquery.min.js',
|
||||
], function (Cryptpad, Crypt) {
|
||||
], function (Cryptpad, Crypt, Merge) {
|
||||
var $ = window.jQuery;
|
||||
var saveAs = window.saveAs;
|
||||
|
||||
@@ -41,7 +42,7 @@ define([
|
||||
var obj = store.proxy;
|
||||
var $div = $('<div>', {'class': 'infoBlock'});
|
||||
|
||||
var accountName = obj.login_name;
|
||||
var accountName = obj.login_name || localStorage[Cryptpad.userNameKey];
|
||||
var $label = $('<span>', {'class': 'label'}).text(Messages.user_accountName + ':');
|
||||
var $name = $('<span>').text(accountName || '');
|
||||
if (!accountName) {
|
||||
@@ -65,10 +66,9 @@ define([
|
||||
'id': 'displayName',
|
||||
'placeholder': Messages.anonymous}).appendTo($div);
|
||||
var $save = $('<button>', {'class': 'btn btn-primary'}).text(Messages.settings_save).appendTo($div);
|
||||
var $ok = $('<span>', {'class': 'fa fa-check'}).appendTo($div);
|
||||
var $spinner = $('<span>', {'class': 'fa fa-spinner fa-pulse'}).appendTo($div);
|
||||
var $ok = $('<span>', {'class': 'fa fa-check', title: Messages.saved}).hide().appendTo($div);
|
||||
var $spinner = $('<span>', {'class': 'fa fa-spinner fa-pulse'}).hide().appendTo($div);
|
||||
|
||||
$spinner.hide();
|
||||
var displayName = obj[USERNAME_KEY] || '';
|
||||
$input.val(displayName);
|
||||
|
||||
@@ -135,7 +135,7 @@ define([
|
||||
};
|
||||
var importFile = function (content, file) {
|
||||
var $spinner = $('<span>', {'class': 'fa fa-spinner fa-pulse'}).appendTo($div);
|
||||
Crypt.put(Cryptpad.getUserHash(), content, function (e) {
|
||||
Crypt.put(Cryptpad.getUserHash() || localStorage[Cryptpad.fileHashKey], content, function (e) {
|
||||
if (e) { console.error(e); }
|
||||
$spinner.remove();
|
||||
});
|
||||
@@ -187,29 +187,67 @@ define([
|
||||
|
||||
$('<br>').appendTo($div);
|
||||
|
||||
var $ok = $('<span>', {'class': 'fa fa-check', title: Messages.saved});
|
||||
var $spinner = $('<span>', {'class': 'fa fa-spinner fa-pulse'});
|
||||
|
||||
var $checkbox = $('<input>', {
|
||||
'type': 'checkbox',
|
||||
}).on('change', function () {
|
||||
$spinner.show();
|
||||
$ok.hide();
|
||||
obj.proxy.allowUserFeedback = $checkbox.is(':checked') || false;
|
||||
// TODO provide feedback to show if this is synced
|
||||
// Cryptpad.whenRealtimeSyncs...
|
||||
Cryptpad.whenRealtimeSyncs(obj.info.realtime, function () {
|
||||
$spinner.hide();
|
||||
$ok.show();
|
||||
});
|
||||
});
|
||||
|
||||
$checkbox.appendTo($div);
|
||||
$label.appendTo($div);
|
||||
|
||||
$ok.hide().appendTo($div);
|
||||
$spinner.hide().appendTo($div);
|
||||
|
||||
if (obj.proxy.allowUserFeedback) {
|
||||
$checkbox[0].checked = true;
|
||||
}
|
||||
return $div;
|
||||
};
|
||||
|
||||
var createImportLocalPads = function (obj) {
|
||||
if (!Cryptpad.isLoggedIn()) { return; }
|
||||
var $div = $('<div>', {'class': 'importLocalPads'});
|
||||
var $label = $('<label>', {'for' : 'importLocalPads'}).text(Messages.settings_importTitle).appendTo($div);
|
||||
$('<br>').appendTo($div);
|
||||
var $button = $('<button>', {'id': 'importLocalPads', 'class': 'btn btn-primary'})
|
||||
.text(Messages.settings_import).appendTo($div);
|
||||
var $ok = $('<span>', {'class': 'fa fa-check', title: Messages.saved}).hide().appendTo($div);
|
||||
var $spinner = $('<span>', {'class': 'fa fa-spinner fa-pulse'}).hide().appendTo($div);
|
||||
|
||||
|
||||
$button.click(function () {
|
||||
Cryptpad.confirm(Messages.settings_importConfirm, function (yes) {
|
||||
if (!yes) { return; }
|
||||
$spinner.show();
|
||||
$ok.hide();
|
||||
Merge.anonDriveIntoUser(obj.proxy, function () {
|
||||
$spinner.hide();
|
||||
$ok.show();
|
||||
Cryptpad.alert(Messages.settings_importDone);
|
||||
});
|
||||
}, undefined, true);
|
||||
});
|
||||
|
||||
return $div;
|
||||
};
|
||||
|
||||
var andThen = function (obj) {
|
||||
APP.$container.append(createTitle());
|
||||
APP.$container.append(createInfoBlock(obj));
|
||||
APP.$container.append(createDisplayNameInput(obj));
|
||||
APP.$container.append(createResetTips());
|
||||
APP.$container.append(createBackupDrive(obj));
|
||||
APP.$container.append(createImportLocalPads(obj));
|
||||
APP.$container.append(createResetDrive(obj));
|
||||
APP.$container.append(createUserFeedbackToggle(obj));
|
||||
obj.proxy.on('change', [], refresh);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
data-main-favicon="/customize/main-favicon.png"
|
||||
data-alt-favicon="/customize/alt-favicon.png"
|
||||
id="favicon" />
|
||||
<link rel="stylesheet" href="/bower_components/components-font-awesome/css/font-awesome.min.css">
|
||||
<link rel="stylesheet" href="/customize/main.css" />
|
||||
<style>
|
||||
html, body {
|
||||
@@ -48,5 +49,14 @@
|
||||
<div id="iframe-container">
|
||||
<iframe id="pad-iframe"></iframe><script src="/common/noscriptfix.js"></script>
|
||||
</div>
|
||||
<div id="loading">
|
||||
<div class="loadingContainer">
|
||||
<img class="cryptofist" src="/customize/cryptofist_small.png" />
|
||||
<div class="spinnerContainer">
|
||||
<span class="fa fa-spinner fa-pulse fa-4x fa-fw"></span>
|
||||
</div>
|
||||
<p data-localization="loading"></p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -19,6 +19,9 @@ define([
|
||||
var $content;
|
||||
var $pad;
|
||||
var placeholder;
|
||||
var separator = '<hr data-pewpew="pezpez">';
|
||||
var separatorReg = /<hr data\-pewpew="pezpez">/g;
|
||||
var slideClass = 'slide-frame';
|
||||
|
||||
Slide.onChange = function (f) {
|
||||
if (typeof(f) === 'function') {
|
||||
@@ -26,11 +29,15 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
var getNumberOfSlides = function () {
|
||||
return $content.find('.' + slideClass).length;
|
||||
};
|
||||
|
||||
var change = function (oldIndex, newIndex) {
|
||||
if (Slide.changeHandlers.length) {
|
||||
Slide.changeHandlers.some(function (f, i) {
|
||||
// HERE
|
||||
f(oldIndex, newIndex, Slide.content.length);
|
||||
f(oldIndex, newIndex, getNumberOfSlides());
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -76,7 +83,7 @@ define([
|
||||
var Err;
|
||||
var Els = [A, B].map(function (frag) {
|
||||
if (typeof(frag) === 'object') {
|
||||
if (!frag && frag.body) {
|
||||
if (!frag || (frag && !frag.body)) {
|
||||
Err = "No body";
|
||||
return;
|
||||
}
|
||||
@@ -108,19 +115,23 @@ define([
|
||||
};
|
||||
|
||||
var draw = Slide.draw = function (i) {
|
||||
console.log("Trying to draw slide #%s", i);
|
||||
if (typeof(Slide.content[i]) !== 'string') { return; }
|
||||
i = i || 0;
|
||||
if (typeof(Slide.content) !== 'string') { return; }
|
||||
|
||||
var c = Slide.content[i];
|
||||
var Dom = domFromHTML('<div id="content">' + Marked(c) + '</div>');
|
||||
var c = Slide.content;
|
||||
var m = '<span class="'+slideClass+'">'+Marked(c).replace(separatorReg, '</span><span class="'+slideClass+'">')+'</span>';
|
||||
|
||||
var Dom = domFromHTML('<div id="content">' + m + '</div>');
|
||||
removeListeners(Dom.body);
|
||||
var patch = makeDiff(domFromHTML($content[0].outerHTML), Dom);
|
||||
|
||||
if (typeof(patch) === 'string') {
|
||||
$content.html(Marked(c));
|
||||
$content.html(m);
|
||||
} else {
|
||||
DD.apply($content[0], patch);
|
||||
}
|
||||
$content.find('.' + slideClass).hide();
|
||||
$content.find('.' + slideClass + ':eq( ' + i + ' )').show();
|
||||
change(Slide.lastIndex, Slide.index);
|
||||
};
|
||||
|
||||
@@ -161,11 +172,11 @@ define([
|
||||
|
||||
var update = Slide.update = function (content) {
|
||||
if (!Slide.shown) { return; }
|
||||
if (!content) { content = placeholder; }
|
||||
var old = Slide.content[Slide.index];
|
||||
Slide.content = content.split(/\n\s*\-\-\-\s*\n/).filter(truthy);
|
||||
if (old !== Slide.content[Slide.index]) {
|
||||
draw(Slide.index);
|
||||
if (!content) { content = ''; }
|
||||
var old = Slide.content;
|
||||
Slide.content = content.replace(/\n\s*\-\-\-\s*\n/g, '\n\n'+separator+'\n\n');
|
||||
if (old !== Slide.content) {
|
||||
draw();
|
||||
return;
|
||||
}
|
||||
change(Slide.lastIndex, Slide.index);
|
||||
@@ -183,7 +194,7 @@ define([
|
||||
console.log('right');
|
||||
Slide.lastIndex = Slide.index;
|
||||
|
||||
var i = Slide.index = Math.min(Slide.content.length -1, Slide.index + 1);
|
||||
var i = Slide.index = Math.min(getNumberOfSlides() -1, Slide.index + 1);
|
||||
Slide.draw(i);
|
||||
};
|
||||
|
||||
@@ -199,7 +210,7 @@ define([
|
||||
console.log('end');
|
||||
Slide.lastIndex = Slide.index;
|
||||
|
||||
var i = Slide.index = Slide.content.length - 1;
|
||||
var i = Slide.index = getNumberOfSlides() - 1;
|
||||
Slide.draw(i);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user