2012-04-25 16:56:43 +04:00
|
|
|
$(document).ready(function(){
|
2013-07-25 12:35:19 +04:00
|
|
|
|
2013-10-17 23:04:18 +04:00
|
|
|
if ($('#isPublic').val()){
|
|
|
|
// no versions actions in public mode
|
|
|
|
// beware of https://github.com/owncloud/core/issues/4545
|
|
|
|
// as enabling this might hang Chrome
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-10-08 20:48:59 +04:00
|
|
|
var file = $('#dir').val().replace(/(?!<=\/)$|\/$/, '/' + 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');
|
2013-12-03 18:09:58 +04:00
|
|
|
$(html).appendTo($('tr').filterAttr('data-file',filename).find('.name'));
|
2012-04-25 20:37:45 +04:00
|
|
|
} 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) {
|
2013-07-25 13:15:24 +04:00
|
|
|
$("#show-more-versions").css("display", "none");
|
2012-05-18 01:22:48 +04:00
|
|
|
} else {
|
2013-07-25 13:15:24 +04:00
|
|
|
$("#show-more-versions").css("display", "block");
|
2013-07-25 12:35:19 +04:00
|
|
|
}
|
|
|
|
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-31 23:21:02 +04:00
|
|
|
var title = formatDate(revision.version*1000);
|
|
|
|
var name ='<span class="versionDate" title="' + title + '">' + revision.humanReadableTimestamp + '</span>';
|
2013-07-25 12:35:19 +04:00
|
|
|
|
2013-07-31 23:21:02 +04:00
|
|
|
var path = OC.filePath('files_versions', '', 'download.php');
|
2013-07-25 12:35:19 +04:00
|
|
|
|
2013-10-02 17:23:51 +04:00
|
|
|
var preview = '<img class="preview" src="'+revision.preview+'"/>';
|
|
|
|
|
2013-07-31 23:21:02 +04:00
|
|
|
var download ='<a href="' + path + "?file=" + files + '&revision=' + revision.version + '">';
|
2013-07-25 12:35:19 +04:00
|
|
|
download+='<img';
|
|
|
|
download+=' src="' + OC.imagePath('core', 'actions/download') + '"';
|
|
|
|
download+=' name="downloadVersion" />';
|
|
|
|
download+=name;
|
|
|
|
download+='</a>';
|
|
|
|
|
2013-07-31 23:21:02 +04:00
|
|
|
var revert='<span class="revertVersion"';
|
2013-07-25 12:35:19 +04:00
|
|
|
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);
|
2013-10-02 17:23:51 +04:00
|
|
|
version.html(preview + 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
|
|
|
);
|