summaryrefslogtreecommitdiffstats
path: root/apps/files_versions/js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_versions/js')
-rw-r--r--apps/files_versions/js/versions.js72
1 files changed, 47 insertions, 25 deletions
diff --git a/apps/files_versions/js/versions.js b/apps/files_versions/js/versions.js
index eadf7a51039..82d569fa0f6 100644
--- a/apps/files_versions/js/versions.js
+++ b/apps/files_versions/js/versions.js
@@ -16,26 +16,34 @@ $(document).ready(function(){
if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback
var file = $('#dir').val()+'/'+filename;
-
- createVersionsDropdown(filename, file)
-
+ // Check if drop down is already visible for a different file
+ if (($('#dropdown').length > 0)) {
+ 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) {
-
- var historyUrl = OC.linkTo('files_versions', 'history.php?path='+encodeURIComponent( $( '#dir' ).val() ).replace( /%2F/g, '/' )+'/'+encodeURIComponent( filename ) )
+
+ var historyUrl = OC.linkTo('files_versions', 'history.php') + '?path='+encodeURIComponent( $( '#dir' ).val() ).replace( /%2F/g, '/' )+'/'+encodeURIComponent( filename );
var html = '<div id="dropdown" class="drop" data-file="'+files+'">';
html += '<div id="private">';
- html += '<select data-placeholder="File Version" id="found_versions" class="chzen-select">';
- html += '<option value="">Saved versions</option>';
+ html += '<select data-placeholder="Saved versions" id="found_versions" class="chzen-select" style="width:16em;">';
+ html += '<option value=""></option>';
html += '</select>';
html += '</div>';
//html += '<input type="button" value="Revert file" onclick="revertFile()" />';
- html += '<input type="button" value="Revert file..." onclick="window.location=\''+historyUrl+'\'" name="makelink" id="makelink" />';
- html += '<br />';
+ html += '<input type="button" value="All versions..." onclick="window.location=\''+historyUrl+'\'" name="makelink" id="makelink" />';
html += '<input id="link" style="display:none; width:90%;" />';
if (filename) {
@@ -47,7 +55,7 @@ function createVersionsDropdown(filename, files) {
$.ajax({
type: 'GET',
- url: OC.linkTo('files_versions', 'ajax/getVersions.php'),
+ url: OC.filePath('files_versions', 'ajax', 'getVersions.php'),
dataType: 'json',
data: { source: files },
async: false,
@@ -56,36 +64,50 @@ function createVersionsDropdown(filename, files) {
//alert("helo "+OC.linkTo('files_versions', 'ajax/getVersions.php'));
if (versions) {
-
$.each( versions, function(index, row ) {
-
- addVersion( row );
+ addVersion( row );
});
-
+ $('#found_versions').chosen();
+ } 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);
+ })
}
});
- function revertFile() {
+ function revertFile(file, revision) {
$.ajax({
type: 'GET',
url: OC.linkTo('files_versions', 'ajax/rollbackVersion.php'),
dataType: 'json',
- data: {path: file, revision: 'revision'},
+ data: {file: file, revision: revision},
async: false,
- success: function(versions) {
- if (versions) {
+ success: function(response) {
+ if (response.status=='error') {
+ OC.dialogs.alert('Failed to revert '+file+' to revision '+formatDate(revision*1000)+'.','Failed to revert');
+ } else {
+ $('#dropdown').hide('blind', function() {
+ $('#dropdown').remove();
+ $('tr').removeClass('mouseOver');
+ // TODO also update the modified time in the web ui
+ });
}
}
});
-
+
}
- function addVersion( name ) {
-
- var version = '<option>'+name+'</option>';
+ function addVersion(revision ) {
+ name=formatDate(revision*1000);
+ var version=$('<option/>');
+ version.attr('value',revision);
+ version.text(name);
// } else {
// var checked = ((permissions > 0) ? 'checked="checked"' : 'style="display:none;"');
@@ -98,10 +120,10 @@ function createVersionsDropdown(filename, files) {
// user += '</li>';
// }
- $(version).appendTo('#found_versions');
+ version.appendTo('#found_versions');
}
$('#dropdown').show('blind');
- $('#share_with').chosen();
+
}