mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +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'];
|
$fieldName = $this->urlParams['ID'];
|
||||||
$fieldVal = $_REQUEST[$fieldName];
|
$fieldVal = $_REQUEST[$fieldName];
|
||||||
$result = '';
|
$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
|
// 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;
|
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,
|
// 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.
|
// he's not allowed to add it to a group either: Don't include it in the suggestions.
|
||||||
if(!$match->canView() || !$match->canEdit()) continue;
|
if(!$match->canView() || !$match->canEdit()) continue;
|
||||||
|
|
||||||
$data = $match->FirstName;
|
$data = array();
|
||||||
$data .= ",$match->Surname";
|
foreach($match->summaryFields() as $k => $v) {
|
||||||
$data .= ",$match->Email";
|
$data[$k] = $match->$k;
|
||||||
$result .= "<li>" . $match->$fieldName . "<span class=\"informal\">($match->FirstName $match->Surname, $match->Email)</span><span class=\"informal data\">$data</span></li>";
|
}
|
||||||
|
$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>";
|
$result .= "</ul>";
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -77,18 +77,10 @@ AjaxMemberLookup = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
afterAutocomplete : function(field, selectedItem) {
|
afterAutocomplete : function(field, selectedItem) {
|
||||||
var data = selectedItem.getElementsByTagName('span')[1].innerHTML;
|
var items = jQuery(selectedItem).data('fields'), form = jQuery(selectedItem).parents('form:first');
|
||||||
var items = data.split(",");
|
for(name in items) {
|
||||||
form = Element.ancestorOfType(field, 'form');
|
jQuery(form).find('input[name='+name+']').val(items[name]);
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user