2012-04-25 12:56:43 +00:00
|
|
|
$(document).ready(function(){
|
2012-05-02 21:26:41 +00:00
|
|
|
if (typeof FileActions !== 'undefined') {
|
2013-02-27 14:46:49 +00:00
|
|
|
// Add versions button to 'files/index.php'
|
2012-09-12 13:10:12 +00:00
|
|
|
FileActions.register(
|
|
|
|
'file'
|
2013-02-27 14:46:49 +00:00
|
|
|
, t('files_versions', 'Versions')
|
2012-09-12 13:10:12 +00: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 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
|
|
|
|
|
|
|
var file = $('#dir').val()+'/'+filename;
|
|
|
|
// Check if drop down is already visible for a different file
|
2012-10-10 11:46:51 +00:00
|
|
|
if (($('#dropdown').length > 0) && $('#dropdown').hasClass('drop-versions') ) {
|
2012-09-12 13:10:12 +00:00
|
|
|
if (file != $('#dropdown').data('file')) {
|
|
|
|
$('#dropdown').hide('blind', function() {
|
|
|
|
$('#dropdown').remove();
|
|
|
|
$('tr').removeClass('mouseOver');
|
|
|
|
createVersionsDropdown(filename, file);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
createVersionsDropdown(filename, file);
|
2012-05-18 14:42:49 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-12 13:10:12 +00:00
|
|
|
);
|
2012-05-02 21:26:41 +00:00
|
|
|
}
|
2012-04-25 12:56:43 +00:00
|
|
|
});
|
2012-04-23 21:54:49 +00:00
|
|
|
|
2013-02-20 03:14:24 +00:00
|
|
|
function goToVersionPage(url){
|
|
|
|
window.location(url);
|
|
|
|
}
|
|
|
|
|
2012-04-26 12:41:22 +00:00
|
|
|
function createVersionsDropdown(filename, files) {
|
2012-06-04 21:02:05 +00:00
|
|
|
|
2012-05-18 09:59:56 +00:00
|
|
|
var historyUrl = OC.linkTo('files_versions', 'history.php') + '?path='+encodeURIComponent( $( '#dir' ).val() ).replace( /%2F/g, '/' )+'/'+encodeURIComponent( filename );
|
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">';
|
2012-05-18 14:39:43 +00:00
|
|
|
html += '<select data-placeholder="Saved versions" id="found_versions" class="chzen-select" style="width:16em;">';
|
2012-05-17 22:57:52 +00:00
|
|
|
html += '<option value=""></option>';
|
2012-04-25 16:37:45 +00:00
|
|
|
html += '</select>';
|
|
|
|
html += '</div>';
|
2013-02-20 03:14:24 +00:00
|
|
|
html += '<input type="button" value="All versions..." name="makelink" id="makelink" />';
|
2012-04-25 16:37:45 +00:00
|
|
|
html += '<input id="link" style="display:none; width:90%;" />';
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2012-04-25 16:37:45 +00: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 16:21:57 +00:00
|
|
|
|
2013-02-20 03:14:24 +00:00
|
|
|
$("#makelink").click(function() {
|
2013-02-22 16:21:57 +00:00
|
|
|
goToVersionPage(historyUrl);
|
2013-02-20 03:14:24 +00:00
|
|
|
});
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2012-05-11 12:17:37 +00:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
2012-05-17 00:16:33 +00:00
|
|
|
url: OC.filePath('files_versions', 'ajax', 'getVersions.php'),
|
2012-05-11 12:17:37 +00:00
|
|
|
dataType: 'json',
|
|
|
|
data: { source: files },
|
|
|
|
async: false,
|
|
|
|
success: function( versions ) {
|
2012-10-14 19:04:08 +00:00
|
|
|
|
2012-05-11 12:17:37 +00:00
|
|
|
if (versions) {
|
|
|
|
$.each( versions, function(index, row ) {
|
2012-05-17 00:16:33 +00:00
|
|
|
addVersion( row );
|
2012-05-11 12:17:37 +00:00
|
|
|
});
|
2012-05-18 14:39:43 +00:00
|
|
|
} else {
|
|
|
|
$('#found_versions').hide();
|
|
|
|
$('#makelink').hide();
|
|
|
|
$('<div style="text-align:center;">No other versions available</div>').appendTo('#dropdown');
|
2012-05-11 12:17:37 +00:00
|
|
|
}
|
2012-05-17 00:16:33 +00:00
|
|
|
$('#found_versions').change(function(){
|
|
|
|
var revision=parseInt($(this).val());
|
|
|
|
revertFile(files,revision);
|
2012-09-05 20:17:33 +00:00
|
|
|
});
|
2012-04-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
});
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2012-05-17 00:16:33 +00:00
|
|
|
function revertFile(file, revision) {
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2012-04-26 17:45:17 +00:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: OC.linkTo('files_versions', 'ajax/rollbackVersion.php'),
|
|
|
|
dataType: 'json',
|
2012-05-17 00:16:33 +00:00
|
|
|
data: {file: file, revision: revision},
|
2012-04-26 17:45:17 +00:00
|
|
|
async: false,
|
2012-05-17 00:16:33 +00:00
|
|
|
success: function(response) {
|
|
|
|
if (response.status=='error') {
|
|
|
|
OC.dialogs.alert('Failed to revert '+file+' to revision '+formatDate(revision*1000)+'.','Failed to revert');
|
2012-05-17 21:22:48 +00:00
|
|
|
} else {
|
2012-05-17 22:57:52 +00:00
|
|
|
$('#dropdown').hide('blind', function() {
|
|
|
|
$('#dropdown').remove();
|
|
|
|
$('tr').removeClass('mouseOver');
|
|
|
|
// TODO also update the modified time in the web ui
|
|
|
|
});
|
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 ) {
|
2012-06-27 13:05:40 +00:00
|
|
|
name=formatDate(revision.version*1000);
|
2012-05-17 00:16:33 +00:00
|
|
|
var version=$('<option/>');
|
2012-06-27 13:05:40 +00:00
|
|
|
version.attr('value',revision.version);
|
2012-05-17 00:16:33 +00:00
|
|
|
version.text(name);
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2012-04-26 15:48:43 +00:00
|
|
|
// } else {
|
|
|
|
// var checked = ((permissions > 0) ? 'checked="checked"' : 'style="display:none;"');
|
|
|
|
// var style = ((permissions == 0) ? 'style="display:none;"' : '');
|
|
|
|
// var user = '<li data-uid_shared_with="'+uid_shared_with+'">';
|
|
|
|
// user += '<a href="" class="unshare" style="display:none;"><img class="svg" alt="Unshare" src="'+OC.imagePath('core','actions/delete')+'"/></a>';
|
|
|
|
// user += uid_shared_with;
|
|
|
|
// user += '<input type="checkbox" name="permissions" id="'+uid_shared_with+'" class="permissions" '+checked+' />';
|
|
|
|
// user += '<label for="'+uid_shared_with+'" '+style+'>can edit</label>';
|
|
|
|
// user += '</li>';
|
|
|
|
// }
|
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-09-12 13:10:12 +00:00
|
|
|
$('tr').filterAttr('data-file',filename).addClass('mouseOver');
|
2012-04-25 16:37:45 +00:00
|
|
|
$('#dropdown').show('blind');
|
2012-08-29 06:42:49 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
);
|