BUGFIX Respecting Member::summaryFields() in SecurityAdmin->autocomplete instead of hardcoding Firstname,Surname,Email. This also allows to include Member::$unique_identifier_field in the autocomplete results

This commit is contained in:
Ingo Schommer 2011-03-08 21:01:51 +13:00
parent a3bd51e388
commit 4374bd815a
2 changed files with 16 additions and 17 deletions

View File

@ -275,6 +275,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
$fieldName = $this->urlParams['ID'];
$fieldVal = $_REQUEST[$fieldName];
$result = '';
$uidField = Member::get_unique_identifier_field();
// Make sure we only autocomplete on keys that actually exist, and that we don't autocomplete on password
if(!singleton($this->stat('subitem_class'))->hasDatabaseField($fieldName) || $fieldName == 'Password') return;
@ -287,10 +288,16 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
// he's not allowed to add it to a group either: Don't include it in the suggestions.
if(!$match->canView() || !$match->canEdit()) continue;
$data = $match->FirstName;
$data .= ",$match->Surname";
$data .= ",$match->Email";
$result .= "<li>" . $match->$fieldName . "<span class=\"informal\">($match->FirstName $match->Surname, $match->Email)</span><span class=\"informal data\">$data</span></li>";
$data = array();
foreach($match->summaryFields() as $k => $v) {
$data[$k] = $match->$k;
}
$result .= sprintf(
'<li data-fields="%s">%s <span class="informal">(%s)</span></li>',
Convert::raw2att(Convert::raw2json($data)),
$match->$fieldName,
implode(',', array_values($data))
);
}
$result .= "</ul>";
return $result;

View File

@ -77,18 +77,10 @@ AjaxMemberLookup = {
}
},
afterAutocomplete : function(field, selectedItem) {
var data = selectedItem.getElementsByTagName('span')[1].innerHTML;
var items = data.split(",");
form = Element.ancestorOfType(field, 'form');
// TODO more flexible column-detection
form.elements.FirstName.value = items[0];
form.elements.Surname.value = items[1];
form.elements.Email.value = items[2];
if(items[3] && form.elements.Password)
form.elements.Password.value = items[3];
//var fieldSet = field.parentNode.parentNode.getElementsByTagName('input');
//ajaxSubmitFieldSet('admin/security/savemember?MemberBaseGroupID='.$('MemberBaseGroupID'), fieldSet);
var items = jQuery(selectedItem).data('fields'), form = jQuery(selectedItem).parents('form:first');
for(name in items) {
jQuery(form).find('input[name='+name+']').val(items[name]);
}
}
}