Autocomplete for share with search in sharing dropdown

This commit is contained in:
Michael Gapczynski 2012-07-30 15:30:21 -04:00
parent 98c020d954
commit ed71343df8
2 changed files with 44 additions and 16 deletions

View file

@ -49,21 +49,34 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['item']
}
break;
}
} else if (isset($_GET['fetch']) && isset($_GET['itemType'])) {
} else if (isset($_GET['fetch'])) {
switch ($_GET['fetch']) {
case 'getItemsSharedStatuses':
$return = OCP\Share::getItemsShared($_GET['itemType'], OCP\Share::FORMAT_STATUSES);
($return) ? OC_JSON::success(array('data' => $return)) : OC_JSON::error();
if (isset($_GET['itemType'])) {
$return = OCP\Share::getItemsShared($_GET['itemType'], OCP\Share::FORMAT_STATUSES);
($return) ? OC_JSON::success(array('data' => $return)) : OC_JSON::error();
}
break;
case 'getItem':
// TODO Check if the item was shared to the current user
if (isset($_GET['item'])) {
if (isset($_GET['itemType']) && isset($_GET['item'])) {
$return = OCP\Share::getItemShared($_GET['itemType'], $_GET['item']);
($return) ? OC_JSON::success(array('data' => $return)) : OC_JSON::error();
}
break;
case 'getShareWith':
// TODO Autocomplete for all users, groups, etc.
if (isset($_GET['search'])) {
$shareWith = array();
$users = OC_User::getUsers();
foreach ($users as $user) {
$shareWith[] = array('label' => $user, 'value' => array('shareType' => OCP\Share::SHARE_TYPE_USER, 'shareWith' => $user));
}
$groups = OC_Group::getGroups();
foreach ($groups as $group) {
$shareWith[] = array('label' => $group.' (group)', 'value' => array('shareType' => OCP\Share::SHARE_TYPE_GROUP, 'shareWith' => $group));
}
OC_JSON::success(array('data' => $shareWith));
}
break;
}
}

View file

@ -94,6 +94,32 @@ OC.Share={
});
}
$('#dropdown').show('blind');
$('#shareWith').autocomplete({minLength: 2, source: function(search, response) {
// if (cache[search.term]) {
// response(cache[search.term]);
// } else {
$.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term }, function(result) {
if (result.status == 'success') {
response(result.data);
} else {
// Suggest sharing via email
response();
}
});
// }
}, select: function(event, selected) {
var shareType = selected.item.value.shareType;
var shareWith = selected.item.value.shareWith;
$(this).val(shareWith);
// Default permissions are Read and Share
var permissions = OC.Share.PERMISSION_READ | OC.Share.PERMISSION_SHARE;
OC.Share.share($('#dropdown').data('item-type'), $('#dropdown').data('item'), shareType, shareWith, permissions, function() {
OC.Share.addShareWith(shareType, shareWith, permissions, possiblePermissions);
$('#shareWith').val('');
});
return false;
}
});
},
hideDropDown:function(callback) {
$('#dropdown').hide('blind', function() {
@ -273,17 +299,6 @@ $(document).ready(function() {
$('a.unshare', this).hide();
}
});
$('#shareWith').live('change', function() {
var shareType = $(li).data('share-type');
var shareWith = $(this).val();
// Default permissions are Read and Share
var permissions = OC.Share.PERMISSION_READ | OC.Share.PERMISSION_SHARE;
OC.Share.share($('#dropdown').data('item-type'), $('#dropdown').data('item'), shareType, shareWith, permissions, function() {
OC.Share.addShareWith(shareType, shareWith, permissions);
$('#shareWith').val('');
});
});
$('.showCruds').live('click', function() {
$(this).parent().find('.cruds').toggle();