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

Merge branch '2.1'

Conflicts:
	Resources/views/CRUD/base_list.html.twig
Thomas Rabaix пре 12 година
родитељ
комит
5594a79276

+ 4 - 1
Admin/FieldDescriptionCollection.php

@@ -117,7 +117,10 @@ class FieldDescriptionCollection implements \ArrayAccess, \Countable
      */
     public function reorder(array $keys)
     {
-        array_unshift($keys, 'batch');
+        if ($this->has('batch')) {
+            array_unshift($keys, 'batch');
+        }
+
         $this->elements = array_merge(array_flip($keys), $this->elements);
     }
 }

+ 4 - 4
Resources/doc/reference/architecture.rst

@@ -106,7 +106,7 @@ Obtaining an ``Admin`` Service
 ------------------------------
 
 ``Admin`` definitions are accessible through the ``sonata.admin.pool`` service or
-directly from the DIC (dependency injection container). The ``Admin`` definitions 
+directly from the DIC (dependency injection container). The ``Admin`` definitions
 are lazy-loaded from the DIC to reduce overhead.
 
 Declaring a new Admin class
@@ -154,8 +154,8 @@ Or if you're using a YML configuration file,
 You can extend ``Sonata\AdminBundle\Admin\Admin`` class to minimize the amount of
 code to write. This base admin class uses the routing services to build routes.
 Note that you can use both the Bundle:Controller format or a `service name`_ to
-specify what controller to load.
-
+specify what controller to load. If you provide null instead of SonataNewsBundle:PostAdmin,
+you will not need to create a controller class and the system will use the default.
 
 .. _`Django Project Website`: http://www.djangoproject.com/
-.. _`service name`: http://symfony.com/doc/2.0/cookbook/controller/service.html
+.. _`service name`: http://symfony.com/doc/2.1/cookbook/controller/service.html

+ 1 - 1
Resources/translations/SonataAdminBundle.de.xliff

@@ -180,7 +180,7 @@
             </trans-unit>
             <trans-unit id="message_delete_confirmation">
                 <source>message_delete_confirmation</source>
-                <target>Sind Sie sicher dass Sie das ausgewählte Element löschen wollen?</target>
+                <target>Sind Sie sicher, dass Sie das ausgewählte Element löschen wollen?</target>
             </trans-unit>
             <trans-unit id="btn_delete">
                 <source>btn_delete</source>

+ 4 - 1
Resources/views/CRUD/base_edit_form.html.twig

@@ -57,7 +57,10 @@
                         {% endif %}
                         {% if admin.id(object) %}
                             <input type="submit" class="btn btn-primary" name="btn_update_and_edit" value="{{ 'btn_update_and_edit_again'|trans({}, 'SonataAdminBundle') }}"/>
-                            <input type="submit" class="btn" name="btn_update_and_list" value="{{ 'btn_update_and_return_to_list'|trans({}, 'SonataAdminBundle') }}"/>
+                            
+                            {% if admin.hasroute('list') %}
+                                <input type="submit" class="btn" name="btn_update_and_list" value="{{ 'btn_update_and_return_to_list'|trans({}, 'SonataAdminBundle') }}"/>
+                            {% endif %}                            
 
                             {% if admin.hasroute('delete') and admin.isGranted('DELETE', object) %}
                                 {{ 'delete_or'|trans({}, 'SonataAdminBundle') }}

+ 53 - 52
Resources/views/CRUD/base_list.html.twig

@@ -77,64 +77,65 @@ file that was distributed with this source code.
                     <tr>
                         <th colspan="{{ admin.list.elements|length - (app.request.isXmlHttpRequest ? 2 : 0) }}">
                             <div class="form-inline">
