Преглед изворни кода

Merge remote branch 'origin/master'

Thomas пре 14 година
родитељ
комит
5f355f6a4a
3 измењених фајлова са 18 додато и 51 уклоњено
  1. 11 43
      Admin/Admin.php
  2. 2 2
      Datagrid/ListMapper.php
  3. 5 6
      Resources/views/CRUD/base_list.twig.html

+ 11 - 43
Admin/Admin.php

@@ -24,15 +24,15 @@ abstract class Admin extends ContainerAware
 {
     protected $class;
 
-    protected $list = false;
+    protected $list = array();
 
     protected $listFieldDescriptions = array();
 
-    protected $form = false;
+    protected $form = array();
     
     protected $formFieldDescriptions = array();
 
-    protected $filter = false;
+    protected $filter = array();
 
     protected $filterFieldDescriptions = array(); 
 
@@ -96,36 +96,6 @@ abstract class Admin extends ContainerAware
 
     abstract public function getClassMetaData();
 
-    /**
-     * This method can be overwritten to tweak the FieldDescription linked to the form
-     *
-     * @return void
-     */
-    protected function configureFormFieldDescriptions()
-    {
-
-    }
-
-    /**
-     * This method can be overwritten to tweak the FieldDescription linked to the form
-     *
-     * @return void
-     */
-    protected function configureListFieldDescriptions()
-    {
-
-    }
-
-    /**
-     * This method can be overwritten to tweak the FieldDescription linked to the form
-     *
-     * @return void
-     */
-    protected function configureFilterFieldDescriptions()
-    {
-
-    }
-
     /**
      * This method can be overwritten to tweak the form construction, by default the form
      * is built by reading the FieldDescription
@@ -190,14 +160,17 @@ abstract class Admin extends ContainerAware
 
         // normalize field
         foreach ($this->listFieldDescriptions as $fieldDescription) {
+
             $this->getListBuilder()->fixFieldDescription($this, $fieldDescription);
         }
 
-        if (!isset($this->listFieldsDescription['_batch'])) {
+        if (!isset($this->listFieldDescriptions['_batch'])) {
+
             $fieldDescription = new FieldDescription();
             $fieldDescription->setOptions(array(
                 'label' => 'batch',
-                'code'  => '_batch'
+                'code'  => '_batch',
+                'type'  => 'batch',
             ));
             $fieldDescription->setTemplate('SonataBaseApplicationBundle:CRUD:list__batch.twig.html');
             $this->listFieldDescriptions = array( '_batch' => $fieldDescription ) + $this->listFieldDescriptions;
@@ -257,11 +230,6 @@ abstract class Admin extends ContainerAware
     static public function getBaseFields($metadata, $selectedFields)
     {
 
-        // if nothing is defined we display all fields
-        if (!$selectedFields) {
-            $selectedFields = array_keys($metadata->reflFields) + array_keys($metadata->associationMappings);
-        }
-
         $fields = array();
 
         // make sure we works with array
@@ -617,10 +585,10 @@ abstract class Admin extends ContainerAware
      * return a list depend on the given $object
      *
      * @param  $object
-     * @return Symfony\Component\Form\Form
+     * @return Symfony\Component\Datagrid\ListCollection
      */
     public function getList(array $options = array())
-    {
+    {   
 
         $list = $this->getListBuilder()->getBaseList($options);
 
@@ -645,7 +613,7 @@ abstract class Admin extends ContainerAware
      * return a list depend on the given $object
      *
      * @param  $object
-     * @return Symfony\Component\Form\Form
+     * @return Symfony\Component\Datagrid\Datagrid
      */
     public function getDatagrid()
     {

+ 2 - 2
Datagrid/ListMapper.php

@@ -42,7 +42,7 @@ class ListMapper
             $fieldDescription = $name;
             $fieldDescription->mergeOptions($fieldDescriptionOptions);
 
-        } else if (is_string($name) && !$this->admin->hasFormFieldDescription($name)) {
+        } else if (is_string($name) && !$this->admin->hasListFieldDescription($name)) {
 
             $fieldDescription = new FieldDescription;
             $fieldDescription->setOptions($fieldDescriptionOptions);
@@ -51,7 +51,7 @@ class ListMapper
             $this->listBuilder->fixFieldDescription($this->admin, $fieldDescription, $fieldDescriptionOptions);
             $this->admin->addListFieldDescription($name, $fieldDescription);
 
-        } else if (is_string($name) && $this->admin->hasFormFieldDescription($name)) {
+        } else if (is_string($name) && $this->admin->hasListFieldDescription($name)) {
             $fieldDescription = $this->admin->getFormFieldDescription($name);
         } else {
 

+ 5 - 6
Resources/views/CRUD/base_list.twig.html

@@ -26,11 +26,11 @@ file that was distributed with this source code.
         <table>
             {% block table_header %}
                 <tr>
-                    {% for field_description in list %}
+                    {% for field_description in list.elements %}
                         {% if field_description.getOption('code') == '_batch' %}
-                          <th class="sonata-ba-list-field-header sonata-ba-list-field-header-batch"><input type="checkbox" id="list_batch_checkbox" /></th>
+                            <th class="sonata-ba-list-field-header sonata-ba-list-field-header-batch"><input type="checkbox" id="list_batch_checkbox" /></th>
                         {% else %}
-                          <th class="sonata-ba-list-field-header sonata-ba-list-field-header-{{ field_description.type}}">{{ field_description.name }}</th>
+                            <th class="sonata-ba-list-field-header sonata-ba-list-field-header-{{ field_description.type}}">{{ field_description.name }}</th>
                         {% endif %}
                     {% endfor %}
                 </tr>
@@ -42,7 +42,7 @@ file that was distributed with this source code.
 
                 {% if datagrid.pager.haveToPaginate() %}
                     <tr>
-                        <td colspan="{{ list|length }}" class="pager">
+                        <td colspan="{{ list.elements|length }}" class="pager">
                             <ul>
                                 {% if datagrid.pager.page != datagrid.pager.previouspage %}
                                     <li><a href="{{ admin.generateUrl('list', datagrid.values|merge({'page': datagrid.pager.previouspage})) }}">{% trans 'link_previous_pager' from 'BaseApplicationBundle' %}</a></li>
@@ -66,6 +66,7 @@ file that was distributed with this source code.
                 {% endif %}
             {% endblock %}
         </table>
+        
         <script type="text/javascript">
             jQuery(document).ready(function($){
                $('#list_batch_checkbox').click(function(){
@@ -86,7 +87,6 @@ file that was distributed with this source code.
     </form>
 {% endblock %}
 
-
 {% block list_filters %}
     <form action="{{ admin.generateUrl('list') }}" method="GET">
         {% for filter in datagrid.filters %}
@@ -98,7 +98,6 @@ file that was distributed with this source code.
         <input type="submit" value="{% trans 'btn_filter' from 'BaseApplicationBundle' %}" />
 
         <a href="{{ admin.generateUrl('list') }}">{% trans 'link_reset_filter' from 'BaseApplicationBundle' %}</a>
-
     </form>
 {% endblock %}