2012-04-25 16:56:43 +04:00
|
|
|
$(document).ready(function(){
|
2013-07-25 12:35:19 +04:00
|
|
|
|
2012-05-03 01:26:41 +04:00
|
|
|
if (typeof FileActions !== 'undefined') {
|
2013-02-27 18:46:49 +04:00
|
|
|
// Add versions button to 'files/index.php'
|
2012-09-12 17:10:12 +04:00
|
|
|
FileActions.register(
|
|
|
|
'file'
|
2013-02-27 18:46:49 +04:00
|
|
|
, t('files_versions', 'Versions')
|
2012-09-12 17:10:12 +04:00
|
|
|
, OC.PERMISSION_UPDATE
|
|
|
|
, function() {
|
|
|
|
// Specify icon for hitory button
|
|
|
|
return OC.imagePath('core','actions/history');
|
|
|
|
}
|
|
|
|
,function(filename){
|
|
|
|
// Action to perform when clicked
|
2012-10-10 15:46:51 +04:00
|
|
|
if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback
|
2012-09-12 17:10:12 +04:00
|
|
|
|
|
|
|
var file = $('#dir').val()+'/'+filename;
|
2013-07-25 12:35:19 +04:00
|
|
|
var createDropDown = true;
|
2012-09-12 17:10:12 +04:00
|
|
|
// Check if drop down is already visible for a different file
|
2013-07-25 12:35:19 +04:00
|
|
|
if (($('#dropdown').length > 0) ) {
|
|
|
|
if ( $('#dropdown').hasClass('drop-versions') && file == $('#dropdown').data('file')) {
|
|
|
|
createDropDown = false;
|
2012-09-12 17:10:12 +04:00
|
|
|
}
|
2013-07-25 12:35:19 +04:00
|
|
|
$('#dropdown').remove();
|
|
|
|
$('tr').removeClass('mouseOver');
|
|
|
|
}
|
|
|
|
|
|
|
|
if(createDropDown === true) {
|
2012-09-12 17:10:12 +04:00
|
|
|
createVersionsDropdown(filename, file);
|
2012-05-18 18:42:49 +04:00
|
|
|
}
|
|
|
|
}
|
2012-09-12 17:10:12 +04:00
|
|
|
);
|
2012-05-03 01:26:41 +04:00
|
|
|
}
|
2013-07-25 12:35:19 +04:00
|
|
|
|
|
|
|
$(document).on("click", 'span[class="revertVersion"]', function() {
|
|
|
|
var revision = $(this).attr('id');
|
|
|
|
var file = $(this).attr('value');
|
|
|
|
revertFile(file, revision);
|
|
|
|
});
|
|
|
|
|
2012-04-25 16:56:43 +04:00
|
|
|
});
|
2012-04-24 01:54:49 +04:00
|
|
|
|
2013-07-25 12:35:19 +04:00
|
|
|
function revertFile(file, revision) {
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: OC.linkTo('files_versions', 'ajax/rollbackVersion.php'),
|
|
|
|
dataType: 'json',
|
|
|
|
data: {file: file, revision: revision},
|
|
|
|
async: false,
|
|
|
|
success: function(response) {
|
|
|
|
if (response.status === 'error') {
|
|
|
|
OC.Notification.show( t('files_version', 'Failed to revert {file} to revision {timestamp}.', {file:file, timestamp:formatDate(revision * 1000)}) );
|
|
|
|
} else {
|
|
|
|
$('#dropdown').hide('blind', function() {
|
|
|
|
$('#dropdown').remove();
|
|
|
|
$('tr').removeClass('mouseOver');
|
|
|
|
// TODO also update the modified time in the web ui
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-02-20 07:14:24 +04:00
|
|
|
function goToVersionPage(url){
|
2013-02-28 07:26:42 +04:00
|
|
|
window.location.assign(url);
|
2013-02-20 07:14:24 +04:00
|
|
|
}
|
|
|
|
|
2012-04-26 16:41:22 +04:00
|
|
|
function createVersionsDropdown(filename, files) {
|
2012-06-05 01:02:05 +04:00
|
|
|
|
2013-07-25 12:35:19 +04:00
|
|
|
var start = 0;
|
2012-08-29 10:42:49 +04:00
|
|
|
|
2012-10-12 16:08:06 +04:00
|
|
|
var html = '<div id="dropdown" class="drop drop-versions" data-file="'+escapeHTML(files)+'">';
|
2012-04-25 20:37:45 +04:00
|
|
|
html += '<div id="private">';
|
2013-07-25 12:35:19 +04:00
|
|
|
html += '<ul id="found_versions">';
|
|
|
|
html += '</ul>';
|
2012-04-25 20:37:45 +04:00
|
|
|
html += '</div>';
|
2013-07-25 12:35:19 +04:00
|
|
|
html += '<input type="button" value="'+ t('files_versions', 'More versions...') + '" name="show-more-versions" id="show-more-versions" style="display: none;" />';
|
2012-08-29 10:42:49 +04:00
|
|
|
|
2012-04-25 20:37:45 +04:00
|
|
|
if (filename) {
|
|
|
|
$('tr').filterAttr('data-file',filename).addClass('mouseOver');
|
|
|
|
$(html).appendTo($('tr').filterAttr('data-file',filename).find('td.filename'));
|
|
|
|
} else {
|
|
|
|
$(html).appendTo($('thead .share'));
|
|
|
|
}
|
2013-02-22 20:21:57 +04:00
|
|
|
|
2013-07-25 12:35:19 +04:00
|
|
|
getVersions(start);
|
|
|
|
start = start + 5;
|
2012-08-29 10:42:49 +04:00
|
|
|
|
2013-07-25 12:35:19 +04:00
|
|
|
$("#show-more-versions").click(function() {
|
|
|
|
//get more versions
|
|
|
|
getVersions(start);
|
|
|
|
start = start + 5;
|
2012-04-26 19:48:43 +04:00
|
|
|
});
|
2012-08-29 10:42:49 +04:00
|
|
|
|
2013-07-25 12:35:19 +04:00
|
|
|
function getVersions(start) {
|
2012-04-26 21:45:17 +04:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
2013-07-25 12:35:19 +04:00
|
|
|
url: OC.filePath('files_versions', 'ajax', 'getVersions.php'),
|
2012-04-26 21:45:17 +04:00
|
|
|
dataType: 'json',
|
2013-07-25 12:35:19 +04:00
|
|
|
data: {source: files, start: start},
|
2012-04-26 21:45:17 +04:00
|
|
|
async: false,
|
2013-07-25 12:35:19 +04:00
|
|
|
success: function(result) {
|
|
|
|
var versions = result.data.versions;
|
|
|
|
if (result.data.endReached === true) {
|
|
|
|
document.getElementById("show-more-versions").style.display="none";
|
2012-05-18 01:22:48 +04:00
|
|
|
} else {
|
2013-07-25 12:35:19 +04:00
|
|
|
document.getElementById("show-more-versions").style.display="block";
|
|
|
|
}
|
|
|
|
if (versions) {
|
|
|
|
$.each(versions, function(index, row) {
|
|
|
|
addVersion(row);
|
2012-05-18 02:57:52 +04:00
|
|
|
});
|
2013-07-25 12:35:19 +04:00
|
|
|
} else {
|
|
|
|
$('<div style="text-align:center;">'+ t('files_versions', 'No other versions available') + '</div>').appendTo('#dropdown');
|
2012-04-26 21:45:17 +04:00
|
|
|
}
|
2013-07-25 12:35:19 +04:00
|
|
|
$('#found_versions').change(function() {
|
|
|
|
var revision = parseInt($(this).val());
|
|
|
|
revertFile(files, revision);
|
|
|
|
});
|
2012-04-26 21:45:17 +04:00
|
|
|
}
|
2012-08-29 10:42:49 +04:00
|
|
|
});
|
2012-04-26 21:45:17 +04:00
|
|
|
}
|
2012-08-29 10:42:49 +04:00
|
|
|
|
2012-09-12 17:10:12 +04:00
|
|
|
function addVersion( revision ) {
|
2013-07-25 12:35:19 +04:00
|
|
|
title = formatDate(revision.version*1000);
|
|
|
|
name ='<span class="versionDate" title="' + title + '">' + revision.humanReadableTimestamp + '</span>';
|
|
|
|
|
|
|
|
path = OC.filePath('files_versions', '', 'download.php');
|
|
|
|
|
|
|
|
download ='<a href="' + path + "?file=" + files + '&revision=' + revision.version + '">';
|
|
|
|
download+='<img';
|
|
|
|
download+=' src="' + OC.imagePath('core', 'actions/download') + '"';
|
|
|
|
download+=' id="' + revision.version + '"';
|
|
|
|
download+=' value="' + files + '"';
|
|
|
|
download+=' name="downloadVersion" />';
|
|
|
|
download+=name;
|
|
|
|
download+='</a>';
|
|
|
|
|
|
|
|
revert='<span class="revertVersion"';
|
|
|
|
revert+=' id="' + revision.version + '"';
|
|
|
|
revert+=' value="' + files + '">';
|
|
|
|
revert+='<img';
|
|
|
|
revert+=' src="' + OC.imagePath('core', 'actions/history') + '"';
|
|
|
|
revert+=' id="' + revision.version + '"';
|
|
|
|
revert+=' value="' + files + '"';
|
|
|
|
revert+=' name="revertVersion"';
|
|
|
|
revert+='/>'+t('files_versions', 'Restore')+'</span>';
|
|
|
|
|
|
|
|
var version=$('<li/>');
|
|
|
|
version.attr('value', revision.version);
|
|
|
|
version.html(download + revert);
|
2012-08-29 10:42:49 +04:00
|
|
|
|
2012-05-17 04:16:33 +04:00
|
|
|
version.appendTo('#found_versions');
|
2012-04-26 19:48:43 +04:00
|
|
|
}
|
2012-10-14 23:04:08 +04:00
|
|
|
|
2012-09-12 17:10:12 +04:00
|
|
|
$('tr').filterAttr('data-file',filename).addClass('mouseOver');
|
2012-04-25 20:37:45 +04:00
|
|
|
$('#dropdown').show('blind');
|
2012-08-29 10:42:49 +04:00
|
|
|
|
|
|
|
|
2012-04-30 21:18:00 +04:00
|
|
|
}
|
2012-09-12 17:10:12 +04:00
|
|
|
|
|
|
|
$(this).click(
|
|
|
|
function(event) {
|
2012-10-09 14:00:04 +04:00
|
|
|
if ($('#dropdown').has(event.target).length === 0 && $('#dropdown').hasClass('drop-versions')) {
|
2012-09-12 17:10:12 +04:00
|
|
|
$('#dropdown').hide('blind', function() {
|
|
|
|
$('#dropdown').remove();
|
|
|
|
$('tr').removeClass('mouseOver');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-10-14 23:04:08 +04:00
|
|
|
|
2012-09-12 17:10:12 +04:00
|
|
|
}
|
2012-09-21 14:30:13 +04:00
|
|
|
);
|