Full support for making and deleting public links from share dropdown

This commit is contained in:
Michael Gapczynski 2011-08-05 11:18:35 -04:00
parent 8f01abf054
commit 843f8aca7c
4 changed files with 28 additions and 16 deletions

View File

@ -0,0 +1,8 @@
<?php
$RUNTIME_NOAPPS = true;
require_once('../../../lib/base.php');
require_once('../lib_public.php');
$path = $_GET['path'];
echo json_encode(OC_PublicLink::getLink($path));

View File

@ -53,7 +53,13 @@ class OC_PublicLink{
public function getToken(){ public function getToken(){
return $this->token; return $this->token;
} }
public static function getLink($path) {
$query=OC_DB::prepare("SELECT token FROM *PREFIX*publiclink WHERE user=? AND path=? LIMIT 1");
$result=$query->execute(array(OC_User::getUser(),$path))->fetchAll();
return $result[0]['token'];
}
/** /**
* gets all public links * gets all public links
* @return array * @return array

View File

@ -5,6 +5,5 @@ require_once('../../../lib/base.php');
require_once('../lib_share.php'); require_once('../lib_share.php');
$source = "/".OC_User::getUser()."/files".$_GET['source']; $source = "/".OC_User::getUser()."/files".$_GET['source'];
error_log($source);
echo json_encode(OC_Share::getMySharedItem($source)); echo json_encode(OC_Share::getMySharedItem($source));
?> ?>

View File

@ -37,7 +37,8 @@ $(document).ready(function() {
$('.permissions').live('change', function() { $('.permissions').live('change', function() {
// TODO Modify item ajax call // TODO Modify item ajax call
}); });
$('.unshare').live('click', function() { $('.unshare').live('click', function(event) {
event.preventDefault();
var source = $('#dropdown').data('file'); var source = $('#dropdown').data('file');
var uid_shared_with = $(this).data('uid_shared_with'); var uid_shared_with = $(this).data('uid_shared_with');
var data='source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with); var data='source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with);
@ -63,22 +64,22 @@ $(document).ready(function() {
data: data, data: data,
success: function(token) { success: function(token) {
if (token) { if (token) {
var link = OC.linkTo('files_publiclink','get.php')+'?token='+token; $('#link').data('token', token);
$('#link').val('http://'+location.host+OC.linkTo('files_publiclink','get.php')+'?token='+token);
$('#link').show('blind'); $('#link').show('blind');
$('#link').val(link);
} }
} }
}); });
} else { } else {
var token = $(this).attr('data-token'); var token = $('#link').data('token');
var data = "token="+token; var data = 'token='+token;
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: OC.linkTo('files_publiclink','ajax/deletelink.php'), url: OC.linkTo('files_publiclink','ajax/deletelink.php'),
cache: false, cache: false,
data: data, data: data,
success: function(){ success: function(){
$('#token').hide('blind'); $('#link').hide('blind');
} }
}); });
} }
@ -104,10 +105,10 @@ function createShareDropdown(filenames, files) {
if (users) { if (users) {
var list = "<ul>"; var list = "<ul>";
$.each(users, function(index, row) { $.each(users, function(index, row) {
list += "<li>"; list += "<li>";
list += row.uid_shared_with; list += row.uid_shared_with;
list += "<input type='checkbox' name='permissions' data-uid_shared_with='"+row.uid_shared_with+"' /><label>can edit</label>"; list += "<input type='checkbox' name='permissions' data-uid_shared_with='"+row.uid_shared_with+"' /><label>can edit</label>";
list += "<a href='#' title='Unshare' class='unshare' data-uid_shared_with='"+row.uid_shared_with+"'><img src='"+OC.imagePath('core','actions/delete')+"'/></a>"; list += "<a href='' title='Unshare' class='unshare' data-uid_shared_with='"+row.uid_shared_with+"'><img src='"+OC.imagePath('core','actions/delete')+"'/></a>";
list += "</li>"; list += "</li>";
if (row.permissions > 0) { if (row.permissions > 0) {
$('share_private_permissions').prop('checked', true); $('share_private_permissions').prop('checked', true);
@ -117,16 +118,14 @@ function createShareDropdown(filenames, files) {
$(list).appendTo('#shared_list'); $(list).appendTo('#shared_list');
} }
}); });
// TODO Create gettoken.php $.getJSON(OC.linkTo('files_publiclink','ajax/getlink.php'), { path: files }, function(token) {
//$.getJSON(OC.linkTo('files_publiclink','ajax/gettoken.php'), { path: files }, function(token) {
var token;
if (token) { if (token) {
var link = OC.linkTo('files_publiclink','get.php')+'?token='+token;
$('#makelink').attr('checked', true); $('#makelink').attr('checked', true);
$('#link').data('token', token);
$('#link').val('http://'+location.host+OC.linkTo('files_publiclink','get.php')+'?token='+token);
$('#link').show('blind'); $('#link').show('blind');
$('#link').val(link);
} }
//}); });
$('#dropdown').show('blind'); $('#dropdown').show('blind');
$('#dropdown').click(function(event) { $('#dropdown').click(function(event) {
event.stopPropagation(); event.stopPropagation();