cryptpad/www/common/sframe-common-history.js

692 lines
26 KiB
JavaScript
Raw Normal View History

2017-08-21 16:21:25 +00:00
define([
'jquery',
'/common/common-interface.js',
'/common/common-util.js',
2020-09-22 12:40:04 +00:00
'/common/hyperscript.js',
'/customize/messages.js',
'/bower_components/nthen/index.js',
2017-11-23 15:56:49 +00:00
//'/bower_components/chainpad-json-validator/json-ot.js',
2017-08-21 16:21:25 +00:00
'/bower_components/chainpad/chainpad.dist.js',
], function ($, UI, Util, h, Messages, nThen, ChainPad /* JsonOT */) {
2017-11-24 09:32:58 +00:00
//var ChainPad = window.ChainPad;
2017-08-21 16:21:25 +00:00
var History = {};
History.create = function (common, config) {
if (!config.$toolbar) { return void console.error("config.$toolbar is undefined");}
if (History.loading) { return void console.error("History is already being loaded..."); }
2020-09-28 16:53:24 +00:00
if (History.state) { return void console.error("Already loaded"); }
History.loading = true;
2020-09-28 16:53:24 +00:00
History.state = true;
var $toolbar = config.$toolbar;
2020-09-28 16:53:24 +00:00
var $hist = $toolbar.find('.cp-toolbar-history');
$hist.addClass('cp-history-init');
if (!config.applyVal || !config.setHistory || !config.onLocal || !config.onRemote) {
throw new Error("Missing config element: applyVal, onLocal, onRemote, setHistory");
2017-08-21 16:21:25 +00:00
}
var getStates = function (rt) {
var states = [];
var b = rt.getAuthBlock();
if (b) { states.unshift(b); }
while (b.getParent()) {
b = b.getParent();
states.unshift(b);
}
return states;
};
var createRealtime = function (config) {
2017-08-21 16:21:25 +00:00
return ChainPad.create({
userName: 'history',
validateContent: function (content) {
try {
JSON.parse(content);
return true;
} catch (e) {
console.log('Failed to parse, rejecting patch');
return false;
}
},
2017-08-21 16:21:25 +00:00
initialState: '',
2017-12-07 17:51:50 +00:00
logLevel: config.debug ? 2 : 0,
2017-08-21 16:21:25 +00:00
noPrune: true
});
};
var fillChainPad = function (realtime, messages) {
messages.forEach(function (m) {
realtime.message(m);
});
};
2017-08-21 16:21:25 +00:00
2020-09-28 14:19:40 +00:00
var realtime;
var states = [];
2020-09-28 16:53:24 +00:00
var patchWidth = 0;
2020-09-28 14:19:40 +00:00
var c = 0;//states.length - 1;
var getIndex = function (i) {
return states.length - 1 + i;
};
var getRank = function (idx) {
return idx - states.length + 1;
};
// Get the author or group of author linked to a state
var getAuthor = function (idx, semantic) {
if (semantic === 1 || !config.extractMetadata) {
return states[idx].author;
}
try {
var val = JSON.parse(states[idx].getContent().doc);
var md = config.extractMetadata(val);
var users = Object.keys(md.users).sort();
return users.join();
} catch (e) {
console.error(e);
return states[idx].author;
}
};
var bar = h('span.cp-history-timeline-bar');
2020-09-28 16:53:24 +00:00
var onResize = function () {
var $bar = $(bar);
if (!$bar.width() || !$bar.length) { return; }
var widthPx = patchWidth * $bar.width() / 100;
$hist.removeClass('cp-smallpatch');
$bar.find('.cp-history-snapshot').css('margin-left', "");
var $pos = $hist.find('.cp-history-timeline-pos');
$pos.css('margin-left', "");
if (widthPx < 18) {
$hist.addClass('cp-smallpatch');
$bar.find('.cp-history-snapshot').css('margin-left', (widthPx/2-2)+"px");
$pos.css('margin-left', (widthPx/2-2)+"px");
}
};
// Refresh the timeline UI with the block states
var refreshBar = function (snapshotsOnly) {
2020-09-28 16:53:24 +00:00
var $pos = $hist.find('.cp-history-timeline-pos');
var $bar = $(bar);
2020-09-28 14:19:40 +00:00
var users = {
list: [],
author: '',
el: undefined,
i: 0
};
var user = {
list: [],
author: '',
el: undefined,
i: 0
};
2020-09-28 16:53:24 +00:00
var snapshotsData = {};
var snapshots = [];
if (config.getLastMetadata) {
try {
var md = config.getLastMetadata();
2020-09-28 16:53:24 +00:00
if (md.snapshots) {
snapshotsData = md.snapshots;
snapshots = Object.keys(md.snapshots);
}
} catch (e) { console.error(e); }
}
2020-09-28 16:53:24 +00:00
2020-09-28 14:19:40 +00:00
var max = states.length - 1;
var snapshotsEl = [];
patchWidth = 100 / max;
// Check if we need a new block on the index i for the "obj" type (user or users)
2020-09-28 14:19:40 +00:00
var check = function (obj, author, i) {
if (snapshotsOnly) { return; }
2020-09-28 14:19:40 +00:00
if (obj.author !== author) {
obj.author = author;
if (obj.el) {
$(obj.el).css('width', (100*(i - obj.i)/max)+'%');
}
obj.el = h('span.cp-history-bar-el');
obj.list.push(obj.el);
obj.i = i;
}
};
2020-09-28 16:53:24 +00:00
var hash;
2020-09-28 14:19:40 +00:00
for (var i = 1; i < states.length; i++) {
2020-09-28 16:53:24 +00:00
hash = states[i].serverHash;
if (snapshots.indexOf(hash) !== -1) {
snapshotsEl.push(h('div.cp-history-snapshot', {
style: 'width:'+patchWidth+'%;left:'+(patchWidth * (i-1))+'%;',
title: snapshotsData[hash].title
}, h('i.fa.fa-camera')));
}
2020-09-29 14:44:07 +00:00
if (config.drive) {
// Display only one bar, split by patch
check(user, i, i);
} else {
// Display two bars, split by author(s)
check(user, getAuthor(i, 1), i);
check(users, getAuthor(i, 2), i);
}
2020-09-28 14:19:40 +00:00
}
if (snapshotsOnly) {
// We only want to redraw the snapshots
2020-09-29 14:44:07 +00:00
$bar.find('.cp-history-snapshots').html('').append([
$pos,
2020-09-28 16:53:24 +00:00
snapshotsEl
]);
} else {
$(user.el).css('width', (100*(max + 1 - user.i)/max)+'%');
2020-09-29 14:44:07 +00:00
if (!config.drive) {
$(users.el).css('width', (100*(max + 1 - users.i)/max)+'%');
}
$bar.html('').append([
h('span.cp-history-timeline-users', users.list),
h('span.cp-history-timeline-user', user.list),
h('div.cp-history-snapshots', [
$pos[0],
snapshotsEl
]),
]);
}
2020-09-28 14:19:40 +00:00
2020-09-28 16:53:24 +00:00
onResize();
2020-09-28 14:19:40 +00:00
};
var allMessages = [];
var lastKnownHash;
var isComplete = false;
var loadMoreHistory = function (config, common, cb) {
if (isComplete) { return void cb ('EFULL'); }
var realtime = createRealtime(config);
var sframeChan = common.getSframeChannel();
sframeChan.query('Q_GET_HISTORY_RANGE', {
2019-06-17 12:13:06 +00:00
lastKnownHash: lastKnownHash,
sharedFolder: config.sharedFolder
}, function (err, data) {
if (err) { return void console.error(err); }
if (!Array.isArray(data.messages)) { return void console.error('Not an array!'); }
lastKnownHash = data.lastKnownHash;
isComplete = data.isFull;
var messages = (data.messages || []).map(function (obj) {
2020-04-02 08:21:12 +00:00
return obj;
});
// We're supposed to receive 2 checkpoints. If the result is only ONE message
// and this message is a checkpoint, it means it's the last message of the history
// (and this is a trimmed history)
if (messages.length === 1) {
var parsed = JSON.parse(messages[0].msg);
if (parsed[0] === 4) {
isComplete = true;
}
}
if (config.debug) { console.log(data.messages); }
Array.prototype.unshift.apply(allMessages, messages); // Destructive concat
fillChainPad(realtime, allMessages);
2018-06-25 14:59:40 +00:00
cb (null, realtime, data.isFull);
});
};
2017-08-21 16:21:25 +00:00
// config.setHistory(bool, bool)
// - bool1: history value
// - bool2: reset old content?
var render = function (val) {
if (typeof val === "undefined") { return; }
try {
config.applyVal(val);
} catch (e) {
// Probably a parse error
console.error(e);
}
};
var onClose = function () {
config.setHistory(false, true);
};
2017-08-21 16:21:25 +00:00
var onRevert = function () {
// Before we can restore the current version, we need to update metadataMgr
// so that it will uses the snapshots from the realtime version!
// Restoring the snapshots to their old version would go against the
// goal of having snapshots
if (config.getLastMetadata) {
var metadataMgr = common.getMetadataMgr();
var lastMd = config.getLastMetadata();
var _snapshots = lastMd.snapshots;
var _users = lastMd.users;
var md = Util.clone(metadataMgr.getMetadata());
md.snapshots = _snapshots;
md.users = _users;
metadataMgr.updateMetadata(md);
}
// And now we can properly restore the content
var closed = config.setHistory(false, false);
if (!closed) {
return void UI.alert(Messages.history_cantRestore);
}
2017-08-21 16:21:25 +00:00
config.onLocal();
config.onRemote();
return true;
2017-08-21 16:21:25 +00:00
};
config.setHistory(true);
2017-08-21 16:21:25 +00:00
2020-05-15 09:43:14 +00:00
var $bottom = $toolbar.find('.cp-toolbar-bottom');
2017-08-21 16:21:25 +00:00
var $cke = $toolbar.find('.cke_toolbox_main');
$hist.html('').css('display', 'flex');
2020-05-15 09:43:14 +00:00
$bottom.hide();
2017-08-21 16:21:25 +00:00
$cke.hide();
UI.spinner($hist).get().show();
2017-08-21 16:21:25 +00:00
var update = function (newRt) {
realtime = newRt;
2017-08-21 16:21:25 +00:00
if (!realtime) { return []; }
states = getStates(realtime);
2020-09-28 14:19:40 +00:00
refreshBar();
2017-08-21 16:21:25 +00:00
return states;
};
var $loadMore, $time, get;
2017-08-21 16:21:25 +00:00
// Get the content of the selected version, and change the version number
var loading = false;
var loadMore = function (cb) {
if (loading) { return; }
loading = true;
2020-09-28 14:19:40 +00:00
$loadMore.find('.fa-ellipsis-h').hide();
$loadMore.find('.fa-refresh').show();
2018-06-25 14:59:40 +00:00
loadMoreHistory(config, common, function (err, newRt, isFull) {
if (err === 'EFULL') {
$loadMore.off('click').hide();
get(c);
return;
}
loading = false;
if (err) { return void console.error(err); }
update(newRt);
2020-09-28 14:19:40 +00:00
$loadMore.find('.fa-ellipsis-h').show();
$loadMore.find('.fa-refresh').hide();
get(c);
2018-06-25 14:59:40 +00:00
if (isFull) {
$loadMore.off('click').hide();
}
if (cb) { cb(); }
});
};
2020-09-22 11:45:12 +00:00
2020-09-24 08:59:31 +00:00
// semantic === 1 : group by user
// semantic === 2 : group by "group of users"
get = function (i, blockOnly, semantic) {
2017-08-21 16:21:25 +00:00
i = parseInt(i);
if (isNaN(i)) { return; }
if (i > 0) { i = 0; }
if (i < -(states.length - 2)) { i = -(states.length - 2); }
2020-09-22 11:45:12 +00:00
var idx = getIndex(i);
2020-09-28 14:19:40 +00:00
if (semantic && i !== c) {
// If semantic is true, jump to the next patch from a different netflux ID
2020-09-24 08:59:31 +00:00
var author = getAuthor(idx, semantic);
2020-09-28 14:19:40 +00:00
var forward = i > c;
for (var j = idx; (j > 0 && j < states.length ); (forward ? j++ : j--)) {
2020-09-24 08:59:31 +00:00
if (author !== getAuthor(j, semantic)) {
2020-09-22 11:45:12 +00:00
break;
}
2020-09-28 14:19:40 +00:00
idx = j;
i = getRank(idx);
2020-09-22 11:45:12 +00:00
}
}
if (i <= -(states.length - 11)) {
loadMore();
}
2020-07-08 09:21:51 +00:00
if (blockOnly) { return states[idx]; }
var val = states[idx].getContent().doc;
2017-08-21 16:21:25 +00:00
c = i;
2020-09-28 14:19:40 +00:00
$hist.find('.cp-toolbar-history-next, .cp-toolbar-history-previous')
.prop('disabled', '');
if (c === -(states.length-1)) {
2020-09-28 14:19:40 +00:00
$hist.find('.cp-toolbar-history-previous').prop('disabled', 'disabled');
}
if (c === 0) {
2020-09-28 14:19:40 +00:00
$hist.find('.cp-toolbar-history-next').prop('disabled', 'disabled');
}
2020-09-28 14:19:40 +00:00
var $pos = $hist.find('.cp-history-timeline-pos');
var p = 100 * (1 - (-(c - 1) / (states.length-1)));
2020-09-28 16:53:24 +00:00
$pos.css('left', p+'%');
$pos.css('width', patchWidth+'%');
// Display the version when the full history is loaded
// Note: the first version is always empty and probably can't be displayed, so
// we can consider we have only states.length - 1 versions
2020-09-22 12:40:04 +00:00
var time = states[idx].time;
if (time) {
$time.text(new Date(time).toLocaleString());
} else { $time.text(''); }
2017-11-21 16:37:38 +00:00
if (config.debug) {
console.log(states[idx]);
var ops = states[idx] && states[idx].getPatch() && states[idx].getPatch().operations;
2017-11-21 16:37:38 +00:00
if (Array.isArray(ops)) {
ops.forEach(function (op) { console.log(op); });
}
}
2017-08-21 16:21:25 +00:00
return val || '';
};
2020-09-24 08:59:31 +00:00
/*
2017-08-21 16:21:25 +00:00
var getNext = function (step) {
return typeof step === "number" ? get(c + step) : get(c + 1);
};
var getPrevious = function (step) {
return typeof step === "number" ? get(c - step) : get(c - 1);
};
2020-09-24 08:59:31 +00:00
*/
2017-08-21 16:21:25 +00:00
var makeSnapshot = function (title) {
var idx = getIndex(c);
if (!config.getLastMetadata || !config.setLastMetadata) { return; }
try {
var block = states[idx];
var hash = block.serverHash;
var md = config.getLastMetadata();
md.snapshots = md.snapshots || {};
if (md.snapshots[hash]) { return; }
md.snapshots[hash] = {
title: title,
time: block.time ? (+new Date(block.time)) : +new Date()
};
var sent = config.setLastMetadata(md);
if (!sent) { return void UI.alert(Messages.snapshots_cantMake); }
2020-10-08 08:53:42 +00:00
$input.val('');
refreshBar();
} catch (e) {
console.error(e);
}
};
2017-08-21 16:21:25 +00:00
// Create the history toolbar
var display = function () {
$hist.html('');
$hist.removeClass('cp-history-init');
2020-09-29 08:18:06 +00:00
var fastPrev = h('button.cp-toolbar-history-previous', { title: Messages.history_fastPrev }, [
2020-09-28 14:19:40 +00:00
h('i.fa.fa-step-backward'),
h('i.fa.fa-users')
]);
2020-09-29 08:18:06 +00:00
var userPrev = h('button.cp-toolbar-history-previous', { title: Messages.history_userPrev }, [
2020-09-28 14:19:40 +00:00
h('i.fa.fa-step-backward'),
h('i.fa.fa-user')
]);
var prev = h('button.cp-toolbar-history-previous', { title: Messages.history_prev }, [
h('i.fa.fa-step-backward')
]);
2020-09-29 14:40:53 +00:00
var fastNext = h('button.cp-toolbar-history-next', { title: Messages.history_fastNext }, [
2020-09-28 14:19:40 +00:00
h('i.fa.fa-users'),
h('i.fa.fa-step-forward'),
]);
2020-09-29 08:18:06 +00:00
var userNext = h('button.cp-toolbar-history-next', { title: Messages.history_userNext }, [
2020-09-28 14:19:40 +00:00
h('i.fa.fa-user'),
h('i.fa.fa-step-forward'),
]);
2020-09-29 14:44:07 +00:00
var next = h('button.cp-toolbar-history-next', { title: Messages.history_next }, [
2020-09-28 14:19:40 +00:00
h('i.fa.fa-step-forward')
]);
2020-09-29 14:44:07 +00:00
if (config.drive) {
fastNext = h('button.cp-toolbar-history-next', { title: Messages.history_next }, [
h('i.fa.fa-fast-forward'),
]);
fastPrev = h('button.cp-toolbar-history-previous', {title: Messages.history_prev}, [
h('i.fa.fa-fast-backward'),
]);
}
2020-09-28 14:19:40 +00:00
var $fastPrev = $(fastPrev);
var $userPrev = $(userPrev);
var $prev = $(prev);
var $fastNext = $(fastNext);
var $userNext = $(userNext);
var $next = $(next);
var _loadMore = h('button.cp-toolbar-history-loadmore', { title: Messages.history_loadMore }, [
h('i.fa.fa-ellipsis-h'),
h('i.fa.fa-refresh.fa-spin.fa-3x.fa-fw', { style: 'display: none;' })
]);
var pos = h('span.cp-history-timeline-pos.fa.fa-caret-down');
2020-09-28 14:19:40 +00:00
var time = h('div.cp-history-timeline-time');
$time = $(time);
var timeline = h('div.cp-toolbar-history-timeline', [
h('div.cp-history-timeline-line', [
h('span.cp-history-timeline-legend', [
h('i.fa.fa-users'),
h('i.fa.fa-user')
]),
h('span.cp-history-timeline-loadmore', _loadMore),
h('span.cp-history-timeline-container', [
bar
])
]),
h('div.cp-history-timeline-actions', [
h('span.cp-history-timeline-prev', [
fastPrev,
2020-09-29 14:44:07 +00:00
config.drive ? undefined : userPrev,
2020-09-28 14:19:40 +00:00
prev,
]),
time,
h('span.cp-history-timeline-next', [
next,
2020-09-29 14:44:07 +00:00
config.drive ? undefined : userNext,
2020-09-28 14:19:40 +00:00
fastNext
])
])
]);
var snapshot = h('button', {
2020-09-29 08:18:06 +00:00
title: Messages.snapshots_new,
2020-09-28 14:19:40 +00:00
}, [
h('i.fa.fa-camera')
]);
2020-09-29 08:18:06 +00:00
var share = h('button', { title: Messages.history_shareTitle }, [
2020-09-28 14:19:40 +00:00
h('i.fa.fa-shhare-alt'),
h('span', Messages.shareButton)
]);
2020-09-29 16:07:39 +00:00
var restoreTitle = config.drive ? Messages.history_restoreDriveTitle
: Messages.history_restoreTitle;
2020-09-28 14:19:40 +00:00
var restore = h('button', {
2020-09-29 16:07:39 +00:00
title: restoreTitle,
2020-09-28 14:19:40 +00:00
}, [
h('i.fa.fa-check'),
h('span', Messages.history_restore)
]);
var close = h('button', { title: Messages.history_closeTitle }, [
h('i.fa.fa-times'),
h('span', Messages.history_close)
]);
var actions = h('div.cp-toolbar-history-actions', [
h('span.cp-history-actions-first', [
snapshot,
share
]),
h('span.cp-history-actions-last', [
restore,
close
])
]);
if (History.readOnly) {
snapshot.disabled = true;
restore.disabled = true;
}
if (config.drive) {
2020-09-29 14:44:07 +00:00
$hist.addClass('cp-history-drive');
$(snapshot).hide();
$(share).hide();
}
2020-09-28 14:19:40 +00:00
$hist.append([timeline, actions]);
2020-09-28 16:53:24 +00:00
onResize();
$(window).on('resize', onResize);
2017-08-21 16:21:25 +00:00
2020-09-28 14:35:06 +00:00
var $bar = $(bar);
2020-09-28 16:53:24 +00:00
$bar.find('.cp-history-snapshots').append(pos);
2020-09-28 14:35:06 +00:00
$bar.click(function (e) {
2020-09-28 14:19:40 +00:00
e.stopPropagation();
2020-09-28 14:35:06 +00:00
var $t = $(e.target);
2020-09-28 16:53:24 +00:00
if ($t.closest('.cp-history-snapshot').length) {
$t = $t.closest('.cp-history-snapshot');
}
var isEl = $t.is('.cp-history-snapshot');
if (!$t.is('.cp-history-snapshots') && !isEl) { return; }
2020-09-28 14:35:06 +00:00
var x = e.offsetX;
if (isEl) {
x += $t.position().left;
}
var p = x / $bar.width();
2020-09-28 16:53:24 +00:00
var v = 1-Math.ceil((states.length - 1) * (1 - p));
2020-09-28 14:19:40 +00:00
render(get(v));
});
$loadMore = $(_loadMore).click(function () {
loadMore(function () {
get(c);
});
});
2017-08-21 16:21:25 +00:00
var onKeyDown, onKeyUp;
2020-09-28 14:19:40 +00:00
var closeUI = function () {
2020-09-28 16:53:24 +00:00
History.state = false;
2017-08-21 16:21:25 +00:00
$hist.hide();
2020-05-15 09:43:14 +00:00
$bottom.show();
2017-08-21 16:21:25 +00:00
$cke.show();
2017-09-04 13:09:54 +00:00
$(window).trigger('resize');
$(window).off('keydown', onKeyDown);
$(window).off('keyup', onKeyUp);
2017-08-21 16:21:25 +00:00
};
// Version buttons
2020-09-24 08:59:31 +00:00
$prev.click(function () { render(get(c - 1)); });
$next.click(function () { render(get(c + 1)); });
2020-09-29 14:44:07 +00:00
if (config.drive) {
$fastPrev.click(function () { render(get(c - 10)); });
$fastNext.click(function () { render(get(c + 10)); });
$userPrev.click(function () { render(get(c - 10)); });
$userNext.click(function () { render(get(c + 10)); });
} else {
$userPrev.click(function () { render(get(c - 1, false, 1)); });
$userNext.click(function () { render(get(c + 1, false, 1)); });
$fastPrev.click(function () { render(get(c - 1, false, 2)); });
$fastNext.click(function () { render(get(c + 1, false, 2)); });
}
onKeyDown = function (e) {
2017-08-21 16:21:25 +00:00
var p = function () { e.preventDefault(); };
2020-09-24 08:59:31 +00:00
if (e.which === 39) { p(); return $next.click(); } // Right
if (e.which === 37) { p(); return $prev.click(); } // Left
if (e.which === 38) { p(); return $userNext.click(); } // Up
if (e.which === 40) { p(); return $userPrev.click(); } // Down
2020-09-22 11:45:12 +00:00
if (e.which === 33) { p(); return $fastNext.click(); } // PageUp
if (e.which === 34) { p(); return $fastPrev.click(); } // PageUp
2020-09-28 14:19:40 +00:00
if (e.which === 27) { p(); $(close).click(); }
};
onKeyUp = function (e) { e.stopPropagation(); };
$(window).on('keydown', onKeyDown).on('keyup', onKeyUp).focus();
// Snapshots
$(snapshot).click(function () {
var input = h('input', {
placeholder: Messages.snapshots_placeholder
});
var $input = $(input);
var content = h('div', [
h('h5', Messages.snapshots_new),
input
]);
var buttons = [{
className: 'cancel',
name: Messages.filePicker_close,
onClick: function () {},
keys: [27],
}, {
className: 'primary',
2020-09-30 09:31:12 +00:00
iconClass: '.fa.fa-camera',
name: Messages.snapshots_new,
onClick: function () {
var val = $input.val();
if (!val) { return true; }
makeSnapshot(val);
},
keys: [],
}];
UI.openCustomModal(UI.dialog.customModal(content, {buttons: buttons }));
setTimeout(function () {
$input.focus();
});
});
2020-07-08 09:21:51 +00:00
// Share
2020-09-28 14:19:40 +00:00
$(share).click(function () {
2020-07-08 09:21:51 +00:00
var block = get(c, true);
common.getSframeChannel().event('EV_SHARE_OPEN', {
versionHash: block.serverHash,
//title: title
});
});
// Close & restore buttons
2020-09-28 14:19:40 +00:00
$(close).click(function () {
2017-08-21 16:21:25 +00:00
states = [];
onClose();
2020-09-28 14:19:40 +00:00
closeUI();
2017-08-21 16:21:25 +00:00
});
2020-09-28 14:19:40 +00:00
$(restore).click(function () {
2020-09-29 16:07:39 +00:00
var restorePrompt = config.drive ? Messages.history_restoreDrivePrompt
: Messages.history_restorePrompt;
UI.confirm(restorePrompt, function (yes) {
2017-08-21 16:21:25 +00:00
if (!yes) { return; }
var done = onRevert();
if (done) {
2020-09-28 14:19:40 +00:00
closeUI();
2020-09-29 16:07:39 +00:00
var restoreDone = config.drive ? Messages.history_restoreDriveDone
: Messages.history_restoreDone;
UI.log(restoreDone);
}
2017-08-21 16:21:25 +00:00
});
});
// Display the latest content
render(get(c));
2017-09-04 13:09:54 +00:00
$(window).trigger('resize');
2017-08-21 16:21:25 +00:00
};
2019-06-17 12:13:06 +00:00
if (config.onOpen) {
config.onOpen();
}
2017-08-21 16:21:25 +00:00
// Load all the history messages into a new chainpad object
2018-06-25 14:59:40 +00:00
loadMoreHistory(config, common, function (err, newRt, isFull) {
History.readOnly = common.getMetadataMgr().getPrivateData().readOnly;
2017-08-21 16:21:25 +00:00
History.loading = false;
if (err) { throw new Error(err); }
update(newRt);
2017-08-21 16:21:25 +00:00
display();
2018-06-25 14:59:40 +00:00
if (isFull) {
$loadMore.off('click').hide();
}
2017-08-21 16:21:25 +00:00
});
};
return History;
});