[icinga-checkins] icinga.org: icingaweb2/master: FilterEditor: add request handle support

git at icinga.org git at icinga.org
Sun Nov 16 00:38:43 CET 2014


Module: icingaweb2
Branch: master
Commit: b1f82bd025c247feb31d8ba781d75662f1fcd361
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=b1f82bd025c247feb31d8ba781d75662f1fcd361

Author: Thomas Gelf <thomas at gelf.net>
Date:   Sat Nov 15 23:49:06 2014 +0100

FilterEditor: add request handle support

---

 library/Icinga/Web/Widget/FilterEditor.php |   59 +++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/library/Icinga/Web/Widget/FilterEditor.php b/library/Icinga/Web/Widget/FilterEditor.php
index d8b9305..4c4dace 100644
--- a/library/Icinga/Web/Widget/FilterEditor.php
+++ b/library/Icinga/Web/Widget/FilterEditor.php
@@ -108,6 +108,63 @@ class FilterEditor extends AbstractWidget
         $response->redirectAndExit($url);
     }
 
+    public function handleRequest($request)
+    {
+        $this->setUrl($request->getUrl());
+        $params = $this->url()->getParams();
+
+        $preserve = array();
+        foreach ($this->preserveParams as $key) {
+            if (null !== ($value = $params->shift($key))) {
+                $preserve[$key] = $value;
+            }
+        }
+
+        $add    = $params->shift('addFilter');
+        $remove = $params->shift('removeFilter');
+        $strip  = $params->shift('stripFilter');
+        $modify = $params->shift('modifyFilter');
+        $filter = $this->getFilter();   
+
+        if ($remove) {
+            $redirect = $this->url();
+            if ($filter->getById($remove)->isRootNode()) {
+                $redirect->setQueryString('');
+            } else {
+                $filter->removeId($remove);
+                $redirect->setQueryString($filter->toQueryString())->getParams()->add('modifyFilter');
+            }
+            $this->redirectNow($redirect->addParams($preserve));
+        }
+
+        if ($strip) {
+            $redirect = $this->url();
+            $filter->replaceById($strip, $filter->getById($strip . '-1'));
+            $redirect->setQueryString($filter->toQueryString())->getParams()->add('modifyFilter');
+            $this->redirectNow($redirect->addParams($preserve));
+        }
+
+
+        if ($modify) {
+            if ($request->isPost()) {
+                if ($request->get('cancel') === 'Cancel') {
+                    $this->redirectNow($this->url()->without('modifyFilter'));
+                }
+
+                $filter = $this->applyChanges($request->getPost());
+                $url = $this->url()->setQueryString($filter->toQueryString())->addParams($preserve);
+                $url->getParams()->add('modifyFilter');
+                $this->redirectNow($url);
+            }
+            $this->url()->getParams()->add('modifyFilter');
+        }
+
+        if ($add) {
+            $this->addFilterToId($add);
+        }
+        return $this;
+    }
+
     protected function select($name, $list, $selected, $attributes = null)
     {
         $view = $this->view();
@@ -454,4 +511,4 @@ class FilterEditor extends AbstractWidget
             return 'ERROR in FilterEditor: ' . $e->getMessage();
         }
     }
-}
+}
\ No newline at end of file



More information about the icinga-checkins mailing list