Commit d6e4c9ba authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(management) Add support for fixed filter elements

Useful for selection classes mainly, for instance PhoneNumberAttribute
 dialog will now only list phones with a non-empty phone number.
This will also be useful for samba.

issue #5965
Showing with 83 additions and 3 deletions
+83 -3
<fieldset><legend>{$NAME}</legend>
{foreach from=$INPUTS key="key" item="input"}
<label title="{$input.desc|escape}">
{if isset($input.icon)}
<img src="{$input.icon|escape}" alt=""/>
{/if}
{$input.name|escape}
</label>
{/foreach}
</fieldset>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2018-2019 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class FixedFilterElement extends FilterElement
{
protected $filter;
public function __construct (managementFilter $parent, string $filter)
{
parent::__construct($parent);
$this->filter = $filter;
}
public function render (): string
{
$inputs = [
[
'name' => $this->filter,
'desc' => $this->filter,
]
];
$smarty = get_smarty();
$smarty->assign('NAME', _('Fixed'));
$smarty->assign('INPUTS', $inputs);
return $smarty->fetch(get_template_path('management/filter-element-fixed.tpl'));
}
public function getFilters (string $type, array &$filters): bool
{
$filters[] = $this->filter;
return FALSE;
}
}
......@@ -30,6 +30,12 @@ class phoneSelect extends selectManagement
['LinkColumn', ['attributes' => 'nameAttr', 'label' => 'Name']],
['LinkColumn', ['attributes' => 'telephoneNumber', 'label' => 'Number']],
];
protected function setUpFilter ()
{
parent::setUpFilter();
$this->filter->addElement(new FixedFilterElement($this->filter, '(telephoneNumber=*)'));
}
}
/*!
......@@ -141,12 +147,24 @@ class PhoneNumberButtonAttribute extends PhoneNumberAttribute
}
}
function handleDialogResult ($dn, array $attrs)
function handleDialogResult ($dn, $entry)
{
if (isset($attrs['telephoneNumber'][0])) {
$this->setValue($attrs['telephoneNumber'][0]);
if (isset($entry['telephoneNumber'][0])) {
$this->setValue($entry['telephoneNumber'][0]);
} elseif (isset($entry['telephoneNumber'])) {
$this->setValue($entry['telephoneNumber']);
} else {
$this->setValue('');
}
}
function getFilterBlackList ()
{
return [];
}
function getFilterWhiteList ()
{
return [];
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment