/* * Copyright (c) 2014 * * This file is licensed under the Affero General Public License version 3 * or later. * * See the COPYING-README file. * */ /* global scanFiles, escapeHTML, formatDate */ $(document).ready(function(){ 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; } if (OCA.Files) { // Add versions button to 'files/index.php' OCA.Files.fileActions.register( 'file', 'Versions', OC.PERMISSION_UPDATE, function() { // Specify icon for hitory button return OC.imagePath('core','actions/history'); }, function(filename, context){ // Action to perform when clicked if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback var file = context.dir.replace(/(?!<=\/)$|\/$/, '/' + filename); var createDropDown = true; // Check if drop down is already visible for a different file if (($('#dropdown').length > 0) ) { if ( $('#dropdown').hasClass('drop-versions') && file == $('#dropdown').data('file')) { createDropDown = false; } $('#dropdown').remove(); $('tr').removeClass('mouseOver'); } if(createDropDown === true) { createVersionsDropdown(filename, file, context.fileList); } }, t('files_versions', 'Versions') ); } $(document).on("click", 'span[class="revertVersion"]', function() { var revision = $(this).attr('id'); var file = $(this).attr('value'); revertFile(file, revision); }); }); 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 }); } } }); } function goToVersionPage(url){ window.location.assign(url); } function createVersionsDropdown(filename, files, fileList) { var start = 0; var fileEl; var html = '