[icinga-checkins] icinga.org: icingaweb2-module-director/feature/service-set-12891: QuickTable: provide multiselect feature

git at icinga.org git at icinga.org
Thu Oct 20 09:26:56 CEST 2016


Module: icingaweb2-module-director
Branch: feature/service-set-12891
Commit: 41c44486854295ec26e358cdcb8766086a0fd30d
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=41c44486854295ec26e358cdcb8766086a0fd30d

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Oct 13 19:04:30 2016 +0000

QuickTable: provide multiselect feature

refs #11614

---

 library/Director/Web/Table/QuickTable.php |   47 +++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/library/Director/Web/Table/QuickTable.php b/library/Director/Web/Table/QuickTable.php
index 3c70711..94fd2de 100644
--- a/library/Director/Web/Table/QuickTable.php
+++ b/library/Director/Web/Table/QuickTable.php
@@ -67,6 +67,41 @@ abstract class QuickTable implements Paginatable
         }
     }
 
+    protected function getMultiselectProperties()
+    {
+        /* array(
+         *     'url'       => 'director/hosts/edit',
+         *     'sourceUrl' => 'director/hosts',
+         *     'keys'      => 'name'
+         * ) */
+
+        return array();
+    }
+
+    protected function renderMultiselectAttributes()
+    {
+        $props = $this->getMultiselectProperties();
+
+        if (empty($props)) {
+            return '';
+        }
+
+        $prefix = 'data-icinga-multiselect-';
+        $view = $this->view();
+        $parts = array();
+        $multi = array(
+            'url'         => $view->href($props['url']),
+            'controllers' => $view->href($props['sourceUrl']),
+            'data'        => implode(',', $props['keys']),
+        );
+
+        foreach ($multi as $k => $v) {
+            $parts[] = $prefix . $k . '="' . $v . '"';
+        }
+
+        return ' ' . implode(' ', $parts);
+    }
+
     protected function renderRow($row)
     {
         $htm = "  <tr" . $this->getRowClassesString($row) . ">\n";
@@ -245,14 +280,22 @@ abstract class QuickTable implements Paginatable
 
     protected function listTableClasses()
     {
-        return array('simple', 'common-table', 'table-row-selectable');
+        $classes = array('simple', 'common-table', 'table-row-selectable');
+        if (! empty($this->getMultiselectProperties())) {
+            $classes[] = 'multiselect';
+        }
+
+        return $classes;
     }
 
     public function render()
     {
         $data = $this->fetchData();
 
-        $htm = '<table' . $this->createClassAttribute($this->listTableClasses()) . '>' . "\n"
+        $htm = '<table'
+             . $this->createClassAttribute($this->listTableClasses())
+             . $this->renderMultiselectAttributes()
+             . '>' . "\n"
              . $this->renderTitles($this->getTitles())
              . "<tbody>\n";
         foreach ($data as $row) {



More information about the icinga-checkins mailing list