[icinga-checkins] icinga.org: icingaweb2-module-director/feature/ sync-import-expression-12700: SyncPropertyForm: Allow user to define an expression for imports

git at icinga.org git at icinga.org
Wed Oct 26 16:32:35 CEST 2016


Module: icingaweb2-module-director
Branch: feature/sync-import-expression-12700
Commit: 217b802ceea96c58bca5012e42b35fd030052cb1
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=217b802ceea96c58bca5012e42b35fd030052cb1

Author: Markus Frosch <markus.frosch at icinga.com>
Date:   Wed Oct 26 16:32:30 2016 +0200

SyncPropertyForm: Allow user to define an expression for imports

refs #12700

---

 application/forms/SyncPropertyForm.php |   57 +++++++++++++++++++-------------
 1 file changed, 34 insertions(+), 23 deletions(-)

diff --git a/application/forms/SyncPropertyForm.php b/application/forms/SyncPropertyForm.php
index 55320df..b09a5a0 100644
--- a/application/forms/SyncPropertyForm.php
+++ b/application/forms/SyncPropertyForm.php
@@ -3,7 +3,6 @@
 namespace Icinga\Module\Director\Forms;
 
 use Exception;
-use Icinga\Exception\InvalidPropertyException;
 use Icinga\Module\Director\Hook\ImportSourceHook;
 use Icinga\Module\Director\Objects\SyncRule;
 use Icinga\Module\Director\Objects\IcingaObject;
@@ -78,19 +77,43 @@ class SyncPropertyForm extends DirectorObjectForm
                 $templates = array_combine($templates, $templates);
             }
 
-            $this->addElement('select', 'source_expression', array(
-                'label'        => $this->translate('Template'), // Objecttype?
-                'multiOptions' => $this->optionalEnum($templates),
-                'required'     => true,
-                'class'        => 'autosubmit',
-            ));
+            $templates['${' . self::EXPRESSION . '}'] = $this->translate('Custom expression');
+            ksort($templates);
+
+            if (preg_match('~\$\{.+\}~', $this->getSentOrObjectValue('source_expression'))) {
+                $this->addElement('text', 'source_expression', array(
+                    'label'        => $this->translate('Template'),
+                    'required'     => true,
+                    'class'        => 'autosubmit',
+                ));
+            }
+            else {
+                $this->addElement('select', 'source_expression', array(
+                    'label'        => $this->translate('Template'), // Objecttype?
+                    'multiOptions' => $this->optionalEnum($templates),
+                    'required'     => true,
+                    'class'        => 'autosubmit',
+                ));
+            }
         } else {
             $this->addSourceColumnElement();
-        }
 
-        if ($this->hasObject()) {
-            if (($col = $this->getObject()->getSourceColumn()) === null) {
-                $this->setElementValue('source_column', self::EXPRESSION);
+            if ($this->hasObject()) {
+                if (($col = $this->getObject()->getSourceColumn()) === null) {
+                    $this->setElementValue('source_column', self::EXPRESSION);
+                    $this->addElement('text', 'source_expression', array(
+                        'label'    => $this->translate('Source Expression'),
+                        'required' => true,
+                    ));
+                    if ($this->getSentValue('source_column') === '${' . self::EXPRESSION . '}') {
+                        unset($this->source_column);
+                    }
+                } else {
+                    $this->setElementValue('source_column', $col);
+                }
+            }
+
+            if ($this->getSentValue('source_column') === self::EXPRESSION) {
                 $this->addElement('text', 'source_expression', array(
                     'label'    => $this->translate('Source Expression'),
                     'required' => true,
@@ -98,18 +121,6 @@ class SyncPropertyForm extends DirectorObjectForm
                 if ($this->getSentValue('source_column') === '${' . self::EXPRESSION . '}') {
                     unset($this->source_column);
                 }
-            } else {
-                $this->setElementValue('source_column', $col);
-            }
-        }
-
-        if ($this->getSentValue('source_column') === self::EXPRESSION) {
-            $this->addElement('text', 'source_expression', array(
-                'label'    => $this->translate('Source Expression'),
-                'required' => true,
-            ));
-            if ($this->getSentValue('source_column') === '${' . self::EXPRESSION . '}') {
-                unset($this->source_column);
             }
         }
 



More information about the icinga-checkins mailing list