parent
fd80344d79
commit
cea6d4b456
|
@ -16,6 +16,7 @@ use Icinga\Module\Director\Objects\IcingaTemplateChoice;
|
|||
use Icinga\Module\Director\Objects\IcingaCommand;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Module\Director\Util;
|
||||
use Icinga\Module\Director\Web\Form\Element\ExtensibleSet;
|
||||
use Icinga\Module\Director\Web\Form\Validate\NamePattern;
|
||||
use Zend_Form_Element as ZfElement;
|
||||
use Zend_Form_Element_Select as ZfSelect;
|
||||
|
@ -623,6 +624,9 @@ abstract class DirectorObjectForm extends DirectorForm
|
|||
$multi[null] = $this->translate($this->translate('- inherited -'));
|
||||
}
|
||||
$el->setMultiOptions($multi);
|
||||
} elseif ($el instanceof ExtensibleSet) {
|
||||
$el->setAttrib('inherited', $inherited);
|
||||
$el->setAttrib('inheritedFrom', $inheritedFrom);
|
||||
} else {
|
||||
if (is_string($inherited) || is_int($inherited)) {
|
||||
$el->setAttrib('placeholder', $inherited . sprintf($txtInherited, $inheritedFrom));
|
||||
|
|
|
@ -42,6 +42,10 @@ class ExtensibleSetElement extends BaseHtmlElement
|
|||
|
||||
private $hideOptions = [];
|
||||
|
||||
private $inherited;
|
||||
|
||||
private $inheritedFrom;
|
||||
|
||||
protected $defaultAttributes = [
|
||||
'class' => 'extensible-set'
|
||||
];
|
||||
|
@ -129,11 +133,18 @@ class ExtensibleSetElement extends BaseHtmlElement
|
|||
$this->disable($attribs['disable']);
|
||||
unset($attribs['disable']);
|
||||
}
|
||||
|
||||
if (array_key_exists('value', $attribs)) {
|
||||
$this->setValue($attribs['value']);
|
||||
unset($attribs['value']);
|
||||
}
|
||||
if (array_key_exists('inherited', $attribs)) {
|
||||
$this->inherited = $attribs['inherited'];
|
||||
unset($attribs['inherited']);
|
||||
}
|
||||
if (array_key_exists('inheritedFrom', $attribs)) {
|
||||
$this->inheritedFrom = $attribs['inheritedFrom'];
|
||||
unset($attribs['inheritedFrom']);
|
||||
}
|
||||
|
||||
if (array_key_exists('multiOptions', $attribs)) {
|
||||
$this->setMultiOptions($attribs['multiOptions']);
|
||||
|
@ -228,10 +239,13 @@ class ExtensibleSetElement extends BaseHtmlElement
|
|||
return;
|
||||
}
|
||||
$field = Html::tag('select', ['class' => 'autosubmit']);
|
||||
$more = $this->inherited === null
|
||||
? $this->translate('- add more -')
|
||||
: $this->getInheritedInfo();
|
||||
$field->add(Html::tag('option', [
|
||||
'value' => '',
|
||||
'tabindex' => '-1'
|
||||
], $this->translate('- add more -')));
|
||||
], $more));
|
||||
|
||||
foreach ($this->multiOptions as $key => $label) {
|
||||
if ($key === null) {
|
||||
|
@ -253,7 +267,9 @@ class ExtensibleSetElement extends BaseHtmlElement
|
|||
} else {
|
||||
$field = Html::tag('input', [
|
||||
'type' => 'text',
|
||||
'placeholder' => $this->translate('Add a new one...'),
|
||||
'placeholder' => $this->inherited === null
|
||||
? $this->translate('Add a new one...')
|
||||
: $this->getInheritedInfo(),
|
||||
]);
|
||||
}
|
||||
$field->addAttributes([
|
||||
|
@ -284,6 +300,22 @@ class ExtensibleSetElement extends BaseHtmlElement
|
|||
}
|
||||
}
|
||||
|
||||
private function getInheritedInfo()
|
||||
{
|
||||
if ($this->inheritedFrom === null) {
|
||||
return \sprintf(
|
||||
$this->translate('%s (inherited)'),
|
||||
\implode(', ', $this->inherited)
|
||||
);
|
||||
} else {
|
||||
return \sprintf(
|
||||
$this->translate('%s (inherited from %s)'),
|
||||
\implode(', ', $this->inherited),
|
||||
$this->inheritedFrom
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function createAddNewButton()
|
||||
{
|
||||
return $this->newInlineButtons(
|
||||
|
|
Loading…
Reference in New Issue