From: Zach Copley Date: Wed, 16 Mar 2011 01:45:08 +0000 (-0700) Subject: Extended profile - autocomplete for manager X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=95d03e74e940ef8f50e26d8e7a3a4b68509dd9c2;p=quix0rs-gnu-social.git Extended profile - autocomplete for manager --- diff --git a/plugins/ExtendedProfile/ExtendedProfilePlugin.php b/plugins/ExtendedProfile/ExtendedProfilePlugin.php index 933b43cad7..d1572ce9fd 100644 --- a/plugins/ExtendedProfile/ExtendedProfilePlugin.php +++ b/plugins/ExtendedProfile/ExtendedProfilePlugin.php @@ -54,6 +54,7 @@ class ExtendedProfilePlugin extends Plugin function onAutoload($cls) { $lower = strtolower($cls); + switch ($lower) { case 'extendedprofile': @@ -62,6 +63,9 @@ class ExtendedProfilePlugin extends Plugin case 'profiledetailsettingsaction': require_once dirname(__FILE__) . '/' . $lower . '.php'; return false; + case 'userautocompleteaction': + require_once dirname(__FILE__) . '/action/' . mb_substr($lower, 0, -6) . '.php'; + return false; case 'profile_detail': require_once dirname(__FILE__) . '/' . ucfirst($lower) . '.php'; return false; @@ -81,11 +85,19 @@ class ExtendedProfilePlugin extends Plugin */ function onStartInitializeRouter($m) { - $m->connect(':nickname/detail', - array('action' => 'profiledetail'), - array('nickname' => Nickname::DISPLAY_FMT)); - $m->connect('settings/profile/detail', - array('action' => 'profiledetailsettings')); + $m->connect( + ':nickname/detail', + array('action' => 'profiledetail'), + array('nickname' => Nickname::DISPLAY_FMT) + ); + $m->connect( + '/settings/profile/finduser', + array('action' => 'Userautocomplete') + ); + $m->connect( + 'settings/profile/detail', + array('action' => 'profiledetailsettings') + ); return true; } diff --git a/plugins/ExtendedProfile/action/userautocomplete.php b/plugins/ExtendedProfile/action/userautocomplete.php new file mode 100644 index 0000000000..d4857429e0 --- /dev/null +++ b/plugins/ExtendedProfile/action/userautocomplete.php @@ -0,0 +1,113 @@ +. + * + * @category Search + * @package StatusNet + * @author Zach Copley + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + + +class UserautocompleteAction extends Action +{ + var $query; + + /** + * Initialization. + * + * @param array $args Web and URL arguments + * + * @return boolean true if nothing goes wrong + */ + function prepare($args) + { + parent::prepare($args); + $this->query = $this->trimmed('term'); + return true; + } + + /** + * Handle a request + * + * @param array $args Arguments from $_REQUEST + * + * @return void + */ + function handle($args) + { + parent::handle($args); + $this->showResults(); + } + + /** + * Search for users matching the query and spit the results out + * as a quick-n-dirty JSON document + * + * @return void + */ + function showResults() + { + $people = array(); + + $profile = new Profile(); + + $search_engine = $profile->getSearchEngine('profile'); + $search_engine->set_sort_mode('nickname_desc'); + $search_engine->limit(0, 10); + $search_engine->query(strtolower($this->query . '*')); + + $cnt = $profile->find(); + + if ($cnt > 0) { + + $sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id ' + . ' AND LEFT(LOWER(profile.nickname), ' + . strlen($this->query) + . ') = \'%s\' ' + . ' LIMIT 0, 10'; + + $profile->query(sprintf($sql, $this->query)); + } + + while ($profile->fetch()) { + $people[] = $profile->nickname; + } + + header('Content-Type: application/json; charset=utf-8'); + print json_encode($people); + } + + /** + * Do we need to write to the database? + * + * @return boolean true + */ + function isReadOnly($args) + { + return true; + } +} diff --git a/plugins/ExtendedProfile/extendedprofilewidget.php b/plugins/ExtendedProfile/extendedprofilewidget.php index fc3d7ca51d..dec0512be4 100644 --- a/plugins/ExtendedProfile/extendedprofilewidget.php +++ b/plugins/ExtendedProfile/extendedprofilewidget.php @@ -466,6 +466,9 @@ class ExtendedProfileWidget extends Form case 'date': $this->out->text($this->ext->getTextValue($name)); break; + case 'person': + $this->out->text($this->ext->getTextValue($name)); + break; case 'tags': $this->out->text($this->ext->getTags()); break; @@ -512,6 +515,9 @@ class ExtendedProfileWidget extends Form case 'date': $out->input($id, null, $this->ext->getTextValue($name)); break; + case 'person': + $out->input($id, null, $this->ext->getTextValue($name)); + break; case 'textarea': $out->textarea($id, null, $this->ext->getTextValue($name)); break; diff --git a/plugins/ExtendedProfile/js/profiledetail.js b/plugins/ExtendedProfile/js/profiledetail.js index 2821bed275..7510323a43 100644 --- a/plugins/ExtendedProfile/js/profiledetail.js +++ b/plugins/ExtendedProfile/js/profiledetail.js @@ -89,6 +89,11 @@ var init = function() { reorder('experience-item'); reorder('education-item'); reorder('im-item'); + + $("input#extprofile-manager").autocomplete({ + source: 'finduser', + minLength: 2 }); + } $(document).ready( diff --git a/plugins/ExtendedProfile/profiledetailsettingsaction.php b/plugins/ExtendedProfile/profiledetailsettingsaction.php index d3b653bad2..b0590f7316 100644 --- a/plugins/ExtendedProfile/profiledetailsettingsaction.php +++ b/plugins/ExtendedProfile/profiledetailsettingsaction.php @@ -44,12 +44,14 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction function showStylesheets() { parent::showStylesheets(); $this->cssLink('plugins/ExtendedProfile/css/profiledetail.css'); + $this->cssLink('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css'); return true; } function showScripts() { parent::showScripts(); $this->script('plugins/ExtendedProfile/js/profiledetail.js'); + $this->script('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js'); return true; } @@ -99,7 +101,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction $profile = $user->getProfile(); - $simpleFieldNames = array('title', 'spouse', 'kids'); + $simpleFieldNames = array('title', 'spouse', 'kids', 'manager'); $dateFieldNames = array('birthday'); foreach ($simpleFieldNames as $name) {