mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
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:
parent
a3bd51e388
commit
4374bd815a
@ -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;
|
||||
@ -286,11 +287,17 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
||||
// If the current user doesnt have permissions on the target user,
|
||||
// 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;
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user