2012-04-25 08:56:43 -04:00
|
|
|
$(document).ready(function(){
|
2013-07-25 04:35:19 -04:00
|
|
|
|
2012-05-02 17:26:41 -04:00
|
|
|
if (typeof FileActions !== 'undefined') {
|
2013-02-27 09:46:49 -05:00
|
|
|
// Add versions button to 'files/index.php'
|
2012-09-12 09:10:12 -04:00
|
|
|
FileActions.register(
|
|
|
|
|
'file'
|
2013-02-27 09:46:49 -05:00
|
|
|
, t('files_versions', 'Versions')
|
2012-09-12 09: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 07:46:51 -04:00
|
|
|
if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback
|
2012-09-12 09:10:12 -04:00
|
|
|
|
|
|
|
|
var file = $('#dir').val()+'/'+filename;
|
2013-07-25 04:35:19 -04:00
|
|
|
var createDropDown = true;
|
2012-09-12 09:10:12 -04:00
|
|
|
// Check if drop down is already visible for a different file
|
2013-07-25 04:35:19 -04:00
|
|
|
if (($('#dropdown').length > 0) ) {
|
|
|
|
|
if ( $('#dropdown').hasClass('drop-versions') && file == $('#dropdown').data('file')) {
|
|
|
|
|
createDropDown = false;
|
2012-09-12 09:10:12 -04:00
|
|
|
}
|
2013-07-25 04:35:19 -04:00
|
|
|
$('#dropdown').remove();
|
|
|
|
|
$('tr').removeClass('mouseOver');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(createDropDown === true) {
|
2012-09-12 09:10:12 -04:00
|
|
|
createVersionsDropdown(filename, file);
|
2012-05-18 10:42:49 -04:00
|
|
|
}
|
|
|
|
|
}
|
2012-09-12 09:10:12 -04:00
|
|
|
);
|
2012-05-02 17:26:41 -04:00
|
|
|
}
|
2013-07-25 04: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 08:56:43 -04:00
|
|
|
});
|
2012-04-23 17:54:49 -04:00
|
|
|
|
2013-07-25 04: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-19 22:14:24 -05:00
|
|
|
function goToVersionPage(url){
|
2013-02-27 22:26:42 -05:00
|
|
|
window.location.assign(url);
|
2013-02-19 22:14:24 -05:00
|
|
|
}
|
|
|
|
|
|
2012-04-26 08:41:22 -04:00
|
|
|
function createVersionsDropdown(filename, files) {
|
2012-06-04 17:02:05 -04:00
|
|
|
|
2013-07-25 04:35:19 -04:00
|
|
|
var start = 0;
|
2012-08-29 02:42:49 -04:00
|
|
|
|
2012-10-12 08:08:06 -04:00
|
|
|
var html = '<div id="dropdown" class="drop drop-versions" data-file="'+escapeHTML(files)+'">';
|
2012-04-25 12:37:45 -04:00
|
|
|
html += '<div id="private">';
|
2013-07-25 04:35:19 -04:00
|
|
|
html += '<ul id="found_versions">';
|
|
|
|
|
html += '</ul>';
|
2012-04-25 12:37:45 -04:00
|
|
|
html += '</div>';
|
2013-07-25 04: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 02:42:49 -04:00
|
|
|
|
2012-04-25 12: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 11:21:57 -05:00
|
|
|
|
2013-07-25 04:35:19 -04:00
|
|
|
getVersions(start);
|
|
|
|
|
start = start + 5;
|
2012-08-29 02:42:49 -04:00
|
|
|
|
2013-07-25 04:35:19 -04:00
|
|
|
$("#show-more-versions").click(function() {
|
|
|
|
|
//get more versions
|
|
|
|
|
getVersions(start);
|
|
|
|
|
start = start + 5;
|
2012-04-26 11:48:43 -04:00
|
|
|
});
|
2012-08-29 02:42:49 -04:00
|
|
|
|
2013-07-25 04:35:19 -04:00
|
|
|
function getVersions(start) {
|
2012-04-26 13:45:17 -04:00
|
|
|
$.ajax({
|
|
|
|
|
type: 'GET',
|
2013-07-25 04:35:19 -04:00
|
|
|
url: OC.filePath('files_versions', 'ajax', 'getVersions.php'),
|
2012-04-26 13:45:17 -04:00
|
|
|
dataType: 'json',
|
2013-07-25 04:35:19 -04:00
|
|
|
data: {source: files, start: start},
|
2012-04-26 13:45:17 -04:00
|
|
|
async: false,
|
2013-07-25 04:35:19 -04:00
|
|
|
success: function(result) {
|
|
|
|
|
var versions = result.data.versions;
|
|
|
|
|
if (result.data.endReached === true) {
|
2013-07-25 05:15:24 -04:00
|
|
|
$("#show-more-versions").css("display", "none");
|
2012-05-17 17:22:48 -04:00
|
|
|
} else {
|
2013-07-25 05:15:24 -04:00
|
|
|
$("#show-more-versions").css("display", "block");
|
2013-07-25 04:35:19 -04:00
|
|
|
}
|
|
|
|
|
if (versions) {
|
|
|
|
|
$.each(versions, function(index, row) {
|
|
|
|
|
addVersion(row);
|
2012-05-17 18:57:52 -04:00
|
|
|
});
|
2013-07-25 04:35:19 -04:00
|
|
|
} else {
|
|
|
|
|
$('<div style="text-align:center;">'+ t('files_versions', 'No other versions available') + '</div>').appendTo('#dropdown');
|
2012-04-26 13:45:17 -04:00
|
|
|
}
|
2013-07-25 04:35:19 -04:00
|
|
|
$('#found_versions').change(function() {
|
|
|
|
|
var revision = parseInt($(this).val());
|
|
|
|
|
revertFile(files, revision);
|
|
|
|
|
});
|
2012-04-26 13:45:17 -04:00
|
|
|
}
|
2012-08-29 02:42:49 -04:00
|
|
|
});
|
2012-04-26 13:45:17 -04:00
|
|
|
}
|
2012-08-29 02:42:49 -04:00
|
|
|
|
2012-09-12 09:10:12 -04:00
|
|
|
function addVersion( revision ) {
|
2013-07-25 04: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+=' 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+=' name="revertVersion"';
|
|
|
|
|
revert+='/>'+t('files_versions', 'Restore')+'</span>';
|
|
|
|
|
|
|
|
|
|
var version=$('<li/>');
|
|
|
|
|
version.attr('value', revision.version);
|
|
|
|
|
version.html(download + revert);
|
2012-08-29 02:42:49 -04:00
|
|
|
|
2012-05-16 20:16:33 -04:00
|
|
|
version.appendTo('#found_versions');
|
2012-04-26 11:48:43 -04:00
|
|
|
}
|
2012-10-14 15:04:08 -04:00
|
|
|
|
2012-09-12 09:10:12 -04:00
|
|
|
$('tr').filterAttr('data-file',filename).addClass('mouseOver');
|
2012-04-25 12:37:45 -04:00
|
|
|
$('#dropdown').show('blind');
|
2012-08-29 02:42:49 -04:00
|
|
|
|
|
|
|
|
|
2012-04-30 13:18:00 -04:00
|
|
|
}
|
2012-09-12 09:10:12 -04:00
|
|
|
|
|
|
|
|
$(this).click(
|
|
|
|
|
function(event) {
|
2012-10-09 06:00:04 -04:00
|
|
|
if ($('#dropdown').has(event.target).length === 0 && $('#dropdown').hasClass('drop-versions')) {
|
2012-09-12 09:10:12 -04:00
|
|
|
$('#dropdown').hide('blind', function() {
|
|
|
|
|
$('#dropdown').remove();
|
|
|
|
|
$('tr').removeClass('mouseOver');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-14 15:04:08 -04:00
|
|
|
|
2012-09-12 09:10:12 -04:00
|
|
|
}
|
2012-09-21 06:30:13 -04:00
|
|
|
);
|