TransportConfigForm: Use a select input for setting the instance

refs #9651
This commit is contained in:
Johannes Meyer 2015-08-31 12:17:57 +02:00
parent 6f6e991fd0
commit ff54284401
2 changed files with 46 additions and 11 deletions

View File

@ -195,6 +195,7 @@ class Monitoring_ConfigController extends Controller
$form->setRedirectUrl('monitoring/config');
$form->setTitle(sprintf($this->translate('Edit Command Transport %s'), $transportName));
$form->setIniConfig($this->Config('commandtransports'));
$form->setInstanceNames($this->backend->select()->from('instance', array('instance_name'))->fetchColumn());
$form->setOnSuccess(function (TransportConfigForm $form) use ($transportName) {
try {
$form->edit($transportName, array_map(
@ -236,6 +237,7 @@ class Monitoring_ConfigController extends Controller
$form->setRedirectUrl('monitoring/config');
$form->setTitle($this->translate('Create New Command Transport'));
$form->setIniConfig($this->Config('commandtransports'));
$form->setInstanceNames($this->backend->select()->from('instance', array('instance_name'))->fetchColumn());
$form->setOnSuccess(function (TransportConfigForm $form) {
try {
$form->add(array_filter($form->getValues()));

View File

@ -24,6 +24,13 @@ class TransportConfigForm extends ConfigForm
*/
protected $transportToLoad;
/**
* The names of all available Icinga instances
*
* @var array
*/
protected $instanceNames;
/**
* Initialize this form
*/
@ -33,6 +40,29 @@ class TransportConfigForm extends ConfigForm
$this->setSubmitLabel($this->translate('Save Changes'));
}
/**
* Set the names of all available Icinga instances
*
* @param array $names
*
* @return $this
*/
public function setInstanceNames(array $names)
{
$this->instanceNames = $names;
return $this;
}
/**
* Return the names of all available Icinga instances
*
* @return array
*/
public function getInstanceNames()
{
return $this->instanceNames ?: array();
}
/**
* Return a form object for the given transport type
*
@ -163,18 +193,21 @@ class TransportConfigForm extends ConfigForm
*/
public function createElements(array $formData)
{
$this->addElement(
'text',
'instance',
array(
'placeholder' => 'default',
'label' => $this->translate('Instance Name'),
'description' => $this->translate(
'The name of the Icinga instance this transport should transfer commands to. You do not '
. 'need to adjust this if you\'re not using a different instance name than the default.'
$instanceNames = $this->getInstanceNames();
if (count($instanceNames) > 1) {
$options = array('none' => $this->translate('None', 'command transport instance association'));
$this->addElement(
'select',
'instance',
array(
'label' => $this->translate('Instance Link'),
'description' => $this->translate(
'The name of the Icinga instance this transport should exclusively transfer commands to.'
),
'multiOptions' => array_merge($options, array_combine($instanceNames, $instanceNames))
)
)
);
);
}
$this->addElement(
'text',