mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
parent
98708e6496
commit
6f46e6b496
@ -124,14 +124,12 @@ class SyncPropertyForm extends DirectorObjectForm
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// TODO: we need modifier
|
// TODO: we need modifier
|
||||||
$this->addElement('select', 'use_filter', array(
|
$this->addElement('YesNo', 'use_filter', array(
|
||||||
'label' => $this->translate('Set based on filter'),
|
'label' => $this->translate('Set based on filter'),
|
||||||
'ignore' => true,
|
'ignore' => true,
|
||||||
'class' => 'autosubmit',
|
'class' => 'autosubmit',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'multiOptions' => $this->enumBoolean()
|
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($this->hasBeenSent()) {
|
if ($this->hasBeenSent()) {
|
||||||
|
@ -229,12 +229,6 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
unset($props['vars']);
|
unset($props['vars']);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($props as $k => $v) {
|
|
||||||
if (is_bool($v)) {
|
|
||||||
$props[$k] = $v ? 'y' : 'n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setDefaults($props);
|
$this->setDefaults($props);
|
||||||
|
|
||||||
if (! $object instanceof IcingaObject) {
|
if (! $object instanceof IcingaObject) {
|
||||||
@ -424,25 +418,12 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
|
|
||||||
protected function addBoolean($key, $options, $default = null)
|
protected function addBoolean($key, $options, $default = null)
|
||||||
{
|
{
|
||||||
$map = array(
|
if ($default === null) {
|
||||||
false => 'n',
|
return $this->addElement('OptionalYesNo', $key, $options);
|
||||||
true => 'y',
|
|
||||||
'n' => 'n',
|
|
||||||
'y' => 'y',
|
|
||||||
);
|
|
||||||
if ($default !== null) {
|
|
||||||
$options['multiOptions'] = $this->enumBoolean();
|
|
||||||
} else {
|
} else {
|
||||||
$options['multiOptions'] = $this->optionalEnum($this->enumBoolean());
|
$this->addElement('YesNo', $key, $options);
|
||||||
|
return $this->getElement($key)->setValue($default);
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = $this->addElement('select', $key, $options);
|
|
||||||
|
|
||||||
if ($default !== null) {
|
|
||||||
$this->getElement($key)->setValue($map[$default]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function optionalBoolean($key, $label, $description)
|
protected function optionalBoolean($key, $label, $description)
|
||||||
@ -453,14 +434,6 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function enumBoolean()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
'y' => $this->translate('Yes'),
|
|
||||||
'n' => $this->translate('No'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasElement($name)
|
public function hasElement($name)
|
||||||
{
|
{
|
||||||
return $this->getElement($name) !== null;
|
return $this->getElement($name) !== null;
|
||||||
|
22
library/Director/Web/Form/Element/OptionalYesNo.php
Normal file
22
library/Director/Web/Form/Element/OptionalYesNo.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Web\Form\Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Input control for booleans, gives y/n
|
||||||
|
*/
|
||||||
|
class OptionalYesNo extends Boolean
|
||||||
|
{
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
$value = $this->getUnfilteredValue();
|
||||||
|
|
||||||
|
if ($value === 'y' || $value === true) {
|
||||||
|
return 'y';
|
||||||
|
} elseif ($value === 'n' || $value === false) {
|
||||||
|
return 'n';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
14
library/Director/Web/Form/Element/YesNo.php
Normal file
14
library/Director/Web/Form/Element/YesNo.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Web\Form\Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Input control for booleans, gives y/n
|
||||||
|
*/
|
||||||
|
class YesNo extends OptionalYesNo
|
||||||
|
{
|
||||||
|
public $options = array(
|
||||||
|
'y' => 'Yes',
|
||||||
|
'n' => 'No',
|
||||||
|
);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user