New implementation of share dialog

This commit is contained in:
Michael Gapczynski 2011-08-02 12:19:49 -04:00
parent ddfc9fc001
commit 0d79560e94
3 changed files with 44 additions and 70 deletions

View File

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

View File

@ -18,88 +18,42 @@ $(document).ready(function() {
} }
createShareDialog(filenames, files); createShareDialog(filenames, files);
}); });
$("input[name=share_type]").live('change', function() { $('#uid_shared_with').live('keyup', function() {
$('#private').toggle();
$('#public').toggle();
});
$('.uid_shared_with').live('keyup', function() {
$(this).autocomplete({ $(this).autocomplete({
source: '../apps/files_sharing/ajax/userautocomplete.php', source: '../apps/files_sharing/ajax/userautocomplete.php'
minLength: 1
}); });
}); });
$('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 = "<br />";
html += "<label>Share with <input placeholder='User or Group' class='uid_shared_with' /></label>";
html += "<button class='add-uid_shared_with fancybutton'>+</button>";
$(html).insertAfter('.add-uid_shared_with');
$(this).html('&nbsp-&nbsp&nbsp');
$(this).removeClass('add-uid_shared_with fancybutton');
$(this).addClass('remove-uid_shared_with fancybutton');
});
$('button.remove-uid_shared_with').live('click', function(event) { $('button.remove-uid_shared_with').live('click', function(event) {
event.preventDefault(); event.preventDefault();
alert("remove"); alert("remove");
// TODO Remove corresponding row // TODO Remove corresponding row
}); });
$('#expire').datepicker({
dateFormat:'MM d, yy',
altField: '#expire_time',
altFormat: 'yy-mm-dd'
});
}); });
function createShareDialog(filenames, files) { function createShareDialog(filenames, files) {
var html = "<div id='dialog' align='center'>"; var html = "<div id='dialog' style='position: absolute'>";
html += "<label><input type='radio' name='share_type' value='private' checked='checked' /> Private</label>";
html += "<label><input type='radio' name='share_type' value='public' /> Public</label>";
html += "<br />";
html += "<div id='private'>"; html += "<div id='private'>";
html += "<label>Share with <input placeholder='User or Group' class='uid_shared_with' /></label>"; html += "<label>Share with <input placeholder='User or Group' id='uid_shared_with' /></label>";
html += "<button id='hey' class='add-uid_shared_with fancybutton'>+</button>"; html += "<label><input type='checkbox' name='permissions' value='1' /> allow editing</label><br />";
html += "<br />"; html += "<br />";
html += "<div id='permissions'style='text-align: left'>"; html += "<div id='shared_list'></div>";
html += "Permissions" $.getJSON(OC.linkTo('files_sharing','ajax/getitem.php'), { source: files }, function(users) {
html += "<br />"; var list = "";
html += "<label><input type='checkbox' name='share_permissions' value='1' /> Edit</label><br />"; $.each(users, function(index, row) {
html += "<label><input type='checkbox' name='share_permissions' value='2' /> Delete</label><br />"; list += row.uid_shared_with;
html += "</div>"; list += " <label><input type='checkbox' name='share_private_permissions' value='1' /> allow editing</label><br />";
html += "</div>"; if (row.permissions > 0) {
html += "<div id='public' style='display: none'>"; $('share_private_permissions').prop('checked', true);
html += "TODO: Construct a public link";
html += "<input placeholder='Expires' id='expire' />";
html += "</div>";
html += "<div>";
$(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');
}
});
}
} }
} });
$(list).appendTo('#shared_list');
}); });
html += "</div>";
html += "<div id='public'>";
html += "<label><input type='checkbox' name='public_link' value='1' /> make public</label>";
html += "<label><input type='checkbox' name='public_link_write' value='1' /> writeable</label>";
html += "<div id='link'>";
html += "</div>";
html += "</div>";
$(html).appendTo($('tr[data-file="'+filenames+'"] '));
} }

View File

@ -118,6 +118,16 @@ class OC_Share {
return $query->execute(array($target, OC_User::getUser()))->fetchAll(); 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 * Get all items the current user is sharing
* @return An array with all items the user is sharing * @return An array with all items the user is sharing