2014-05-20 09:44:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-05-20 14:01:34 +00:00
|
|
|
/* global scanFiles, escapeHTML, formatDate */
|
2012-04-25 12:56:43 +00:00
|
|
|
$(document).ready(function(){
|
2013-07-25 08:35:19 +00:00
|
|
|
|
2013-10-17 19:04:18 +00: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;
|
|
|
|
}
|
|
|
|
|
2014-05-20 14:01:34 +00:00
|
|
|
if (OCA.Files) {
|
2013-02-27 14:46:49 +00:00
|
|
|
// Add versions button to 'files/index.php'
|
2014-05-20 14:01:34 +00:00
|
|
|
OCA.Files.fileActions.register(
|
2014-05-20 09:44:18 +00:00
|
|
|
'file',
|
|
|
|
'Versions',
|
|
|
|
OC.PERMISSION_UPDATE,
|
|
|
|
function() {
|
2012-09-12 13:10:12 +00:00
|
|
|
// Specify icon for hitory button
|
|
|
|
return OC.imagePath('core','actions/history');
|
2014-05-20 09:44:18 +00:00
|
|
|
}, function(filename, context){
|
2012-09-12 13:10:12 +00:00
|
|
|
// Action to perform when clicked
|
2012-10-10 11:46:51 +00:00
|
|
|
if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback
|
2012-09-12 13:10:12 +00:00
|
|
|
|
2014-05-20 09:44:18 +00:00
|
|
|
var file = context.dir.replace(/(?!<=\/)$|\/$/, '/' + filename);
|
2013-07-25 08:35:19 +00:00
|
|
|
var createDropDown = true;
|
2012-09-12 13:10:12 +00:00
|
|
|
// Check if drop down is already visible for a different file
|
2013-07-25 08:35:19 +00:00
|
|
|
if (($('#dropdown').length > 0) ) {
|
|
|
|
if ( $('#dropdown').hasClass('drop-versions') && file == $('#dropdown').data('file')) {
|
|
|
|
createDropDown = false;
|
2012-09-12 13:10:12 +00:00
|
|
|
}
|
2013-07-25 08:35:19 +00:00
|
|
|
$('#dropdown').remove();
|
|
|
|
$('tr').removeClass('mouseOver');
|
|
|
|
}
|
|
|
|
|
|
|
|
if(createDropDown === true) {
|
2014-05-20 09:44:18 +00:00
|
|
|
createVersionsDropdown(filename, file, context.fileList);
|
2012-05-18 14:42:49 +00:00
|
|
|
}
|
2014-05-20 09:44:18 +00:00
|
|
|
}, t('files_versions', 'Versions')
|
2012-09-12 13:10:12 +00:00
|
|
|
);
|
2012-05-02 21:26:41 +00:00
|
|
|
}
|
2013-07-25 08:35:19 +00:00
|
|
|
|
|
|
|
$(document).on("click", 'span[class="revertVersion"]', function() {
|
|
|
|
var revision = $(this).attr('id');
|
|
|
|
var file = $(this).attr('value');
|
|
|
|
revertFile(file, revision);
|
|
|
|
});
|
|
|
|
|
2012-04-25 12:56:43 +00:00
|
|
|
});
|
2012-04-23 21:54:49 +00:00
|
|
|
|
2013-07-25 08:35:19 +00: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() {
|
2014-06-17 20:22:03 +00:00
|
|
|
$('#dropdown').closest('tr').find('.modified:first').html(relative_modified_date(revision));
|
2013-07-25 08:35:19 +00:00
|
|
|
$('#dropdown').remove();
|
|
|
|
$('tr').removeClass('mouseOver');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-02-20 03:14:24 +00:00
|
|
|
function goToVersionPage(url){
|
2013-02-28 03:26:42 +00:00
|
|
|
window.location.assign(url);
|
2013-02-20 03:14:24 +00:00
|
|
|
}
|
|
|
|
|
2014-05-20 09:44:18 +00:00
|
|
|
function createVersionsDropdown(filename, files, fileList) {
|
2012-06-04 21:02:05 +00:00
|
|
|
|
2013-07-25 08:35:19 +00:00
|
|
|
var start = 0;
|
2014-01-10 14:02:26 +00:00
|
|
|
var fileEl;
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2012-10-12 12:08:06 +00:00
|
|
|
var html = '<div id="dropdown" class="drop drop-versions" data-file="'+escapeHTML(files)+'">';
|
2012-04-25 16:37:45 +00:00
|
|
|
html += '<div id="private">';
|
2013-07-25 08:35:19 +00:00
|
|
|
html += '<ul id="found_versions">';
|
|
|
|
html += '</ul>';
|
2012-04-25 16:37:45 +00:00
|
|
|
html += '</div>';
|
2013-07-25 08:35:19 +00: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 06:42:49 +00:00
|
|
|
|
2012-04-25 16:37:45 +00:00
|
|
|
if (filename) {
|
2014-05-20 09:44:18 +00:00
|
|
|
fileEl = fileList.findFileEl(filename);
|
2014-01-10 14:02:26 +00:00
|
|
|
fileEl.addClass('mouseOver');
|
|
|
|
$(html).appendTo(fileEl.find('td.filename'));
|
2012-04-25 16:37:45 +00:00
|
|
|
} else {
|
|
|
|
$(html).appendTo($('thead .share'));
|
|
|
|
}
|
2013-02-22 16:21:57 +00:00
|
|
|
|
2013-07-25 08:35:19 +00:00
|
|
|
getVersions(start);
|
|
|
|
start = start + 5;
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2013-07-25 08:35:19 +00:00
|
|
|
$("#show-more-versions").click(function() {
|
|
|
|
//get more versions
|
|
|
|
getVersions(start);
|
|
|
|
start = start + 5;
|
2012-04-26 15:48:43 +00:00
|
|
|
});
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2013-07-25 08:35:19 +00:00
|
|
|
function getVersions(start) {
|
2012-04-26 17:45:17 +00:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
2013-07-25 08:35:19 +00:00
|
|
|
url: OC.filePath('files_versions', 'ajax', 'getVersions.php'),
|
2012-04-26 17:45:17 +00:00
|
|
|
dataType: 'json',
|
2013-07-25 08:35:19 +00:00
|
|
|
data: {source: files, start: start},
|
2012-04-26 17:45:17 +00:00
|
|
|
async: false,
|
2013-07-25 08:35:19 +00:00
|
|
|
success: function(result) {
|
|
|
|
var versions = result.data.versions;
|
|
|
|
if (result.data.endReached === true) {
|
2013-07-25 09:15:24 +00:00
|
|
|
$("#show-more-versions").css("display", "none");
|
2012-05-17 21:22:48 +00:00
|
|
|
} else {
|
2013-07-25 09:15:24 +00:00
|
|
|
$("#show-more-versions").css("display", "block");
|
2013-07-25 08:35:19 +00:00
|
|
|
}
|
|
|
|
if (versions) {
|
|
|
|
$.each(versions, function(index, row) {
|
|
|
|
addVersion(row);
|
2012-05-17 22:57:52 +00:00
|
|
|
});
|
2013-07-25 08:35:19 +00:00
|
|
|
} else {
|
|
|
|
$('<div style="text-align:center;">'+ t('files_versions', 'No other versions available') + '</div>').appendTo('#dropdown');
|
2012-04-26 17:45:17 +00:00
|
|
|
}
|
2013-07-25 08:35:19 +00:00
|
|
|
$('#found_versions').change(function() {
|
|
|
|
var revision = parseInt($(this).val());
|
|
|
|
revertFile(files, revision);
|
|
|
|
});
|
2012-04-26 17:45:17 +00:00
|
|
|
}
|
2012-08-29 06:42:49 +00:00
|
|
|
});
|
2012-04-26 17:45:17 +00:00
|
|
|
}
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2012-09-12 13:10:12 +00:00
|
|
|
function addVersion( revision ) {
|
2013-07-31 19:21:02 +00:00
|
|
|
var title = formatDate(revision.version*1000);
|
|
|
|
var name ='<span class="versionDate" title="' + title + '">' + revision.humanReadableTimestamp + '</span>';
|
2013-07-25 08:35:19 +00:00
|
|
|
|
2013-07-31 19:21:02 +00:00
|
|
|
var path = OC.filePath('files_versions', '', 'download.php');
|
2013-07-25 08:35:19 +00:00
|
|
|
|
2013-10-02 13:23:51 +00:00
|
|
|
var preview = '<img class="preview" src="'+revision.preview+'"/>';
|
|
|
|
|
2014-01-10 14:02:26 +00:00
|
|
|
var download ='<a href="' + path + "?file=" + encodeURIComponent(files) + '&revision=' + revision.version + '">';
|
2013-07-25 08:35:19 +00:00
|
|
|
download+='<img';
|
|
|
|
download+=' src="' + OC.imagePath('core', 'actions/download') + '"';
|
|
|
|
download+=' name="downloadVersion" />';
|
|
|
|
download+=name;
|
|
|
|
download+='</a>';
|
|
|
|
|
2013-07-31 19:21:02 +00:00
|
|
|
var revert='<span class="revertVersion"';
|
2014-01-10 14:02:26 +00:00
|
|
|
revert+=' id="' + revision.version + '">';
|
2013-07-25 08:35:19 +00:00
|
|
|
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 13:23:51 +00:00
|
|
|
version.html(preview + download + revert);
|
2014-01-10 14:02:26 +00:00
|
|
|
// add file here for proper name escaping
|
|
|
|
version.find('span.revertVersion').attr('value', files);
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2012-05-17 00:16:33 +00:00
|
|
|
version.appendTo('#found_versions');
|
2012-04-26 15:48:43 +00:00
|
|
|
}
|
2012-10-14 19:04:08 +00:00
|
|
|
|
2012-04-25 16:37:45 +00:00
|
|
|
$('#dropdown').show('blind');
|
2012-04-30 17:18:00 +00:00
|
|
|
}
|
2012-09-12 13:10:12 +00:00
|
|
|
|
|
|
|
$(this).click(
|
|
|
|
function(event) {
|
2012-10-09 10:00:04 +00:00
|
|
|
if ($('#dropdown').has(event.target).length === 0 && $('#dropdown').hasClass('drop-versions')) {
|
2012-09-12 13:10:12 +00:00
|
|
|
$('#dropdown').hide('blind', function() {
|
|
|
|
$('#dropdown').remove();
|
|
|
|
$('tr').removeClass('mouseOver');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-10-14 19:04:08 +00:00
|
|
|
|
2012-09-12 13:10:12 +00:00
|
|
|
}
|
2012-09-21 10:30:13 +00:00
|
|
|
);
|