Sfoglia il codice sorgente

Fix issue #122 - Dont show batch checkboxs if no batch actions present

Thomas Rabaix 14 anni fa
parent
commit
445832ed3c
2 ha cambiato i file con 26 aggiunte e 23 eliminazioni
  1. 3 3
      Admin/Admin.php
  2. 23 20
      Resources/views/CRUD/base_list.html.twig

+ 3 - 3
Admin/Admin.php

@@ -454,7 +454,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
             $this->getListBuilder()->fixFieldDescription($this, $fieldDescription);
         }
 
-        if (!isset($this->listFieldDescriptions['_batch'])) {
+        if (!isset($this->listFieldDescriptions['_batch']) && count($this->getBatchActions()) > 0) {
             $fieldDescription = $this->modelManager->getNewFieldDescriptionInstance($this->getClass(), 'batch', array(
                 'label'    => 'batch',
                 'code'     => '_batch',
@@ -1867,7 +1867,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
     }
 
     /**
-     * @param string $name
+     * @param string $names
      * @return boolean
      */
     public function isGranted($names)
@@ -1876,7 +1876,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
             $names = (array) $names;
         }
 
-        foreach($names as $name) {
+        foreach ($names as $name) {
             if (true === $this->securityContext->isGranted($name, $this)) {
                 return true;
             }

+ 23 - 20
Resources/views/CRUD/base_list.html.twig

@@ -24,13 +24,14 @@ file that was distributed with this source code.
 {% block side_menu %}{{ admin.sidemenu(action).render|raw }}{% endblock %}
 
 {% block list_table %}
+    {% set batchactions = admin.batchactions %}
     {% if admin.datagrid.results|length > 0 %}
         <form action="{{ admin.generateUrl('batch') }}" method="POST" >
             <table>
                 {% block table_header %}
                     <tr class="sonata-ba-list-field-header">
                         {% for field_description in admin.list.elements %}
-                            {% if field_description.getOption('code') == '_batch' %}
+                            {% if field_description.getOption('code') == '_batch' and batchactions|length > 0%}
                                 <th class="sonata-ba-list-field-header sonata-ba-list-field-header-batch">
                                   <input type="checkbox" id="list_batch_checkbox" />
                                 </th>
@@ -100,25 +101,27 @@ file that was distributed with this source code.
                 {% endblock %}
             </table>
 
-            <script type="text/javascript">
-                jQuery(document).ready(function($){
-                   $('#list_batch_checkbox').click(function(){
-                       $(this).closest('table').find("td input[type='checkbox']").attr('checked', $(this).is(':checked'));
-                   });
-                   $('.delete_link').click(function(e){
-                      if (!confirm('{% trans from 'SonataAdminBundle' %}confirm_msg{% endtrans %}')) e.preventDefault();
-                   });
-                });
-            </script>
-
-            <div class="sonata-ba-list-actions">
-                <select name="action">
-                    {% for action, label in admin.batchactions %}
-                        <option value="{{ action }}">{{ label }}</option>
-                    {% endfor %}
-                </select>
-                <input type="submit" value="{% trans from 'SonataAdminBundle' %}btn_batch{% endtrans %}" />
-            </div>
+            {% if batchactions|length > 0%}
+                <script type="text/javascript">
+                    jQuery(document).ready(function($){
+                       $('#list_batch_checkbox').click(function(){
+                           $(this).closest('table').find("td input[type='checkbox']").attr('checked', $(this).is(':checked'));
+                       });
+                       $('.delete_link').click(function(e){
+                          if (!confirm('{% trans from 'SonataAdminBundle' %}confirm_msg{% endtrans %}')) e.preventDefault();
+                       });
+                    });
+                </script>
+
+                <div class="sonata-ba-list-actions">
+                    <select name="action">
+                        {% for action, label in batchactions %}
+                            <option value="{{ action }}">{{ label }}</option>
+                        {% endfor %}
+                    </select>
+                    <input type="submit" value="{% trans from 'SonataAdminBundle' %}btn_batch{% endtrans %}" />
+                </div>
+            {% endif %}
         </form>
     {% else %}
         <p class="notice">