]> git.andy128k.dev Git - ipf.git/commitdiff
render filters
authorAndrey Kutejko <andy128k@gmail.com>
Sun, 22 Apr 2018 19:57:50 +0000 (21:57 +0200)
committerAndrey Kutejko <andy128k@gmail.com>
Sun, 22 Apr 2018 20:44:32 +0000 (22:44 +0200)
ipf/admin/component.php
ipf/admin/templates/admin/items.html

index 6986d0addfc43a4c820cbe17a69b3d709e2535de..fd52693a976bed8168e46949fa318d6d7eb9c33a 100644 (file)
@@ -1,10 +1,13 @@
 <?php
 
+use \PFF\HtmlBuilder\Tag as Tag;
+
 interface IPF_Admin_ListFilter
 {
     function title();
+    function paramName();
     function setParams($params);
-    function render($extraParams);
+    function getItems();
 }
 
 abstract class IPF_Admin_Component
@@ -368,5 +371,29 @@ abstract class IPF_Admin_Component
     {
         throw new IPF_Exception('Reordering is not implemented.');
     }
-}
 
+    function renderFilter($filter)
+    {
+        $params = $this->request->GET;
+        $paramName = $filter->paramName();
+
+        $ul = Tag::ul();
+        foreach ($filter->getItems() as $item) {
+            unset($params[$paramName]);
+            if ($item['id'] !== null) {
+                $params[$paramName] = $item['id'];
+            }
+            $url = '?'.IPF_HTTP_URL::generateParams($params, false);
+
+            $ul->append(Tag::li()
+                ->toggleClass('selected', $item['selected'])
+                ->append(Tag::a()
+                    ->attr('href', $url)
+                    ->append($item['label'])
+                )
+            );
+        }
+
+        return $ul->html();
+    }
+}
index e6786eea57b7c63432f3c88fb621733627c15cba..bbf31c8d7518bfc4adb23f77ef5543f5f909ef6b 100644 (file)
@@ -40,7 +40,7 @@
         <h2>Filter</h2>
         {foreach $filters as $f}
           <h3>{$f->title()}</h3>
-          {$f->render($request->GET)|safe}
+          {$component->renderFilter($f)|safe}
         {/foreach}
       </div>
       {/if}