Refresh snapshot modal after creation or deletion

pull/1/head
yflory 4 years ago
parent a936c64794
commit bac3fb0a25

@ -128,6 +128,7 @@
margin-bottom: @snapshot_spacing;
max-height: 245px;
overflow: auto;
min-height: 100px;
.cp-snapshot-element {
display: flex;
align-items: center;

@ -85,7 +85,7 @@
border-left: none;
width: 2px !important;
background: @pos-color;
&:before {
&:before {
left: -6px;
}
}

@ -3315,11 +3315,27 @@ define([
Messages.snapshots_open = "View";
Messages.snapshots_delete = "Delete";
UIElements.openSnapshotsModal = function (common, load, make, remove) {
var modal;
var readOnly = common.getMetadataMgr().getPrivateData().readOnly;
var container = h('div.cp-snapshots-container', {tabindex:0});
var $container = $(container);
var input = h('input', {
placeholder: Messages.snapshots_placeholder
});
var $input = $(input);
var content = h('div.cp-snapshots-modal', [
h('h5', Messages.snapshots_button),
container,
readOnly ? undefined : h('h6', Messages.snapshots_new),
readOnly ? undefined : input
]);
var refresh = function () {
var metadataMgr = common.getMetadataMgr();
var md = metadataMgr.getMetadata();
var snapshots = md.snapshots || {};
var modal;
var readOnly = common.getMetadataMgr().getPrivateData().readOnly;
var list = Object.keys(snapshots).sort(function (h1, h2) {
var s1 = snapshots[h1];
@ -3347,10 +3363,7 @@ define([
classes: 'btn-danger'
}, function () {
remove(hash, s);
if (modal && modal.closeModal) {
modal.closeModal();
UIElements.openSnapshotsModal(common, load, make, remove);
}
refresh();
});
return h('span.cp-snapshot-element', {tabindex:0}, [
@ -3366,16 +3379,13 @@ define([
]);
});
var input = h('input', {
placeholder: Messages.snapshots_placeholder
$container.html('').append(list);
setTimeout(function () {
if (list.length) { return void $container.focus(); }
$input.focus();
});
var $input = $(input);
var content = h('div.cp-snapshots-modal', [
h('h5', Messages.snapshots_button),
h('div.cp-snapshots-container', list),
readOnly ? undefined : h('h6', Messages.snapshots_new),
readOnly ? undefined : input
]);
};
refresh();
var buttons = [{
className: 'cancel',
@ -3391,23 +3401,19 @@ define([
onClick: function () {
var val = $input.val();
if (!val) { return true; }
make(val);
setTimeout(function () {
UIElements.openSnapshotsModal(common, load, make, remove);
$container.html('');
UI.spinner($container).get().show();
make(val, function (err) {
if (err) { return; }
refresh();
});
return true;
},
keys: [],
});
}
modal = UI.openCustomModal(UI.dialog.customModal(content, {buttons: buttons }));
setTimeout(function () {
if (list.length) {
$(list[0]).focus();
return;
}
$input.focus();
});
};
return UIElements;

@ -137,21 +137,22 @@ define([
cpNfInner.metadataMgr.updateMetadata(md);
onLocal();
};
var makeSnapshot = function (title) {
var makeSnapshot = function (title, cb) {
var sframeChan = common.getSframeChannel();
sframeChan.query("Q_GET_LAST_HASH", null, function (err, obj) {
if (err || (obj && obj.error)) { return void UI.warn(Messages.error); }
var hash = obj.hash;
if (!hash) { return void UI.warn(Messages.error); }
if (!hash) { cb('NO_HASH'); return void UI.warn(Messages.error); }
var md = Util.clone(cpNfInner.metadataMgr.getMetadata());
var snapshots = md.snapshots = md.snapshots || {};
if (snapshots[hash]) { return void UI.warn(Messages.error); } // XXX EEXISTS
if (snapshots[hash]) { cb('EEXISTS'); return void UI.warn(Messages.error); } // XXX
snapshots[hash] = {
title: title,
time: +new Date()
};
cpNfInner.metadataMgr.updateMetadata(md);
onLocal();
cpNfInner.chainpad.onSettle(cb);
});
};

Loading…
Cancel
Save