diff --git a/apps/files_sharing/ajax/getitem.php b/apps/files_sharing/ajax/getitem.php new file mode 100644 index 0000000000..a074510363 --- /dev/null +++ b/apps/files_sharing/ajax/getitem.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 6ca018fca0..6b5b47f90f 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -18,88 +18,42 @@ $(document).ready(function() { } createShareDialog(filenames, files); }); - $("input[name=share_type]").live('change', function() { - $('#private').toggle(); - $('#public').toggle(); - }); - $('.uid_shared_with').live('keyup', function() { + $('#uid_shared_with').live('keyup', function() { $(this).autocomplete({ - source: '../apps/files_sharing/ajax/userautocomplete.php', - minLength: 1 + source: '../apps/files_sharing/ajax/userautocomplete.php' }); }); - $('button.add-uid_shared_with').live('click', function(event) { - event.preventDefault(); - // TODO Make sure previous textbox has a valid user or group name - var html = "
"; - html += ""; - html += ""; - $(html).insertAfter('.add-uid_shared_with'); - $(this).html(' -  '); - $(this).removeClass('add-uid_shared_with fancybutton'); - $(this).addClass('remove-uid_shared_with fancybutton'); - }); $('button.remove-uid_shared_with').live('click', function(event) { event.preventDefault(); alert("remove"); // TODO Remove corresponding row }); - $('#expire').datepicker({ - dateFormat:'MM d, yy', - altField: '#expire_time', - altFormat: 'yy-mm-dd' - }); }); function createShareDialog(filenames, files) { - var html = "
"; - html += ""; - html += ""; - html += "
"; + var html = "
"; html += "
"; - html += ""; - html += ""; + html += ""; + html += "
"; html += "
"; - html += "
"; - html += "Permissions" - html += "
"; - html += "
"; - html += "
"; - html += "
"; - html += "
"; - html += ""; - html += "
"; - $(html).dialog({ - title: 'Share ' + filenames, - modal: true, - close: function(event, ui) { - $(this).remove(); - }, - buttons: { - 'Share': function() { - if ($('input[name=share_type]:checked').val() == 'public') { - // TODO Construct public link - } else { - // TODO Check all inputs are valid - var uid_shared_with = $('.uid_shared_with').val(); - var permissions = 0; - $(this).find('input:checkbox:checked').each(function() { - permissions += parseInt($(this).val()); - }); - $.ajax({ - type: 'POST', - url: '../apps/files_sharing/ajax/share.php', - cache: false, - data: '&sources='+encodeURIComponent(files)+'&uid_shared_with[]='+uid_shared_with+'&permissions='+permissions, - success: function() { - $('#dialog').dialog('close'); - } - }); - } + html += "
"; + $.getJSON(OC.linkTo('files_sharing','ajax/getitem.php'), { source: files }, function(users) { + var list = ""; + $.each(users, function(index, row) { + list += row.uid_shared_with; + list += "
"; + if (row.permissions > 0) { + $('share_private_permissions').prop('checked', true); } - } + }); + $(list).appendTo('#shared_list'); }); + html += "
"; + html += "
"; + html += ""; + html += ""; + html += ""; + html += "
"; + $(html).appendTo($('tr[data-file="'+filenames+'"] ')); } \ No newline at end of file diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index f8b00aa905..159c45e11e 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -117,7 +117,17 @@ class OC_Share { $query = OC_DB::prepare("SELECT uid_owner, source, permissions FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); return $query->execute(array($target, OC_User::getUser()))->fetchAll(); } - + + /** + * Get the item with the specified source location + * @param $source The source location of the item + * @return An array with the users and permissions the item is shared with + */ + public static function getMySharedItem($source) { + $source = self::cleanPath($source); + $query = OC_DB::prepare("SELECT uid_shared_with, permissions FROM *PREFIX*sharing WHERE source = ? AND uid_owner = ?"); + return $query->execute(array($source, OC_User::getUser()))->fetchAll(); + } /** * Get all items the current user is sharing * @return An array with all items the user is sharing