Skip to content
Snippets Groups Projects
Commit c693ee2a authored by Sam Tuke's avatar Sam Tuke
Browse files

added available version names to files dropdown menu via new ajax script

parent 6312067a
Branches
No related tags found
No related merge requests found
<?php
require_once('../../../lib/base.php');
OC_JSON::checkAppEnabled('files_versions');
require_once('../versions.php');
$userDirectory = "/".OC_User::getUser()."/files";
$source = $_GET['source'];
$source = strip_tags( $source );
if( OCA_Versions\Storage::isversioned( $source ) ) {
$count=5; //show the newest revisions
$versions=OCA_Versions\Storage::getversions( $source, $count);
$versionsSorted = array_reverse( $versions );
if ( !empty( $versionsSorted ) ) {
OC_JSON::encodedPrint($versionsSorted);
}
}else{
return;
}
// $path = $source;
// $users = array();
// if ($users = OC_Share::getMySharedItem($source)) {
// for ($i = 0; $i < count($users); $i++) {
// if ($users[$i]['uid_shared_with'] == OC_Share::PUBLICLINK) {
// $users[$i]['token'] = OC_Share::getTokenFromSource($source);
// }
// }
// }
// $source = dirname($source);
// while ($source != "" && $source != "/" && $source != "." && $source != $userDirectory) {
// if ($values = OC_Share::getMySharedItem($source)) {
// $values = array_values($values);
// $parentUsers = array();
// for ($i = 0; $i < count($values); $i++) {
// if ($values[$i]['uid_shared_with'] == OC_Share::PUBLICLINK) {
// $values[$i]['token'] = OC_Share::getTokenFromSource($source)."&path=".substr($path, strlen($source));
// }
// $parentUsers[basename($source)."-".$i] = $values[$i];
// }
// $users = array_merge($users, $parentUsers);
// }
// $source = dirname($source);
// }
// if (!empty($users)) {
// OC_JSON::encodedPrint($users);
// }
...@@ -9,8 +9,27 @@ $(document).ready(function(){ ...@@ -9,8 +9,27 @@ $(document).ready(function(){
createVersionsDropdown(filename, file) createVersionsDropdown(filename, file)
//window.location='../apps/files_versions/history.php?path='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename); $.ajax({
type: 'GET',
url: OC.linkTo('files_versions', 'ajax/getVersions.php'),
dataType: 'json',
data: {source: file},
async: false,
success: function(versions) {
if (versions) {
// icon = OC.imagePath('core', 'actions/shared');
// $.each(users, function(index, row) {
// if (row.uid_shared_with == 'public') {
// icon = OC.imagePath('core', 'actions/public');
// }
// });
// } else {
// icon = OC.imagePath('core', 'actions/share');
}
shared_status[file]= { timestamp: new Date().getTime(), icon: icon };
}
});
}); });
...@@ -21,17 +40,14 @@ function createVersionsDropdown(filename, files) { ...@@ -21,17 +40,14 @@ function createVersionsDropdown(filename, files) {
//alert( historyUrl ); //alert( historyUrl );
var html = '<div id="dropdown" class="drop" data-file="'+files+'">'; var html = '<div id="dropdown" class="drop" data-file="'+files+'">';
html += '<div id="private">'; html += '<div id="private">';
html += '<select data-placeholder="File Version" id="share_with" class="chzen-select">'; html += '<select data-placeholder="File Version" id="found_versions" class="chzen-select">';
html += '<option value=""></option>'; html += '<option value="">Select version</option>';
html += '</select>'; html += '</select>';
html += '<ul id="shared_list"></ul>';
html += '</div>'; html += '</div>';
html += '<div id="public">';
html += '<input type="button" name="makelink" id="makelink" value="Revert file" />'; html += '<input type="button" name="makelink" id="makelink" value="Revert file" />';
html += '<input type="button" onclick="window.location=\''+historyUrl+'\'" name="makelink" id="makelink" value="More..." />'; html += '<input type="button" onclick="window.location=\''+historyUrl+'\'" name="makelink" id="makelink" value="More..." />';
html += '<br />'; html += '<br />';
html += '<input id="link" style="display:none; width:90%;" />'; html += '<input id="link" style="display:none; width:90%;" />';
html += '</div>';
if (filename) { if (filename) {
$('tr').filterAttr('data-file',filename).addClass('mouseOver'); $('tr').filterAttr('data-file',filename).addClass('mouseOver');
...@@ -39,6 +55,7 @@ function createVersionsDropdown(filename, files) { ...@@ -39,6 +55,7 @@ function createVersionsDropdown(filename, files) {
} else { } else {
$(html).appendTo($('thead .share')); $(html).appendTo($('thead .share'));
} }
// $.getJSON(OC.linkTo('files_sharing', 'ajax/userautocomplete.php'), function(users) { // $.getJSON(OC.linkTo('files_sharing', 'ajax/userautocomplete.php'), function(users) {
// if (users) { // if (users) {
// $.each(users, function(index, row) { // $.each(users, function(index, row) {
...@@ -47,19 +64,35 @@ function createVersionsDropdown(filename, files) { ...@@ -47,19 +64,35 @@ function createVersionsDropdown(filename, files) {
// $('#share_with').trigger('liszt:updated'); // $('#share_with').trigger('liszt:updated');
// } // }
// }); // });
// $.getJSON(OC.linkTo('files_sharing', 'ajax/getitem.php'), { source: files }, function(users) { $.getJSON(OC.linkTo('files_versions', 'ajax/getVersions.php'), { source: files }, function(versions) {
// if (users) { if (versions) {
// $.each(users, function(index, row) {
// if (row.uid_shared_with == 'public') { $.each( versions, function(index, row ) {
// showPublicLink(row.token, '/'+filename);
// } else if (isNaN(index)) { addVersion( row );
// addUser(row.uid_shared_with, row.permissions, index.substr(0, index.lastIndexOf('-'))); });
}
});
function addVersion( name ) {
var version = '<option>'+name+'</option>';
// } else { // } else {
// addUser(row.uid_shared_with, row.permissions, false); // 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>';
// } // }
// });
$(version).appendTo('#found_versions');
}
$('#dropdown').show('blind'); $('#dropdown').show('blind');
$('#share_with').chosen(); $('#share_with').chosen();
......
...@@ -11,7 +11,11 @@ ...@@ -11,7 +11,11 @@
echo('<strong>Versions of '.$_['path']).'</strong><br>'; echo('<strong>Versions of '.$_['path']).'</strong><br>';
echo('<p><em>You can click on the revert button to revert to the specific verson.</em></p><br />'); echo('<p><em>You can click on the revert button to revert to the specific verson.</em></p><br />');
foreach ( $_['versions'] as $v ){ foreach ( $_['versions'] as $v ){
echo(' '.OC_Util::formatDate($v).' <a href="history.php?path='.urlencode($_['path']).'&revert='.$v.'" class="button">Revert</a><br /><br />');
echo ' ';
echo OC_Util::formatDate( $v );
echo ' <a href="history.php?path='.urlencode( $_['path'] ).'&revert='. $v .'" class="button">Revert</a><br /><br />';
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment