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

View File

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