Blame view
sources/apps/files_versions/js/versions.js
5.3 KB
|
6d9380f96
|
1 2 3 4 5 6 7 8 9 10 11 |
/* * 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 */ |
|
03e52840d
|
12 13 14 15 16 17 18 19 |
$(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;
}
|
|
6d9380f96
|
20 |
if (OCA.Files) {
|
|
03e52840d
|
21 |
// Add versions button to 'files/index.php' |
|
6d9380f96
|
22 23 24 25 26 |
OCA.Files.fileActions.register(
'file',
'Versions',
OC.PERMISSION_UPDATE,
function() {
|
|
03e52840d
|
27 28 |
// Specify icon for hitory button
return OC.imagePath('core','actions/history');
|
|
6d9380f96
|
29 |
}, function(filename, context){
|
|
03e52840d
|
30 31 |
// Action to perform when clicked
if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback
|
|
6d9380f96
|
32 |
var file = context.dir.replace(/(?!<=\/)$|\/$/, '/' + filename); |
|
31b7f2792
|
33 |
var createDropDown = true; |
|
03e52840d
|
34 |
// Check if drop down is already visible for a different file |
|
31b7f2792
|
35 36 37 |
if (($('#dropdown').length > 0) ) {
if ( $('#dropdown').hasClass('drop-versions') && file == $('#dropdown').data('file')) {
createDropDown = false;
|
|
03e52840d
|
38 |
} |
|
31b7f2792
|
39 40 41 42 43 |
$('#dropdown').remove();
$('tr').removeClass('mouseOver');
}
if(createDropDown === true) {
|
|
6d9380f96
|
44 |
createVersionsDropdown(filename, file, context.fileList); |
|
03e52840d
|
45 |
} |
|
6d9380f96
|
46 |
}, t('files_versions', 'Versions')
|
|
03e52840d
|
47 48 |
); } |
|
03e52840d
|
49 |
|
|
31b7f2792
|
50 51 52 53 54 |
$(document).on("click", 'span[class="revertVersion"]', function() {
var revision = $(this).attr('id');
var file = $(this).attr('value');
revertFile(file, revision);
});
|
|
03e52840d
|
55 |
|
|
31b7f2792
|
56 |
}); |
|
03e52840d
|
57 |
|
|
31b7f2792
|
58 |
function revertFile(file, revision) {
|
|
03e52840d
|
59 60 61 |
$.ajax({
type: 'GET',
|
|
31b7f2792
|
62 |
url: OC.linkTo('files_versions', 'ajax/rollbackVersion.php'),
|
|
03e52840d
|
63 |
dataType: 'json', |
|
31b7f2792
|
64 |
data: {file: file, revision: revision},
|
|
03e52840d
|
65 |
async: false, |
|
31b7f2792
|
66 67 68 69 70 |
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() {
|
|
6d9380f96
|
71 |
$('#dropdown').closest('tr').find('.modified:first').html(relative_modified_date(revision));
|
|
31b7f2792
|
72 73 |
$('#dropdown').remove();
$('tr').removeClass('mouseOver');
|
|
31b7f2792
|
74 75 76 77 78 79 |
}); } } }); } |
|
03e52840d
|
80 |
|
|
31b7f2792
|
81 82 83 |
function goToVersionPage(url){
window.location.assign(url);
}
|
|
03e52840d
|
84 |
|
|
6d9380f96
|
85 |
function createVersionsDropdown(filename, files, fileList) {
|
|
03e52840d
|
86 |
|
|
31b7f2792
|
87 |
var start = 0; |
|
a293d369c
|
88 |
var fileEl; |
|
03e52840d
|
89 |
|
|
31b7f2792
|
90 91 92 93 94 95 |
var html = '<div id="dropdown" class="drop drop-versions" data-file="'+escapeHTML(files)+'">';
html += '<div id="private">';
html += '<ul id="found_versions">';
html += '</ul>';
html += '</div>';
html += '<input type="button" value="'+ t('files_versions', 'More versions...') + '" name="show-more-versions" id="show-more-versions" style="display: none;" />';
|
|
03e52840d
|
96 |
|
|
31b7f2792
|
97 |
if (filename) {
|
|
6d9380f96
|
98 |
fileEl = fileList.findFileEl(filename); |
|
a293d369c
|
99 100 |
fileEl.addClass('mouseOver');
$(html).appendTo(fileEl.find('td.filename'));
|
|
31b7f2792
|
101 102 103 |
} else {
$(html).appendTo($('thead .share'));
}
|
|
03e52840d
|
104 |
|
|
31b7f2792
|
105 106 |
getVersions(start); start = start + 5; |
|
03e52840d
|
107 |
|
|
31b7f2792
|
108 109 110 111 |
$("#show-more-versions").click(function() {
//get more versions
getVersions(start);
start = start + 5;
|
|
03e52840d
|
112 |
}); |
|
31b7f2792
|
113 |
function getVersions(start) {
|
|
03e52840d
|
114 115 |
$.ajax({
type: 'GET',
|
|
31b7f2792
|
116 |
url: OC.filePath('files_versions', 'ajax', 'getVersions.php'),
|
|
03e52840d
|
117 |
dataType: 'json', |
|
31b7f2792
|
118 |
data: {source: files, start: start},
|
|
03e52840d
|
119 |
async: false, |
|
31b7f2792
|
120 121 122 123 |
success: function(result) {
var versions = result.data.versions;
if (result.data.endReached === true) {
$("#show-more-versions").css("display", "none");
|
|
03e52840d
|
124 |
} else {
|
|
31b7f2792
|
125 126 127 128 129 |
$("#show-more-versions").css("display", "block");
}
if (versions) {
$.each(versions, function(index, row) {
addVersion(row);
|
|
03e52840d
|
130 |
}); |
|
31b7f2792
|
131 132 |
} else {
$('<div style="text-align:center;">'+ t('files_versions', 'No other versions available') + '</div>').appendTo('#dropdown');
|
|
03e52840d
|
133 |
} |
|
31b7f2792
|
134 135 136 137 |
$('#found_versions').change(function() {
var revision = parseInt($(this).val());
revertFile(files, revision);
});
|
|
03e52840d
|
138 139 |
} }); |
|
03e52840d
|
140 141 142 |
}
function addVersion( revision ) {
|
|
31b7f2792
|
143 144 145 146 147 148 |
var title = formatDate(revision.version*1000);
var name ='<span class="versionDate" title="' + title + '">' + revision.humanReadableTimestamp + '</span>';
var path = OC.filePath('files_versions', '', 'download.php');
var preview = '<img class="preview" src="'+revision.preview+'"/>';
|
|
a293d369c
|
149 |
var download ='<a href="' + path + "?file=" + encodeURIComponent(files) + '&revision=' + revision.version + '">'; |
|
31b7f2792
|
150 151 152 153 154 155 156 |
download+='<img';
download+=' src="' + OC.imagePath('core', 'actions/download') + '"';
download+=' name="downloadVersion" />';
download+=name;
download+='</a>';
var revert='<span class="revertVersion"';
|
|
a293d369c
|
157 |
revert+=' id="' + revision.version + '">'; |
|
31b7f2792
|
158 159 160 161 162 163 164 165 |
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);
version.html(preview + download + revert);
|
|
a293d369c
|
166 167 |
// add file here for proper name escaping
version.find('span.revertVersion').attr('value', files);
|
|
03e52840d
|
168 169 170 |
version.appendTo('#found_versions');
}
|
|
03e52840d
|
171 |
$('#dropdown').show('blind');
|
|
03e52840d
|
172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
}
$(this).click(
function(event) {
if ($('#dropdown').has(event.target).length === 0 && $('#dropdown').hasClass('drop-versions')) {
$('#dropdown').hide('blind', function() {
$('#dropdown').remove();
$('tr').removeClass('mouseOver');
});
}
}
);
|