-                                {% if not app.request.isXmlHttpRequest and batchactions|length > 0 %}
-                                    {% block batch %}
-                                        <script type="text/javascript">
-                                            {% block batch_javascript %}
-                                            jQuery(document).ready(function ($) {
-                                                $('#list_batch_checkbox').click(function () {
-                                                    $(this).closest('table').find("td input[type='checkbox']").attr('checked', $(this).is(':checked')).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
-                                                });
-                                                $("td.sonata-ba-list-field-batch input[type='checkbox']").change(function () {
-                                                    $(this).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
-                                                });
-                                            });
-                                            {% endblock %}
-                                        </script>
-
-                                        {% block batch_actions %}
-                                            <label class="checkbox" for="{{ admin.uniqid }}_all_elements">
-                                                <input type="checkbox" name="all_elements" id="{{ admin.uniqid }}_all_elements"/>
-                                                {{ 'all_elements'|trans({}, 'SonataAdminBundle') }}
-                                            </label>
-
-                                            <select name="action" style="width: auto; height: auto">
-                                                {% for action, options in batchactions %}
-                                                    <option value="{{ action }}">{{ options.label }}</option>
-                                                {% endfor %}
-                                            </select>
-
-                                            <input type="submit" class="btn btn-small btn-primary" value="{{ 'btn_batch'|trans({}, 'SonataAdminBundle') }}"/>
-                                            <div class="pull-right">
-                                                {% if admin.hasRoute('export') and admin.isGranted("EXPORT") and admin.getExportFormats()|length %}
-                                                    {{ "label_export_download"|trans({}, "SonataAdminBundle") }}
-                                                    {% for format in admin.getExportFormats() %}
-                                                        <a href="{{ admin.generateUrl('export', admin.modelmanager.paginationparameters(admin.datagrid, 0) + {'format' : format}) }}">{{ format }}</a>{% if not loop.last %},{% endif %}
+                                {% if not app.request.isXmlHttpRequest %}
+                                    {% if batchactions|length > 0  %}
+                                        {% block batch %}
+                                            <script type="text/javascript">
+                                                {% block batch_javascript %}
+                                                    jQuery(document).ready(function ($) {
+                                                        $('#list_batch_checkbox').click(function () {
+                                                            $(this).closest('table').find("td input[type='checkbox']").attr('checked', $(this).is(':checked')).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
+                                                        });
+                                                        $("td.sonata-ba-list-field-batch input[type='checkbox']").change(function () {
+                                                            $(this).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
+                                                        });
+                                                    });
+                                                {% endblock %}
+                                            </script>
+
+                                            {% block batch_actions %}
+                                                <label class="checkbox" for="{{ admin.uniqid }}_all_elements">
+                                                    <input type="checkbox" name="all_elements" id="{{ admin.uniqid }}_all_elements"/>
+                                                    {{ 'all_elements'|trans({}, 'SonataAdminBundle') }}
+                                                </label>
+
+                                                <select name="action" style="width: auto; height: auto">
+                                                    {% for action, options in batchactions %}
+                                                        <option value="{{ action }}">{{ options.label }}</option>
                                                     {% endfor %}
+                                                </select>
+                                            {% endblock %}
+                                        {% endblock %}
+
+                                        <input type="submit" class="btn btn-small btn-primary" value="{{ 'btn_batch'|trans({}, 'SonataAdminBundle') }}"/>
+                                    {% endif %}
+
+                                    <div class="pull-right">
+                                        {% if admin.hasRoute('export') and admin.isGranted("EXPORT") and admin.getExportFormats()|length %}
+                                            {{ "label_export_download"|trans({}, "SonataAdminBundle") }}
+                                            {% for format in admin.getExportFormats() %}
+                                                <a href="{{ admin.generateUrl('export', admin.modelmanager.paginationparameters(admin.datagrid, 0) + {'format' : format}) }}">{{ format }}</a>{% if not loop.last %},{% endif %}
+                                            {% endfor %}
 
-                                                    &nbsp;-&nbsp;
-                                                {% endif %}
+                                            &nbsp;-&nbsp;
+                                        {% endif %}
 
