ソースを参照

Moved the pager html to seperate templates

Sjoerd Peters 12 年 前
コミット
8a7006422d

+ 2 - 0
DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php

@@ -276,6 +276,8 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
             'batch_confirmation'       => 'SonataAdminBundle:CRUD:batch_confirmation.html.twig',
             'inner_list_row'           => 'SonataAdminBundle:CRUD:list_inner_row.html.twig',
             'base_list_field'          => 'SonataAdminBundle:CRUD:base_list_field.html.twig',
+            'pager_links'              => 'SonataAdminBundle:Pager:links.html.twig',
+            'pager_results'            => 'SonataAdminBundle:Pager:results.html.twig',
         ), $definedTemplates);
 
         $definition->addMethodCall('setTemplates', array($definedTemplates));

+ 2 - 0
DependencyInjection/Configuration.php

@@ -158,6 +158,8 @@ class Configuration implements ConfigurationInterface
                         ->scalarNode('batch_confirmation')->defaultValue('SonataAdminBundle:CRUD:batch_confirmation.html.twig')->cannotBeEmpty()->end()
                         ->scalarNode('inner_list_row')->defaultValue('SonataAdminBundle:CRUD:list_inner_row.html.twig')->cannotBeEmpty()->end()
                         ->scalarNode('base_list_field')->defaultValue('SonataAdminBundle:CRUD:base_list_field.html.twig')->cannotBeEmpty()->end()
+                        ->scalarNode('pager_links')->defaultValue('SonataAdminBundle:Pager:links.html.twig')->cannotBeEmpty()->end()
+                        ->scalarNode('pager_results')->defaultValue('SonataAdminBundle:Pager:results.html.twig')->cannotBeEmpty()->end()
                     ->end()
                 ->end()
 

+ 8 - 47
Resources/views/CRUD/base_list.html.twig

@@ -118,60 +118,21 @@ file that was distributed with this source code.
                                              - 
                                         {% endif %}
 
-                                        {{ admin.datagrid.pager.page }} / {{ admin.datagrid.pager.lastpage }}
-
-                                         - 
-
-                                        {% transchoice admin.datagrid.pager.nbresults with {'%count%': admin.datagrid.pager.nbresults} from 'SonataAdminBundle' %}list_results_count{% endtranschoice %}
-
-                                         - 
-                                        <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>
+                                        {% block pager_results %}
+                                            {% include admin.getTemplate('pager_results') %}
+                                        {% endblock %}
                                     </div>
                                 {% endif %}
                             </div>
                         </th>
                     </tr>
-                    {% if admin.datagrid.pager.haveToPaginate() %}
-                        <tr>
-                            <td colspan="{{ admin.list.elements|length }}">
-                                <div class="pagination pagination-centered">
-                                    <ul>
-                                        {% if admin.datagrid.pager.page > 2  %}
-                                            <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, 1)) }}" title="{{ 'link_first_pager'|trans({}, 'SonataAdminBundle') }}">&laquo;</a></li>
-                                        {% endif %}
 
-                                        {% if admin.datagrid.pager.page != admin.datagrid.pager.previouspage %}
-                                            <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, admin.datagrid.pager.previouspage)) }}" title="{{ 'link_previous_pager'|trans({}, 'SonataAdminBundle') }}">&lsaquo;</a></li>
-                                        {% endif %}
-
-                                        {# Set the number of pages to display in the pager #}
-                                        {% for page in admin.datagrid.pager.getLinks() %}
-                                            {% if page == admin.datagrid.pager.page %}
-                                                <li class="active"><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, page)) }}">{{ page }}</a></li>
-                                            {% else %}
-                                                <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, page)) }}">{{ page }}</a></li>
-                                            {% endif %}
-                                        {% endfor %}
-
-                                        {% if admin.datagrid.pager.page != admin.datagrid.pager.nextpage %}
-                                            <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, admin.datagrid.pager.nextpage)) }}" title="{{ 'link_next_pager'|trans({}, 'SonataAdminBundle') }}">&rsaquo;</a></li>
-                                        {% endif %}
+                    {% block pager_links %}
+                        {% if admin.datagrid.pager.haveToPaginate() %}
+                            {% include admin.getTemplate('pager_links') %}
+                        {% endif %}
+                    {% endblock %}
 
