Add restore button to the revision history sidebar
This commit is contained in:
parent
ea484bb357
commit
4cda46798e
@ -241,6 +241,10 @@
|
|||||||
padding: 10px 0;
|
padding: 10px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#revisionsContainer li:first-child .restoreVersion{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
#revisionsContainer a{
|
#revisionsContainer a{
|
||||||
padding-left: 15px;
|
padding-left: 15px;
|
||||||
}
|
}
|
||||||
@ -249,6 +253,11 @@
|
|||||||
background-color: rgba(0, 0, 0, 0.1);
|
background-color: rgba(0, 0, 0, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.restoreVersion{
|
||||||
|
position: absolute;
|
||||||
|
right: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
#show-more-versions{
|
#show-more-versions{
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
@ -218,6 +218,7 @@ var documentsMain = {
|
|||||||
revHistoryItemTemplate: '<li>' +
|
revHistoryItemTemplate: '<li>' +
|
||||||
'<a href="{{downloadUrl}}" class="downloadVersion has-tooltip" title="Download"><img src="{{downloadIconUrl}}" />' +
|
'<a href="{{downloadUrl}}" class="downloadVersion has-tooltip" title="Download"><img src="{{downloadIconUrl}}" />' +
|
||||||
'<a class="versionPreview"><span class="versiondate has-tooltip" title="{{relativeTimestamp}}">{{formattedTimestamp}}</span></a>' +
|
'<a class="versionPreview"><span class="versiondate has-tooltip" title="{{relativeTimestamp}}">{{formattedTimestamp}}</span></a>' +
|
||||||
|
'<a href="{{restoreUrl}}" class="restoreVersion"><img src="{{restoreIconUrl}}" />' +
|
||||||
'</a>' +
|
'</a>' +
|
||||||
'</li>',
|
'</li>',
|
||||||
|
|
||||||
@ -281,7 +282,7 @@ var documentsMain = {
|
|||||||
addRevision: function(fileId, version, relativeTimestamp, documentPath) {
|
addRevision: function(fileId, version, relativeTimestamp, documentPath) {
|
||||||
var formattedTimestamp = OC.Util.formatDate(parseInt(version) * 1000);
|
var formattedTimestamp = OC.Util.formatDate(parseInt(version) * 1000);
|
||||||
var fileName = documentsMain.fileName.substring(0, documentsMain.fileName.indexOf('.'));
|
var fileName = documentsMain.fileName.substring(0, documentsMain.fileName.indexOf('.'));
|
||||||
var downloadUrl;
|
var downloadUrl, restoreUrl;
|
||||||
if (version === 0) {
|
if (version === 0) {
|
||||||
formattedTimestamp = t('richdocuments', 'Latest revision');
|
formattedTimestamp = t('richdocuments', 'Latest revision');
|
||||||
downloadUrl = OC.generateUrl('apps/files/download'+ documentPath);
|
downloadUrl = OC.generateUrl('apps/files/download'+ documentPath);
|
||||||
@ -290,12 +291,16 @@ var documentsMain = {
|
|||||||
downloadUrl = OC.generateUrl('apps/files_versions/download.php?file={file}&revision={revision}',
|
downloadUrl = OC.generateUrl('apps/files_versions/download.php?file={file}&revision={revision}',
|
||||||
{file: documentPath, revision: version});
|
{file: documentPath, revision: version});
|
||||||
fileId = fileId + '_' + version;
|
fileId = fileId + '_' + version;
|
||||||
|
restoreUrl = OC.generateUrl('apps/files_versions/ajax/rollbackVersion.php?file={file}&revision={revision}',
|
||||||
|
{file: documentPath, revision: version});
|
||||||
}
|
}
|
||||||
|
|
||||||
var revHistoryItemTemplate = Handlebars.compile(documentsMain.UI.revHistoryItemTemplate);
|
var revHistoryItemTemplate = Handlebars.compile(documentsMain.UI.revHistoryItemTemplate);
|
||||||
var html = revHistoryItemTemplate({
|
var html = revHistoryItemTemplate({
|
||||||
downloadUrl: downloadUrl,
|
downloadUrl: downloadUrl,
|
||||||
downloadIconUrl: OC.imagePath('core', 'actions/download'),
|
downloadIconUrl: OC.imagePath('core', 'actions/download'),
|
||||||
|
restoreUrl: restoreUrl,
|
||||||
|
restoreIconUrl: OC.imagePath('core', 'actions/history'),
|
||||||
relativeTimestamp: relativeTimestamp,
|
relativeTimestamp: relativeTimestamp,
|
||||||
formattedTimestamp: formattedTimestamp
|
formattedTimestamp: formattedTimestamp
|
||||||
});
|
});
|
||||||
@ -363,6 +368,42 @@ var documentsMain = {
|
|||||||
$(e.currentTarget.parentElement).addClass('active');
|
$(e.currentTarget.parentElement).addClass('active');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#revisionsContainer').on('click', '.restoreVersion', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// close the viewer
|
||||||
|
documentsMain.onCloseViewer();
|
||||||
|
|
||||||
|
// close the editor
|
||||||
|
documentsMain.UI.hideEditor();
|
||||||
|
|
||||||
|
// If there are changes in the opened editor, we need to wait
|
||||||
|
// for sometime before these changes can be saved and a revision is created for it,
|
||||||
|
// before restoring to requested version.
|
||||||
|
documentsMain.overlay.documentOverlay('show');
|
||||||
|
setTimeout(function() {
|
||||||
|
// restore selected version
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: e.currentTarget.href,
|
||||||
|
success: function(response) {
|
||||||
|
if (response.status === 'error') {
|
||||||
|
documentsMain.UI.notify(t('richdocuments', 'Failed to revert the document to older version'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// generate file id with returnToDir information in it, if any
|
||||||
|
var fileid = e.currentTarget.parentElement.dataset.fileid.replace(/_.*/, '') +
|
||||||
|
(documentsMain.returnToDir ? '_' + documentsMain.returnToDir : '');
|
||||||
|
|
||||||
|
// load the file again, it should get reverted now
|
||||||
|
window.location = OC.generateUrl('apps/richdocuments/index#{fileid}', {fileid: fileid});
|
||||||
|
window.location.reload();
|
||||||
|
documentsMain.overlay.documentOverlay('hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
|
||||||
// fake click on first revision (i.e current revision)
|
// fake click on first revision (i.e current revision)
|
||||||
$('#revisionsContainer li').first().find('.versionPreview').click();
|
$('#revisionsContainer li').first().find('.versionPreview').click();
|
||||||
},
|
},
|
||||||
@ -785,7 +826,7 @@ var documentsMain = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
onClose: function(force) {
|
onClose: function() {
|
||||||
if (!documentsMain.isEditorMode){
|
if (!documentsMain.isEditorMode){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -798,7 +839,7 @@ var documentsMain = {
|
|||||||
documentsMain.UI.hideEditor();
|
documentsMain.UI.hideEditor();
|
||||||
$('#ocToolbar').remove();
|
$('#ocToolbar').remove();
|
||||||
|
|
||||||
if (!force && documentsMain.returnToDir) {
|
if (documentsMain.returnToDir) {
|
||||||
window.location = OC.generateUrl('apps/files?dir={dir}', {dir: documentsMain.returnToDir});
|
window.location = OC.generateUrl('apps/files?dir={dir}', {dir: documentsMain.returnToDir});
|
||||||
} else {
|
} else {
|
||||||
documentsMain.show();
|
documentsMain.show();
|
||||||
@ -806,9 +847,12 @@ var documentsMain = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onCloseViewer: function() {
|
onCloseViewer: function() {
|
||||||
|
$('#revisionsContainer *').off();
|
||||||
|
|
||||||
$('#revPanelContainer').remove();
|
$('#revPanelContainer').remove();
|
||||||
$('#revViewerContainer').remove();
|
$('#revViewerContainer').remove();
|
||||||
documentsMain.isViewerMode = false;
|
documentsMain.isViewerMode = false;
|
||||||
|
documentsMain.UI.revisionsStart = 0;
|
||||||
|
|
||||||
$('#loleafletframe').focus();
|
$('#loleafletframe').focus();
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user