nextcloud/apps/files_versions/js/versions.js

149 lines
4.6 KiB
JavaScript
Raw Normal View History

$(document).ready(function() {
$('#versions').bind('change', function() {
var checked = 1;
if (!this.checked) {
checked = 0;
}
$.post(OC.filePath('files_versions','ajax','togglesettings.php'), 'versions='+checked);
});
});
$(document).ready(function(){
if (typeof FileActions !== 'undefined') {
2012-09-21 14:30:13 +04:00
// Add history button to 'files/index.php'
FileActions.register(
'file'
2012-09-21 14:30:13 +04:00
, t('files_versions', 'History')
, OC.PERMISSION_UPDATE
, function() {
// Specify icon for hitory button
return OC.imagePath('core','actions/history');
}
,function(filename){
// Action to perform when clicked
if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback
var file = $('#dir').val()+'/'+filename;
// Check if drop down is already visible for a different file
if (($('#dropdown').length > 0) && $('#dropdown').hasClass('drop-versions') ) {
if (file != $('#dropdown').data('file')) {
$('#dropdown').hide('blind', function() {
$('#dropdown').remove();
$('tr').removeClass('mouseOver');
createVersionsDropdown(filename, file);
});
}
} else {
createVersionsDropdown(filename, file);
}
}
);
}
});
function createVersionsDropdown(filename, files) {
2012-05-18 13:59:56 +04:00
var historyUrl = OC.linkTo('files_versions', 'history.php') + '?path='+encodeURIComponent( $( '#dir' ).val() ).replace( /%2F/g, '/' )+'/'+encodeURIComponent( filename );
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)+'">';
html += '<div id="private">';
html += '<select data-placeholder="Saved versions" id="found_versions" class="chzen-select" style="width:16em;">';
2012-05-18 02:57:52 +04:00
html += '<option value=""></option>';
html += '</select>';
html += '</div>';
html += '<input type="button" value="All versions..." onclick="window.location=\''+historyUrl+'\'" name="makelink" id="makelink" />';
html += '<input id="link" style="display:none; width:90%;" />';
2012-08-29 10:42:49 +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'));
}
2012-08-29 10:42:49 +04:00
$.ajax({
type: 'GET',
url: OC.filePath('files_versions', 'ajax', 'getVersions.php'),
dataType: 'json',
data: { source: files },
async: false,
success: function( versions ) {
2012-10-14 23:04:08 +04:00
if (versions) {
$.each( versions, function(index, row ) {
addVersion( row );
});
} else {
$('#found_versions').hide();
$('#makelink').hide();
$('<div style="text-align:center;">No other versions available</div>').appendTo('#dropdown');
}
$('#found_versions').change(function(){
var revision=parseInt($(this).val());
revertFile(files,revision);
2012-09-06 00:17:33 +04:00
});
}
});
2012-08-29 10:42:49 +04:00
function revertFile(file, revision) {
2012-08-29 10:42:49 +04:00
$.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.dialogs.alert('Failed to revert '+file+' to revision '+formatDate(revision*1000)+'.','Failed to revert');
} else {
2012-05-18 02:57:52 +04:00
$('#dropdown').hide('blind', function() {
$('#dropdown').remove();
$('tr').removeClass('mouseOver');
// TODO also update the modified time in the web ui
});
}
}
2012-08-29 10:42:49 +04:00
});
}
2012-08-29 10:42:49 +04:00
function addVersion( revision ) {
name=formatDate(revision.version*1000);
var version=$('<option/>');
version.attr('value',revision.version);
version.text(name);
2012-08-29 10:42:49 +04: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 10:42:49 +04:00
version.appendTo('#found_versions');
}
2012-10-14 23:04:08 +04:00
$('tr').filterAttr('data-file',filename).addClass('mouseOver');
$('#dropdown').show('blind');
2012-08-29 10:42:49 +04:00
}
$(this).click(
function(event) {
if ($('#dropdown').has(event.target).length === 0 && $('#dropdown').hasClass('drop-versions')) {
$('#dropdown').hide('blind', function() {
$('#dropdown').remove();
$('tr').removeClass('mouseOver');
});
}
2012-10-14 23:04:08 +04:00
}
2012-09-21 14:30:13 +04:00
);