mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
forms/Assign*: add new assignment subforms
This commit is contained in:
parent
98c5d9f43b
commit
88633ba660
66
application/forms/AssignListSubForm.php
Normal file
66
application/forms/AssignListSubForm.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Forms;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\Objects\IcingaObject;
|
||||||
|
use Icinga\Module\Director\Web\Form\QuickSubForm;
|
||||||
|
|
||||||
|
class AssignListSubForm extends QuickSubForm
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $object;
|
||||||
|
|
||||||
|
public function setObject($object)
|
||||||
|
{
|
||||||
|
$this->object = $object;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue($value)
|
||||||
|
{
|
||||||
|
var_dump($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup()
|
||||||
|
{
|
||||||
|
$idx = -1;
|
||||||
|
|
||||||
|
if ($this->object && $this->object->isApplyRule()) {
|
||||||
|
// $this->setElementValue('assignlist', $object->assignments()->getFormValues());
|
||||||
|
foreach ($this->object->assignments()->getFormValues() as $values) {
|
||||||
|
$idx++;
|
||||||
|
$sub = new AssignmentSubForm();
|
||||||
|
$sub->setup();
|
||||||
|
$sub->populate($values);
|
||||||
|
$this->addSubForm($sub, $idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$idx++;
|
||||||
|
$sub = new AssignmentSubForm();
|
||||||
|
$sub->setup();
|
||||||
|
$this->addSubForm($sub, $idx);
|
||||||
|
$this->addElement('submit', 'addmore', array(
|
||||||
|
'label' => $this->translate('Add more'),
|
||||||
|
'class' => 'link-button icon-plus',
|
||||||
|
'ignore' => true,
|
||||||
|
));
|
||||||
|
$this->getElement('addmore')->setDecorators(array('ViewHelper'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadDefaultDecorators()
|
||||||
|
{
|
||||||
|
$this->setDecorators(array(
|
||||||
|
'FormElements',
|
||||||
|
array('HtmlTag', array(
|
||||||
|
'tag' => 'ul',
|
||||||
|
'class' => 'assign-rule'
|
||||||
|
)),
|
||||||
|
array('Fieldset', array(
|
||||||
|
'legend' => 'Assignment rules',
|
||||||
|
)),
|
||||||
|
));
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
75
application/forms/AssignmentSubForm.php
Normal file
75
application/forms/AssignmentSubForm.php
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Forms;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\Objects\IcingaHost;
|
||||||
|
use Icinga\Module\Director\Web\Form\QuickSubForm;
|
||||||
|
|
||||||
|
class AssignmentSubForm extends QuickSubForm
|
||||||
|
{
|
||||||
|
protected $_disableLoadDefaultDecorators = true;
|
||||||
|
|
||||||
|
public function setup()
|
||||||
|
{
|
||||||
|
$this->addElement('select', 'assign_type', array(
|
||||||
|
'multiOptions' => array(
|
||||||
|
'assign' => 'assign where',
|
||||||
|
'ignore' => 'ignore where',
|
||||||
|
),
|
||||||
|
'class' => 'assign-type',
|
||||||
|
'value' => 'assign'
|
||||||
|
));
|
||||||
|
$this->addElement('select', 'property', array(
|
||||||
|
'label' => $this->translate('Property'),
|
||||||
|
'class' => 'assign-property autosubmit',
|
||||||
|
'multiOptions' => $this->optionalEnum(IcingaHost::enumProperties($this->db))
|
||||||
|
));
|
||||||
|
$this->addElement('select', 'operator', array(
|
||||||
|
'label' => $this->translate('Operator'),
|
||||||
|
'multiOptions' => array(
|
||||||
|
'=' => '=',
|
||||||
|
'!=' => '!=',
|
||||||
|
'>' => '>',
|
||||||
|
'>=' => '>=',
|
||||||
|
'<=' => '<=',
|
||||||
|
'<' => '<',
|
||||||
|
),
|
||||||
|
'required' => $this->valueIsEmpty($this->getValue('property')),
|
||||||
|
'value' => '=',
|
||||||
|
'class' => 'assign-operator',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->addElement('text', 'expression', array(
|
||||||
|
'label' => $this->translate('Expression'),
|
||||||
|
'placeholder' => $this->translate('Expression'),
|
||||||
|
'class' => 'assign-expression',
|
||||||
|
'required' => !$this->valueIsEmpty($this->getValue('property'))
|
||||||
|
));
|
||||||
|
/*
|
||||||
|
$this->addElement('submit', 'remove', array(
|
||||||
|
'label' => '-',
|
||||||
|
'ignore' => true
|
||||||
|
));
|
||||||
|
$this->addElement('submit', 'add', array(
|
||||||
|
'label' => '+',
|
||||||
|
'ignore' => true
|
||||||
|
));
|
||||||
|
*/
|
||||||
|
foreach ($this->getElements() as $el) {
|
||||||
|
$el->setDecorators(array('ViewHelper'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadDefaultDecorators()
|
||||||
|
{
|
||||||
|
$this->setDecorators(array(
|
||||||
|
'FormElements',
|
||||||
|
array('HtmlTag', array(
|
||||||
|
'tag' => 'li',
|
||||||
|
)),
|
||||||
|
array('FormErrors'),
|
||||||
|
));
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user