mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 17:24:18 +02:00
parent
98708e6496
commit
6f46e6b496
@ -124,14 +124,12 @@ class SyncPropertyForm extends DirectorObjectForm
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// TODO: we need modifier
|
||||
$this->addElement('select', 'use_filter', array(
|
||||
$this->addElement('YesNo', 'use_filter', array(
|
||||
'label' => $this->translate('Set based on filter'),
|
||||
'ignore' => true,
|
||||
'class' => 'autosubmit',
|
||||
'required' => true,
|
||||
'multiOptions' => $this->enumBoolean()
|
||||
));
|
||||
|
||||
if ($this->hasBeenSent()) {
|
||||
|
@ -229,12 +229,6 @@ abstract class DirectorObjectForm extends QuickForm
|
||||
unset($props['vars']);
|
||||
}
|
||||
|
||||
foreach ($props as $k => $v) {
|
||||
if (is_bool($v)) {
|
||||
$props[$k] = $v ? 'y' : 'n';
|
||||
}
|
||||
}
|
||||
|
||||
$this->setDefaults($props);
|
||||
|
||||
if (! $object instanceof IcingaObject) {
|
||||
@ -424,25 +418,12 @@ abstract class DirectorObjectForm extends QuickForm
|
||||
|
||||
protected function addBoolean($key, $options, $default = null)
|
||||
{
|
||||
$map = array(
|
||||
false => 'n',
|
||||
true => 'y',
|
||||
'n' => 'n',
|
||||
'y' => 'y',
|
||||
);
|
||||
if ($default !== null) {
|
||||
$options['multiOptions'] = $this->enumBoolean();
|
||||
if ($default === null) {
|
||||
return $this->addElement('OptionalYesNo', $key, $options);
|
||||
} 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)
|
||||
@ -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)
|
||||
{
|
||||
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