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