[icinga-checkins] icinga.org: icingaweb2-module-director/master: SyncPropertyForm: allow to define a filter

git at icinga.org git at icinga.org
Sun Feb 28 17:12:40 CET 2016


Module: icingaweb2-module-director
Branch: master
Commit: 7f949e1b5a6930f8a87bc08d78795f7ba23a89a3
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=7f949e1b5a6930f8a87bc08d78795f7ba23a89a3

Author: Thomas Gelf <thomas at gelf.net>
Date:   Sun Feb 28 16:23:51 2016 +0100

SyncPropertyForm: allow to define a filter

---

 application/forms/SyncPropertyForm.php |   41 ++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/application/forms/SyncPropertyForm.php b/application/forms/SyncPropertyForm.php
index dc431d2..83df075 100644
--- a/application/forms/SyncPropertyForm.php
+++ b/application/forms/SyncPropertyForm.php
@@ -122,25 +122,36 @@ class SyncPropertyForm extends DirectorObjectForm
         }
         */
 
-        /*
-        TODO: Filter should be a modifier
+
+        // TODO: we need modifier
         $this->addElement('select', 'use_filter', array(
-            'label'        => $this->translate('Filter values'),
-            'description'  => $this->translate('Whether you want to merge or replace the destination field. Makes no difference for strings'),
+            'label'        => $this->translate('Set based on filter'),
+            'ignore'       => true,
+            'class'        => 'autosubmit',
             'required'     => true,
-            'multiOptions' => $this->optionalEnum(array(
-                'y' => 'merge',
-                'n' => 'replace'
-            ))
+            'multiOptions' => $this->enumBoolean()
         ));
 
-        $this->addElement('text', 'filter_expression', array(
-            'label'       => $this->translate('Filter Expression'),
-            'description' => $this->translate('This allows to filter for specific parts within the given source expression'),
-            'required'    => false,
-            // TODO: validate filter
-        )); 
-        */
+        if ($this->hasBeenSent()) {
+            $useFilter = $this->getSentValue('use_filter');
+            if ($useFilter === null) {
+                $this->setElementValue('use_filter', $useFilter = 'n');
+            }
+        } else {
+            $useFilter = empty($this->getObject()->filter_expression) ? 'n' : 'y';
+            $this->setElementValue('use_filter', $useFilter);
+        }
+
+        if ($useFilter === 'y') {
+            $this->addElement('text', 'filter_expression', array(
+                'label'       => $this->translate('Filter Expression'),
+                'description' => $this->translate(
+                    'This allows to filter for specific parts within the given source expression'
+                ),
+                'required'    => false,
+                // TODO: validate filter
+            ));
+        }
 
         if ($isCustomvar || $destination === 'vars') {
             $this->addElement('select', 'merge_policy', array(



More information about the icinga-checkins mailing list