-                                                {{ admin.datagrid.pager.page }} / {{ admin.datagrid.pager.lastpage }}
+                                        {{ admin.datagrid.pager.page }} / {{ admin.datagrid.pager.lastpage }}
 
-                                                &nbsp;-&nbsp;
+                                        &nbsp;-&nbsp;
 
-                                                {% transchoice admin.datagrid.pager.nbresults with {'%count%': admin.datagrid.pager.nbresults} from 'SonataAdminBundle' %}list_results_count{% endtranschoice %}
+                                        {% transchoice admin.datagrid.pager.nbresults with {'%count%': admin.datagrid.pager.nbresults} from 'SonataAdminBundle' %}list_results_count{% endtranschoice %}
 
-                                                {% if not app.request.isXmlHttpRequest %}
-                                                    &nbsp;-&nbsp;
-                                                    <label class="control-label" for="{{ admin.uniqid }}_per_page">{% trans from 'SonataAdminBundle' %}label_per_page{% endtrans %}</label>
-                                                    <select class="per-page small" id="{{ admin.uniqid }}_per_page" style="width: auto; height: auto">
-                                                        {% for per_page in admin.getperpageoptions %}
-                                                            <option {% if per_page == admin.datagrid.pager.maxperpage %}selected="selected"{% endif %} value="{{ admin.generateUrl('list', {'filter': admin.datagrid.values | merge({'_per_page': per_page})}) }}">
-                                                                {{ per_page }}
-                                                            </option>
-                                                        {% endfor %}
-                                                    </select>
-                                                {% endif %}
-                                            </div>
-                                        {% endblock %}
-                                    {% endblock %}
+                                        &nbsp;-&nbsp;
+                                        <label class="control-label" for="{{ admin.uniqid }}_per_page">{% trans from 'SonataAdminBundle' %}label_per_page{% endtrans %}</label>
+                                        <select class="per-page small" id="{{ admin.uniqid }}_per_page" style="width: auto; height: auto">
+                                            {% for per_page in admin.getperpageoptions %}
+                                                <option {% if per_page == admin.datagrid.pager.maxperpage %}selected="selected"{% endif %} value="{{ admin.generateUrl('list', {'filter': admin.datagrid.values | merge({'_per_page': per_page})}) }}">
+                                                    {{ per_page }}
+                                                </option>
+                                            {% endfor %}
+                                        </select>
+                                    </div>
                                 {% endif %}
                             </div>
                         </th>

+ 44 - 1
Tests/Admin/FieldDescriptionCollectionTest.php

@@ -68,4 +68,47 @@ class FieldDescriptionCollectionTest extends \PHPUnit_Framework_TestCase
 
         $collection['foo'] = null;
     }
-}
+
+    public function testReorderListWithoutBatchField()
+    {
+        $collection = new FieldDescriptionCollection();
+
+        $fieldDescription = $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
+        $fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('title'));
+        $collection->add($fieldDescription);
+
+        $fieldDescription = $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
+        $fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('position'));
+        $collection->add($fieldDescription);
+
+        $newOrder = array('position', 'title');
+        $collection->reorder($newOrder);
+
+        $actualElements = array_keys($collection->getElements());
+        $this->assertSame($newOrder, $actualElements, 'the order is wrong');
+    }
+
+    public function testReorderListWithBatchField()
+    {
+        $collection = new FieldDescriptionCollection();
+
+        $fieldDescription = $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
+        $fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('title'));
+        $collection->add($fieldDescription);
+
+        $fieldDescription = $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
+        $fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('position'));
+        $collection->add($fieldDescription);
+
+        $fieldDescription = $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
+        $fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('batch'));
+        $collection->add($fieldDescription);
+
+        $newOrder = array('position', 'title');
+        $collection->reorder($newOrder);
+        array_unshift($newOrder, 'batch');
+
+        $actualElements = array_keys($collection->getElements());
+        $this->assertSame($newOrder, $actualElements, 'the order is wrong');
+    }
+}