summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2012-07-30 15:30:21 -0400
committerMichael Gapczynski <mtgap@owncloud.com>2012-07-30 15:30:21 -0400
commited71343df8a3d35c2a0fe7d6c91778278f8d7dd1 (patch)
tree6826dee6a69b67718f8cf811a0211cd49574ba55 /core
parent98c020d954f6a8dac93c5e93309807c7a66456eb (diff)
downloadnextcloud-server-ed71343df8a3d35c2a0fe7d6c91778278f8d7dd1.tar.gz
nextcloud-server-ed71343df8a3d35c2a0fe7d6c91778278f8d7dd1.zip
Autocomplete for share with search in sharing dropdown
Diffstat (limited to 'core')
-rw-r--r--core/ajax/share.php23
-rw-r--r--core/js/share.js37
2 files changed, 44 insertions, 16 deletions
diff --git a/core/ajax/share.php b/core/ajax/share.php
index 4c5ef310b7f..41c9e80fd75 100644
--- a/core/ajax/share.php
+++ b/core/ajax/share.php
@@ -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;
}
}
diff --git a/core/js/share.js b/core/js/share.js
index 8ab92c2a85d..64fcb77c0b0 100644
--- a/core/js/share.js
+++ b/core/js/share.js
@@ -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();