Sfoglia il codice sorgente

let filter decide wether it is active or not

Benoit Pointet 13 anni fa
parent
commit
d42c0c234a

+ 1 - 11
Datagrid/Datagrid.php

@@ -183,7 +183,7 @@ class Datagrid implements DatagridInterface
     public function hasActiveFilters()
     {
         foreach ($this->filters as $name => $filter) {
-            if ($this->hasActiveFilter($name)) {
+            if ($filter->isActive()) {
                 return true;
             }
         }
@@ -191,16 +191,6 @@ class Datagrid implements DatagridInterface
         return false;
     }
 
-    /**
-     * @param $name
-     * @return bool
-     */
-    public function hasActiveFilter($name)
-    {
-        return isset($this->values[$name])
-            && ! empty($this->values[$name]['value']);
-    }
-
     /**
      * @return \Sonata\AdminBundle\Admin\FieldDescriptionCollection
      */

+ 0 - 7
Datagrid/DatagridInterface.php

@@ -102,11 +102,4 @@ interface DatagridInterface
      * @return boolean
      */
     public function hasActiveFilters();
-
-    /**
-     * @abstract
-     * @param $name
-     * @return bool
-     */
-    public function hasActiveFilter($name);
 }

+ 10 - 1
Filter/Filter.php

@@ -148,6 +148,15 @@ abstract class Filter implements FilterInterface
         return $this->value;
     }
 
+    /**
+     * @return string
+     */
+    public function isActive()
+    {
+        $values = $this->getValue();
+        return ! empty($values['value']);
+    }
+
     /**
      * @param $condition
      * @return void
@@ -164,4 +173,4 @@ abstract class Filter implements FilterInterface
     {
         return $this->condition;
     }
-}
+}

+ 1 - 1
Resources/views/CRUD/base_list.html.twig

@@ -166,7 +166,7 @@ file that was distributed with this source code.
                 <div class="filter_container {{ admin.datagrid.hasActiveFilters ? 'active' : 'inactive' }}">
                     <table class="bordered-table">
                         {% for filter in admin.datagrid.filters %}
-                        <tr id="filter_{{ filter.name }}_row" class="filter {{ admin.datagrid.hasActiveFilter(filter.name) ? 'active' : 'inactive' }}">
+                        <tr id="filter_{{ filter.name }}_row" class="filter {{ filter.isActive ? 'active' : 'inactive' }}">
                                 <td class="filter-title">{{ admin.trans(filter.label) }}</td>
                                 <td class="filter-type">{{ form_widget(form.getChild(filter.name).getChild('type')) }}</td>
                                 <td class="filter-value">{{ form_widget(form.getChild(filter.name).getChild('value')) }}</td>