From 4868aaf9ea3fbcba09252c84389f2abbe622d879 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 6 Dec 2010 16:55:16 -0800 Subject: [PATCH] Ticket #2924: include mini avatars in Autocomplete plugin drop-down list Ticket #2923: don't show "(null)" for some profiles with no full name set --- plugins/Autocomplete/Autocomplete.js | 8 +++++++- plugins/Autocomplete/autocomplete.php | 26 ++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/plugins/Autocomplete/Autocomplete.js b/plugins/Autocomplete/Autocomplete.js index f39c1a7a72..81d43dccde 100644 --- a/plugins/Autocomplete/Autocomplete.js +++ b/plugins/Autocomplete/Autocomplete.js @@ -12,7 +12,13 @@ $(document).ready(function(){ minChars: 1, formatItem: function(row, i, max){ row = eval("(" + row + ")"); - return fullName(row); + // the display:inline is because our INSANE stylesheets + // override the standard display of all img tags for no + // good reason. + var div = $('
') + .find('img').attr('src', row.avatar).end() + .find('span').text(fullName(row)).end() + return div.html(); }, formatMatch: function(row, i, max){ row = eval("(" + row + ")"); diff --git a/plugins/Autocomplete/autocomplete.php b/plugins/Autocomplete/autocomplete.php index be5b51a199..c4b30d264d 100644 --- a/plugins/Autocomplete/autocomplete.php +++ b/plugins/Autocomplete/autocomplete.php @@ -126,10 +126,32 @@ class AutocompleteAction extends Action $results = array(); foreach($this->users as $user){ $profile = $user->getProfile(); - $results[]=array('nickname' => $user->nickname, 'fullname'=> $profile->fullname, 'type'=>'user'); + $avatar = $profile->getAvatar(AVATAR_MINI_SIZE); + // sigh.... encapsulate this upstream! + if ($avatar) { + $avatar = $avatar->displayUrl(); + } else { + $avatar = Avatar::defaultImage(AVATAR_MINI_SIZE); + } + $results[] = array( + 'nickname' => $user->nickname, + 'fullname'=> $profile->fullname, + 'avatar' => $avatar, + 'type' => 'user' + ); } foreach($this->groups as $group){ - $results[]=array('nickname' => $group->nickname, 'fullname'=> $group->fullname, 'type'=>'group'); + // sigh.... encapsulate this upstream! + if ($group->mini_logo) { + $avatar = $group->mini_logo; + } else { + $avatar = User_group::defaultLogo(AVATAR_MINI_SIZE); + } + $results[] = array( + 'nickname' => $group->nickname, + 'fullname'=> $group->fullname, + 'avatar' => $avatar, + 'type' => 'group'); } foreach($results as $result) { print json_encode($result) . "\n"; -- 2.39.5