Extended profile - autocomplete for manager

This commit is contained in:
Zach Copley 2011-03-15 18:45:08 -07:00
parent e4eb6719a5
commit 95d03e74e9
5 changed files with 144 additions and 6 deletions

View File

@ -54,6 +54,7 @@ class ExtendedProfilePlugin extends Plugin
function onAutoload($cls) function onAutoload($cls)
{ {
$lower = strtolower($cls); $lower = strtolower($cls);
switch ($lower) switch ($lower)
{ {
case 'extendedprofile': case 'extendedprofile':
@ -62,6 +63,9 @@ class ExtendedProfilePlugin extends Plugin
case 'profiledetailsettingsaction': case 'profiledetailsettingsaction':
require_once dirname(__FILE__) . '/' . $lower . '.php'; require_once dirname(__FILE__) . '/' . $lower . '.php';
return false; return false;
case 'userautocompleteaction':
require_once dirname(__FILE__) . '/action/' . mb_substr($lower, 0, -6) . '.php';
return false;
case 'profile_detail': case 'profile_detail':
require_once dirname(__FILE__) . '/' . ucfirst($lower) . '.php'; require_once dirname(__FILE__) . '/' . ucfirst($lower) . '.php';
return false; return false;
@ -81,11 +85,19 @@ class ExtendedProfilePlugin extends Plugin
*/ */
function onStartInitializeRouter($m) function onStartInitializeRouter($m)
{ {
$m->connect(':nickname/detail', $m->connect(
':nickname/detail',
array('action' => 'profiledetail'), array('action' => 'profiledetail'),
array('nickname' => Nickname::DISPLAY_FMT)); array('nickname' => Nickname::DISPLAY_FMT)
$m->connect('settings/profile/detail', );
array('action' => 'profiledetailsettings')); $m->connect(
'/settings/profile/finduser',
array('action' => 'Userautocomplete')
);
$m->connect(
'settings/profile/detail',
array('action' => 'profiledetailsettings')
);
return true; return true;
} }

View File

@ -0,0 +1,113 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Action for showing Twitter-like JSON search results
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Search
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @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;
}
}

View File

@ -466,6 +466,9 @@ class ExtendedProfileWidget extends Form
case 'date': case 'date':
$this->out->text($this->ext->getTextValue($name)); $this->out->text($this->ext->getTextValue($name));
break; break;
case 'person':
$this->out->text($this->ext->getTextValue($name));
break;
case 'tags': case 'tags':
$this->out->text($this->ext->getTags()); $this->out->text($this->ext->getTags());
break; break;
@ -512,6 +515,9 @@ class ExtendedProfileWidget extends Form
case 'date': case 'date':
$out->input($id, null, $this->ext->getTextValue($name)); $out->input($id, null, $this->ext->getTextValue($name));
break; break;
case 'person':
$out->input($id, null, $this->ext->getTextValue($name));
break;
case 'textarea': case 'textarea':
$out->textarea($id, null, $this->ext->getTextValue($name)); $out->textarea($id, null, $this->ext->getTextValue($name));
break; break;

View File

@ -89,6 +89,11 @@ var init = function() {
reorder('experience-item'); reorder('experience-item');
reorder('education-item'); reorder('education-item');
reorder('im-item'); reorder('im-item');
$("input#extprofile-manager").autocomplete({
source: 'finduser',
minLength: 2 });
} }
$(document).ready( $(document).ready(

View File

@ -44,12 +44,14 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
function showStylesheets() { function showStylesheets() {
parent::showStylesheets(); parent::showStylesheets();
$this->cssLink('plugins/ExtendedProfile/css/profiledetail.css'); $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; return true;
} }
function showScripts() { function showScripts() {
parent::showScripts(); parent::showScripts();
$this->script('plugins/ExtendedProfile/js/profiledetail.js'); $this->script('plugins/ExtendedProfile/js/profiledetail.js');
$this->script('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js');
return true; return true;
} }
@ -99,7 +101,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
$profile = $user->getProfile(); $profile = $user->getProfile();
$simpleFieldNames = array('title', 'spouse', 'kids'); $simpleFieldNames = array('title', 'spouse', 'kids', 'manager');
$dateFieldNames = array('birthday'); $dateFieldNames = array('birthday');
foreach ($simpleFieldNames as $name) { foreach ($simpleFieldNames as $name) {