mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
ImportSourceForm: less hacky, less buggy
This commit is contained in:
parent
b3ce3bc749
commit
0b4c4d6538
@ -23,59 +23,37 @@ class ImportSourceForm extends DirectorObjectForm
|
|||||||
$this->addElement('select', 'provider_class', array(
|
$this->addElement('select', 'provider_class', array(
|
||||||
'label' => $this->translate('Source Type'),
|
'label' => $this->translate('Source Type'),
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'multiOptions' => $this->enumSourceTypes(),
|
'multiOptions' => $this->optionalEnum($this->enumSourceTypes()),
|
||||||
'class' => 'autosubmit'
|
'class' => 'autosubmit'
|
||||||
));
|
));
|
||||||
|
|
||||||
// TODO: Form needs to provide a better way for doing this
|
$this->addSettings();
|
||||||
if (isset($_POST['provider_class'])) {
|
|
||||||
$class = $_POST['provider_class'];
|
|
||||||
if ($class && array_key_exists($class, $this->enumSourceTypes())) {
|
|
||||||
$this->addSettings($class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addSettings($class = null)
|
protected function addSettings($class = null)
|
||||||
{
|
{
|
||||||
if ($class === null) {
|
if ($this->hasBeenSent()) {
|
||||||
if ($class = $this->getValue('provider_class')) {
|
$class = $this->getRequest()->getPost('provider_class');
|
||||||
$class::addSettingsFormFields($this);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$class::addSettingsFormFields($this);
|
if (! ($class = $this->object()->provider_class)) {
|
||||||
}
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
public function loadObject($id)
|
|
||||||
{
|
|
||||||
|
|
||||||
parent::loadObject($id);
|
|
||||||
$this->addSettings();
|
|
||||||
foreach ($this->object()->getSettings() as $key => $val) {
|
|
||||||
if ($el = $this->getElement($key)) {
|
|
||||||
$el->setValue($val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->moveSubmitToBottom();
|
|
||||||
|
|
||||||
return $this;
|
if (array_key_exists($class, $this->enumSourceTypes())) {
|
||||||
}
|
$class::addSettingsFormFields($this);
|
||||||
|
foreach ($this->object()->getSettings() as $key => $val) {
|
||||||
public function onSuccess()
|
if ($el = $this->getElement($key)) {
|
||||||
{
|
$el->setValue($val);
|
||||||
/*
|
}
|
||||||
$this->getElement('owner')->setValue(
|
}
|
||||||
self::username()
|
}
|
||||||
);
|
|
||||||
*/
|
|
||||||
parent::onSuccess();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function enumSourceTypes()
|
protected function enumSourceTypes()
|
||||||
{
|
{
|
||||||
$hooks = Hook::all('Director\\ImportSource');
|
$hooks = Hook::all('Director\\ImportSource');
|
||||||
$enum = array(null => '- please choose -');
|
$enum = array();
|
||||||
foreach ($hooks as $hook) {
|
foreach ($hooks as $hook) {
|
||||||
$enum[get_class($hook)] = $hook->getName();
|
$enum[get_class($hook)] = $hook->getName();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user