diff options
Diffstat (limited to 'application/forms/Navigation')
-rw-r--r-- | application/forms/Navigation/ActionForm.php | 58 | ||||
-rw-r--r-- | application/forms/Navigation/IcingadbHostActionForm.php | 10 | ||||
-rw-r--r-- | application/forms/Navigation/IcingadbServiceActionForm.php | 10 |
3 files changed, 78 insertions, 0 deletions
diff --git a/application/forms/Navigation/ActionForm.php b/application/forms/Navigation/ActionForm.php new file mode 100644 index 0000000..08cba3f --- /dev/null +++ b/application/forms/Navigation/ActionForm.php @@ -0,0 +1,58 @@ +<?php + +/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2 */ + +namespace Icinga\Module\Icingadb\Forms\Navigation; + +use Icinga\Exception\ConfigurationError; +use Icinga\Forms\Navigation\NavigationItemForm; +use Icinga\Module\Icingadb\Common\Auth; + +class ActionForm extends NavigationItemForm +{ + use Auth; + + /** + * The name of the restriction to which the filter should be applied + * + * @var string + */ + protected $restriction; + + public function createElements(array $formData) + { + parent::createElements($formData); + + $this->addElement( + 'text', + 'filter', + array( + 'allowEmpty' => true, + 'label' => $this->translate('Filter'), + 'description' => $this->translate( + 'Display this action only for objects matching this filter. Leave it blank' + . ' if you want this action being displayed regardless of the object' + ) + ) + ); + } + + public function isValid($formData): bool + { + if (! parent::isValid($formData)) { + return false; + } + + if (($filterString = $this->getValue('filter')) !== null) { + try { + $this->parseRestriction($filterString, $this->restriction); + } catch (ConfigurationError $err) { + $this->getElement('filter')->addError($err->getMessage()); + + return false; + } + } + + return true; + } +} diff --git a/application/forms/Navigation/IcingadbHostActionForm.php b/application/forms/Navigation/IcingadbHostActionForm.php new file mode 100644 index 0000000..adee11d --- /dev/null +++ b/application/forms/Navigation/IcingadbHostActionForm.php @@ -0,0 +1,10 @@ +<?php + +/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2 */ + +namespace Icinga\Module\Icingadb\Forms\Navigation; + +class IcingadbHostActionForm extends ActionForm +{ + protected $restriction = 'icingadb/filter/hosts'; +} diff --git a/application/forms/Navigation/IcingadbServiceActionForm.php b/application/forms/Navigation/IcingadbServiceActionForm.php new file mode 100644 index 0000000..29d33c8 --- /dev/null +++ b/application/forms/Navigation/IcingadbServiceActionForm.php @@ -0,0 +1,10 @@ +<?php + +/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2 */ + +namespace Icinga\Module\Icingadb\Forms\Navigation; + +class IcingadbServiceActionForm extends ActionForm +{ + protected $restriction = 'icingadb/filter/services'; +} |