-                                        {% if admin.datagrid.pager.page != admin.datagrid.pager.lastpage and admin.datagrid.pager.lastpage != admin.datagrid.pager.nextpage %}
-                                            <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, admin.datagrid.pager.lastpage)) }}" title="{{ 'link_last_pager'|trans({}, 'SonataAdminBundle') }}">&raquo;</a></li>
-                                        {% endif %}
-                                    </ul>
-                                </div>
-                            </td>
-                        </tr>
-                    {% endif %}
                 {% endblock %}
             </table>
         {% if admin.hasRoute('batch') %}

+ 43 - 0
Resources/views/Pager/base_links.html.twig

@@ -0,0 +1,43 @@
+{#
+
+This file is part of the Sonata package.
+
+(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+
+For the full copyright and license information, please view the LICENSE
+file that was distributed with this source code.
+
+#}
+
+<tr>
+    <td colspan="{{ admin.list.elements|length }}">
+        <div class="pagination pagination-centered">
+            <ul>
+                {% if admin.datagrid.pager.page > 2  %}
+                    <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, 1)) }}" title="{{ 'link_first_pager'|trans({}, 'SonataAdminBundle') }}">&laquo;</a></li>
+                {% endif %}
+
+                {% if admin.datagrid.pager.page != admin.datagrid.pager.previouspage %}
+                    <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, admin.datagrid.pager.previouspage)) }}" title="{{ 'link_previous_pager'|trans({}, 'SonataAdminBundle') }}">&lsaquo;</a></li>
+                {% endif %}
+
+                {# Set the number of pages to display in the pager #}
+                {% for page in admin.datagrid.pager.getLinks() %}
+                    {% if page == admin.datagrid.pager.page %}
+                        <li class="active"><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, page)) }}">{{ page }}</a></li>
+                    {% else %}
+                        <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, page)) }}">{{ page }}</a></li>
+                    {% endif %}
+                {% endfor %}
+
+                {% if admin.datagrid.pager.page != admin.datagrid.pager.nextpage %}
+                    <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, admin.datagrid.pager.nextpage)) }}" title="{{ 'link_next_pager'|trans({}, 'SonataAdminBundle') }}">&rsaquo;</a></li>
+                {% endif %}
+
+                {% if admin.datagrid.pager.page != admin.datagrid.pager.lastpage and admin.datagrid.pager.lastpage != admin.datagrid.pager.nextpage %}
+                    <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, admin.datagrid.pager.lastpage)) }}" title="{{ 'link_last_pager'|trans({}, 'SonataAdminBundle') }}">&raquo;</a></li>
+                {% endif %}
+            </ul>
+        </div>
+    </td>
+</tr>

+ 31 - 0
Resources/views/Pager/base_results.html.twig

@@ -0,0 +1,31 @@
+{#
+
+This file is part of the Sonata package.
+
+(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+
+For the full copyright and license information, please view the LICENSE
+file that was distributed with this source code.
+
+#}
+
+{% block num_pages %}
+    {{ admin.datagrid.pager.page }} / {{ admin.datagrid.pager.lastpage }}
+    &nbsp;-&nbsp;
+{% endblock %}
+
+{% block num_results %}
+    {% transchoice admin.datagrid.pager.nbresults with {'%count%': admin.datagrid.pager.nbresults} from 'SonataAdminBundle' %}list_results_count{% endtranschoice %}
+    &nbsp;-&nbsp;
+{% endblock %}
+
+{% block max_per_page %}
+    <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>
+{% endblock %}

+ 12 - 0
Resources/views/Pager/links.html.twig

@@ -0,0 +1,12 @@
+{#
+
+This file is part of the Sonata package.
+
+(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+
+For the full copyright and license information, please view the LICENSE
+file that was distributed with this source code.
+
+#}
+
+{% extends 'SonataAdminBundle:Pager:base_links.html.twig' %}

+ 12 - 0
Resources/views/Pager/results.html.twig

@@ -0,0 +1,12 @@
+{#
+
+This file is part of the Sonata package.
+
+(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+
+For the full copyright and license information, please view the LICENSE
+file that was distributed with this source code.
+
+#}
+
+{% extends 'SonataAdminBundle:Pager:base_results.html.twig' %}