support filter for NIS net groups

This commit is contained in:
Roland Gruber 2015-05-31 08:03:00 +00:00
parent 0807a1b741
commit e0d291378e
3 changed files with 55 additions and 1 deletions

View File

@ -418,6 +418,8 @@ class htmlInputField extends htmlElement {
protected $fieldMaxLength = 255;
/** on keypress event */
protected $onKeyPress = null;
/** on keyupp event */
protected $onKeyUp = null;
/** password field */
protected $isPassword = false;
/** check password strength */
@ -535,11 +537,15 @@ class htmlInputField extends htmlElement {
if ($this->onKeyPress != null) {
$onKeyPress = ' onkeypress="' . $this->onKeyPress . '"';
}
$onKeyUp = '';
if ($this->onKeyUp != null) {
$onKeyUp = ' onkeyup="' . $this->onKeyUp . '"';
}
$title = '';
if (!empty($this->title)) {
$title = ' title="' . $this->title . '"';
}
echo '<input type="' . $inputType . '"' . $class . $name . $id . $value . $maxLength . $size . $fieldTabIndex . $onKeyPress . $title . $disabled . '>';
echo '<input type="' . $inputType . '"' . $class . $name . $id . $value . $maxLength . $size . $fieldTabIndex . $onKeyPress . $onKeyUp . $title . $disabled . '>';
// autocompletion
if ($this->autocomplete) {
echo "<script type=\"text/javascript\">\n";
@ -723,6 +729,15 @@ class htmlInputField extends htmlElement {
$this->onKeyPress = $onKeyPress;
}
/**
* Sets the JavaScript for the onKeyUp event.
*
* @param String $onKeyUp JavaScript code
*/
public function setOnKeyUp($onKeyUp) {
$this->onKeyUp = $onKeyUp;
}
/**
* Shows a calendar when the field is selected.
*

View File

@ -192,6 +192,15 @@ class nisNetGroupUser extends baseModule {
$addButton = new htmlButton('addGroup', 'add.png', true);
$addButton->setTitle(_('Add'));
$return->addElement($addButton, true);
$filterGroup = new htmlGroup();
$filterGroup->alignment = htmlElement::ALIGN_RIGHT;
$filterGroup->addElement(new htmlOutputText(_('Filter') . ' '));
$filter = new htmlInputField('group_filter');
$filter->setFieldSize('5em');
$filter->setOnKeyUp('filterSelect(\'group_filter\', \'group_add\', event);');
$filterGroup->addElement($filter);
$return->addElement($filterGroup, true);
}
return $return;
}

View File

@ -615,3 +615,33 @@ function updateModulePositions(id, oldPos, newPos) {
}
jQuery('#' + id).val(positions.join(','));
}
/**
* Filters a select box by the value of the filter input field.
*
* @param filterInput ID of input field for filter
* @param select ID of select box to filter
* @param event key event
*/
function filterSelect(filterInput, select, event) {
// if values were not yet saved, save them
if (!jQuery('#' + select).data('options')) {
var options = [];
jQuery('#' + select).find('option').each(function() {
options.push({value: $(this).val(), text: $(this).text()});
});
jQuery('#' + select).data('options', options);
}
// get matching values
var list = jQuery('#' + select).empty().scrollTop(0).data('options');
var search = jQuery.trim(jQuery('#' + filterInput).val());
var regex = new RegExp(search,'gi');
jQuery.each(list, function(i) {
var option = list[i];
if(option.text.match(regex) !== null) {
jQuery('#' + select).append(
jQuery('<option>').text(option.text).val(option.value)
);
}
});
}