瀏覽代碼

View code for filtered actions

Benjamin Eberlei 14 年之前
父節點
當前提交
21e337c586
共有 2 個文件被更改,包括 37 次插入14 次删除
  1. 26 14
      Admin/Admin.php
  2. 11 0
      Resources/views/CRUD/base_list.html.twig

+ 26 - 14
Admin/Admin.php

@@ -534,6 +534,30 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
 
         return $this->listFieldDescriptions;
     }
+    
+    /**
+     * Get parameters that are currently bound to the filter.
+     * 
+     * @return array
+     */
+    public function getFilterParameters()
+    {
+        $parameters = array();
+        // build the values array
+        if ($this->hasRequest()) {
+            $parameters = array_merge(
+                $this->getModelManager()->getDefaultSortValues($this->getClass()),
+                $this->datagridValues,
+                $this->request->query->all()
+            );
+
+            // always force the parent value
+            if ($this->isChild() && $this->getParentAssociationMapping()) {
+                $parameters[$this->getParentAssociationMapping()] = $this->request->get($this->getParent()->getIdParameter());
+            }
+        }
+        return $parameters;
+    }
 
     /**
      * build the filter FieldDescription array
@@ -560,20 +584,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
             $this->getDatagridBuilder()->fixFieldDescription($this, $fieldDescription);
         }
 
-        $parameters = array();
-        // build the values array
-        if ($this->hasRequest()) {
-            $parameters = array_merge(
-                $this->getModelManager()->getDefaultSortValues($this->getClass()),
-                $this->datagridValues,
-                $this->request->query->all()
-            );
-
-            // always force the parent value
-            if ($this->isChild() && $this->getParentAssociationMapping()) {
-                $parameters[$this->getParentAssociationMapping()] = $this->request->get($this->getParent()->getIdParameter());
-            }
-        }
+        $parameters = $this->getFilterParameters();
 
         // initialize the datagrid
         $this->datagrid = $this->getDatagridBuilder()->getBaseDatagrid($this, $parameters);
@@ -818,6 +829,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         $collection->add('list');
         $collection->add('create');
         $collection->add('batch');
+        $collection->add('filter');
         $collection->add('edit', $this->getRouterIdParameter().'/edit');
         $collection->add('delete', $this->getRouterIdParameter().'/delete');
         $collection->add('view', $this->getRouterIdParameter().'/view');

+ 11 - 0
Resources/views/CRUD/base_list.html.twig

@@ -143,6 +143,17 @@ file that was distributed with this source code.
 
             <a href="{{ admin.generateUrl('list') }}">{% trans from 'SonataAdminBundle' %}link_reset_filter{% endtrans %}</a>
         </form>
+    
+        {% if admin.filterActions %}
+        <form class="sonata-filter-action-form" action="{{ admin.generateUrl('filter') }}?{% for k,v in admin.filterParameters %}&{{k}}={{v}}{% endfor %}" method="POST">
+            <select name="action">
+                {% for action, label in admin.filterActions %}
+                    <option value="{{ action }}">{{ label }}</option>
+                {% endfor %}
+            </select>
+            <input type="submit" value="{% trans from 'SonataAdminBundle' %}btn_batch{% endtrans %}" />
+        </form>
+        {% endif %}
     {% endif %}
 {% endblock %}