View and restore the history of a pad

This commit is contained in:
yflory
2017-04-21 17:31:47 +02:00
parent 43c045721c
commit 92ea03d7d9
9 changed files with 314 additions and 71 deletions

View File

@@ -54,6 +54,8 @@ define([
var defaultName = Cryptpad.getDefaultName(parsedHash);
var initialState = Messages.codeInitialState;
var isHistoryMode = false;
var editor = module.editor = CMeditor.fromTextArea($textarea[0], {
lineNumbers: true,
lineWrapping: true,
@@ -164,6 +166,14 @@ define([
var canonicalize = function (t) { return t.replace(/\r\n/g, '\n'); };
var setHistory = function (bool, update) {
isHistoryMode = bool;
setEditable(!bool);
if (!bool && update) {
config.onRemote();
}
};
var isDefaultTitle = function () {
var parsed = Cryptpad.parsePadUrl(window.location.href);
return Cryptpad.isDefaultName(parsed, document.title);
@@ -191,6 +201,7 @@ define([
var onLocal = config.onLocal = function () {
if (initializing) { return; }
if (isHistoryMode) { return; }
if (readOnly) { return; }
editor.save();
@@ -372,7 +383,7 @@ define([
var onInit = config.onInit = function (info) {
userList = info.userList;
var config = {
var configTb = {
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad'],
userData: userData,
readOnly: readOnly,
@@ -388,8 +399,7 @@ define([
},
common: Cryptpad
};
if (readOnly) {delete config.changeNameID; }
toolbar = module.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, userList, config);
toolbar = module.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, userList, configTb);
var $rightside = $bar.find('.' + Toolbar.constants.rightside);
var $userBlock = $bar.find('.' + Toolbar.constants.username);
@@ -402,19 +412,36 @@ define([
editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
}
/* add an export button */
var $hist = Cryptpad.createButton();
var historyRender = function () {};
var historyClose = function () {
// TODO: enable onlocal, onremote... (or at least the display part)
/* add a history button */
var histConfig = {};
histConfig.onRender = function (val) {
if (typeof val === "undefined") { return; }
try {
var hjson = JSON.parse(val || '{}');
var remoteDoc = hjson.content;
editor.setValue(remoteDoc || '');
editor.save();
} catch (e) {
// Probably a parse error
console.error(e);
}
};
var historyTodo = function (hist) {
hist.display($bar, historyRender, historyClose);
histConfig.onClose = function () {
// Close button clicked
setHistory(false, true);
};
$hist.removeClass('fa-question').addClass('fa-history').click(function () {
// TODO: disable onlocal, onremote...
Cryptpad.getHistory(historyTodo);
});
histConfig.onRevert = function () {
// Revert button clicked
setHistory(false, false);
config.onLocal();
config.onRemote();
};
histConfig.onReady = function () {
// Called when the history is loaded and the UI displayed
setHistory(true);
};
histConfig.$toolbar = $bar;
var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig});
$rightside.append($hist);
/* save as template */
@@ -663,6 +690,7 @@ define([
var onRemote = config.onRemote = function () {
if (initializing) { return; }
if (isHistoryMode) { return; }
var scroll = editor.getScrollInfo();
var oldDoc = canonicalize($textarea.val());