From d4c0ac779034a47d4fc8a56e0a96a7d84170e03c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 14 Nov 2013 09:38:55 +0100 Subject: [PATCH 1/3] introduce auto completion on share email - integrated with the contactsmanager api --- core/ajax/share.php | 24 ++++++++++++++++++++++++ core/js/share.js | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/core/ajax/share.php b/core/ajax/share.php index be02c05635..6bac2867c4 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -261,6 +261,30 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo OC_JSON::success(array('data' => array('reshare' => $reshare, 'shares' => $shares))); } break; + case 'getShareWithEmail': + $result = array(); + if (isset($_GET['search'])) { + $cm = OC::$server->getContactsManager(); + if (!is_null($cm) && $cm->isEnabled()) { + $contacts = $cm->search($_GET['search'], array('FN', 'EMAIL')); + foreach ($contacts as $contact) { + $emails = $contact['EMAIL']; + if (!is_array($emails)) { + $emails = array($emails); + } + + foreach($emails as $email) { + $result[] = array( + 'id' => $contact['ID'], + 'email' => $email, + 'displayname' => $contact['FN'], + ); + } + } + } + } + OC_JSON::success(array('data' => $result)); + break; case 'getShareWith': if (isset($_GET['search'])) { $sharePolicy = OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global'); diff --git a/core/js/share.js b/core/js/share.js index 411f0d23c3..44c58a3f94 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -314,6 +314,26 @@ OC.Share={ .append( insert ) .appendTo( ul ); }; + $('#email').autocomplete({ + minLength: 1, + source: function (search, response) { + $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWithEmail', search: search.term }, function(result) { + if (result.status == 'success' && result.data.length > 0) { + response(result.data); + } + }); + }, + select: function( event, item ) { + $('#email').val(item.item.email); + return false; + } + }) + .data("ui-autocomplete")._renderItem = function( ul, item ) { + return $( "
  • " ) + .append( "" + item.displayname + "
    " + item.email + "
    " ) + .appendTo( ul ); + }; + } else { html += ''; html += ''; From aa5bba2bcce010ecbbbf4df0a63570a66986d846 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Tue, 25 Mar 2014 14:22:39 +0100 Subject: [PATCH 2/3] 'ID' => 'id' and check existence of EMAIL --- core/ajax/share.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 6bac2867c4..588781556f 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -268,6 +268,10 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo if (!is_null($cm) && $cm->isEnabled()) { $contacts = $cm->search($_GET['search'], array('FN', 'EMAIL')); foreach ($contacts as $contact) { + if (!isset($emails = $contact['EMAIL']) { + continue; + } + $emails = $contact['EMAIL']; if (!is_array($emails)) { $emails = array($emails); @@ -275,7 +279,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo foreach($emails as $email) { $result[] = array( - 'id' => $contact['ID'], + 'id' => $contact['id'], 'email' => $email, 'displayname' => $contact['FN'], ); From 0b4d87961926d69e5f95b2a6477edb804d726b78 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Tue, 25 Mar 2014 15:38:11 +0100 Subject: [PATCH 3/3] Fix copy/paste error :P --- core/ajax/share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 588781556f..747cb3c6db 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -268,7 +268,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo if (!is_null($cm) && $cm->isEnabled()) { $contacts = $cm->search($_GET['search'], array('FN', 'EMAIL')); foreach ($contacts as $contact) { - if (!isset($emails = $contact['EMAIL']) { + if (!isset($contact['EMAIL'])) { continue; }