From d6e4c9bae7e2a41f077fa32a3ba1a031478b8e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Tue, 2 Apr 2019 10:54:39 +0200 Subject: [PATCH] :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 --- .../management/filter-element-fixed.tpl | 10 ++++ .../management/class_FixedFilterElement.inc | 52 +++++++++++++++++++ .../attributes/class_PhoneNumberAttribute.inc | 24 +++++++-- 3 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 ihtml/themes/breezy/management/filter-element-fixed.tpl create mode 100644 include/management/class_FixedFilterElement.inc diff --git a/ihtml/themes/breezy/management/filter-element-fixed.tpl b/ihtml/themes/breezy/management/filter-element-fixed.tpl new file mode 100644 index 000000000..9123f6367 --- /dev/null +++ b/ihtml/themes/breezy/management/filter-element-fixed.tpl @@ -0,0 +1,10 @@ +<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> diff --git a/include/management/class_FixedFilterElement.inc b/include/management/class_FixedFilterElement.inc new file mode 100644 index 000000000..aeb43f580 --- /dev/null +++ b/include/management/class_FixedFilterElement.inc @@ -0,0 +1,52 @@ +<?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; + } +} diff --git a/include/simpleplugin/attributes/class_PhoneNumberAttribute.inc b/include/simpleplugin/attributes/class_PhoneNumberAttribute.inc index 770932f4b..401e2ff9d 100644 --- a/include/simpleplugin/attributes/class_PhoneNumberAttribute.inc +++ b/include/simpleplugin/attributes/class_PhoneNumberAttribute.inc @@ -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 []; + } } -- GitLab