base_list.html.twig 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. {#
  2. This file is part of the Sonata package.
  3. (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  4. For the full copyright and license information, please view the LICENSE
  5. file that was distributed with this source code.
  6. #}
  7. {% extends base_template %}
  8. {% block actions %}
  9. <div class="sonata-actions">
  10. {% include 'SonataAdminBundle:Core:create_button.html.twig' %}
  11. </div>
  12. {% endblock %}
  13. {% block side_menu %}{{ knp_menu_render(admin.sidemenu(action), {'currentClass' : 'active'}, 'list') }}{% endblock %}
  14. {% block list_table %}
  15. {% set batchactions = admin.batchactions %}
  16. {% if admin.datagrid.results|length > 0 %}
  17. <form action="{{ admin.generateUrl('batch', admin.filterParameters) }}" method="POST" >
  18. <table class="table table-bordered table-striped">
  19. {% block table_header %}
  20. <thead>
  21. <tr class="sonata-ba-list-field-header">
  22. {% for field_description in admin.list.elements %}
  23. {% if field_description.getOption('code') == '_batch' and batchactions|length > 0%}
  24. <th class="sonata-ba-list-field-header sonata-ba-list-field-header-batch">
  25. <input type="checkbox" id="list_batch_checkbox" />
  26. </th>
  27. {% else %}
  28. {% set sortable = false %}
  29. {% if field_description.options.sortable is defined and field_description.options.sortable%}
  30. {% set sortable = true %}
  31. {% set current = admin.datagrid.values._sort_by == field_description %}
  32. {% set sort_parameters = admin.modelmanager.sortparameters(field_description, admin.datagrid) %}
  33. {% set sort_active_class = current ? 'sonata-ba-list-field-order-active' : '' %}
  34. {% set sort_by = current ? admin.datagrid.values._sort_order : field_description.options._sort_order %}
  35. {% endif %}
  36. {% spaceless %}
  37. <th class="sonata-ba-list-field-header-{{ field_description.type}} {% if sortable %} sonata-ba-list-field-header-order-{{ sort_by|lower }} {{ sort_active_class }}{% endif %}">
  38. {% if sortable %}<a href="{{ admin.generateUrl('list', sort_parameters) }}">{% endif %}
  39. {{ admin.trans(field_description.label) }}
  40. {% if sortable %}</a>{% endif %}
  41. </th>
  42. {% endspaceless %}
  43. {% endif %}
  44. {% endfor %}
  45. </tr>
  46. </thead>
  47. {% endblock %}
  48. {% block table_body %}
  49. <tbody>
  50. {% for object in admin.datagrid.results %}
  51. <tr>
  52. {% for field_description in admin.list.elements %}
  53. {{ object|render_list_element(field_description) }}
  54. {% endfor %}
  55. </tr>
  56. {% endfor %}
  57. </tbody>
  58. {% endblock %}
  59. {% block table_footer %}
  60. <tr>
  61. <th colspan="{{ admin.list.elements|length - 1 }}">
  62. {{ admin.datagrid.pager.page }} / {{ admin.datagrid.pager.lastpage }}
  63. {% if admin.isGranted("EXPORT") and admin.getExportFormats()|length %}
  64. -
  65. {{ "label_export_download"|trans({}, "SonataAdminBundle") }}
  66. {% for format in admin.getExportFormats() %}
  67. <a href="{{ admin.generateUrl('export', admin.modelmanager.paginationparameters(admin.datagrid, 0) + {'format' : format}) }}">{{ format }}</a>{% if not loop.last%},{% endif %}
  68. {% endfor %}
  69. {% endif %}
  70. </th>
  71. <th>
  72. {% transchoice admin.datagrid.pager.nbresults with {'%count%': admin.datagrid.pager.nbresults} from 'SonataAdminBundle' %}list_results_count{% endtranschoice %}
  73. </th>
  74. </tr>
  75. {% if admin.datagrid.pager.haveToPaginate() %}
  76. <tr>
  77. <td colspan="{{ admin.list.elements|length }}">
  78. <div class="pagination pagination-centered">
  79. <ul>
  80. {% if admin.datagrid.pager.page != 1 %}
  81. <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, 1)) }}" title="{{ 'link_first_pager'|trans({}, 'SonataAdminBundle') }}">&laquo;</a></li>
  82. {% endif %}
  83. {% if admin.datagrid.pager.page != admin.datagrid.pager.previouspage %}
  84. <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, admin.datagrid.pager.previouspage)) }}" title="{{ 'link_previous_pager'|trans({}, 'SonataAdminBundle') }}">&lsaquo;</a></li>
  85. {% endif %}
  86. {# Set the number of pages to display in the pager #}
  87. {% for page in admin.datagrid.pager.getLinks() %}
  88. {% if page == admin.datagrid.pager.page %}
  89. <li class="active"><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, page)) }}">{{ page }}</a></li>
  90. {% else %}
  91. <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, page)) }}">{{ page }}</a></li>
  92. {% endif %}
  93. {% endfor %}
  94. {% if admin.datagrid.pager.page != admin.datagrid.pager.nextpage %}
  95. <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, admin.datagrid.pager.nextpage)) }}" title="{{ 'link_next_pager'|trans({}, 'SonataAdminBundle') }}">&rsaquo;</a></li>
  96. {% endif %}
  97. {% if admin.datagrid.pager.page != admin.datagrid.pager.lastpage %}
  98. <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, admin.datagrid.pager.lastpage)) }}" title="{{ 'link_last_pager'|trans({}, 'SonataAdminBundle') }}">&raquo;</a></li>
  99. {% endif %}
  100. </ul>
  101. </div>
  102. </td>
  103. </tr>
  104. {% endif %}
  105. {% endblock %}
  106. </table>
  107. {% if batchactions|length > 0%}
  108. {% block batch %}
  109. <script type="text/javascript">
  110. {% block batch_javascript %}
  111. jQuery(document).ready(function($){
  112. $('#list_batch_checkbox').click(function(){
  113. $(this).closest('table').find("td input[type='checkbox']").attr('checked', $(this).is(':checked')).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
  114. });
  115. $("td.sonata-ba-list-field-batch input[type='checkbox']").change(function(){
  116. $(this).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
  117. });
  118. });
  119. {% endblock %}
  120. </script>
  121. <div class="actions sonata-ba-list-actions">
  122. {% block batch_actions %}
  123. <select name="action">
  124. {% for action, options in batchactions %}
  125. <option value="{{ action }}">{{ options.label }}</option>
  126. {% endfor %}
  127. </select>
  128. <label class="checkbox">
  129. <input type="checkbox" name="all_elements"/>
  130. {{ 'all_elements'|trans({}, 'SonataAdminBundle') }}
  131. </label>
  132. <input type="submit" class="btn btn-primary" value="{{ 'btn_batch'|trans({}, 'SonataAdminBundle') }}" />
  133. {% endblock %}
  134. </div>
  135. {% endblock %}
  136. {% endif %}
  137. </form>
  138. {% else %}
  139. <p class="notice">
  140. {{ 'no_result'|trans({}, 'SonataAdminBundle') }}
  141. </p>
  142. {% endif %}
  143. {% endblock %}
  144. {% block list_filters %}
  145. {% if admin.datagrid.filters %}
  146. <form class="sonata-filter-form {{ admin.isChild and 1 == admin.datagrid.filters|length ? 'hide' : '' }}" action="{{ admin.generateUrl('list') }}" method="GET">
  147. <fieldset class="filter_legend">
  148. <legend class="filter_legend {{ admin.datagrid.hasActiveFilters ? 'active' : 'inactive' }}">{{ 'label_filters'|trans({}, 'SonataAdminBundle') }}</legend>
  149. <div class="filter_container {{ admin.datagrid.hasActiveFilters ? 'active' : 'inactive' }}">
  150. <table class="table table-bordered">
  151. {% for filter in admin.datagrid.filters %}
  152. <tr id="filter_{{ filter.name }}_row" class="filter {{ filter.isActive ? 'active' : 'inactive' }}">
  153. <td class="filter-title">{{ admin.trans(filter.label) }}</td>
  154. <td class="filter-type">{{ form_widget(form.children[filter.formName].children['type']) }}</td>
  155. <td class="filter-value">{{ form_widget(form.children[filter.formName].children['value']) }}</td>
  156. </tr>
  157. {% endfor %}
  158. </table>
  159. <input type="hidden" name="filter[_page]" id="filter__page" value="1" />
  160. {% set foo = form.children['_page'].setRendered() %}
  161. {{ form_rest(form) }}
  162. <input type="submit" class="btn btn-primary" value="{{ 'btn_filter'|trans({}, 'SonataAdminBundle') }}" />
  163. <a class="btn" href="{{ admin.generateUrl('list', {filters: 'reset'}) }}">{{ 'link_reset_filter'|trans({}, 'SonataAdminBundle') }}</a>
  164. </div>
  165. </fieldset>
  166. </form>
  167. {% endif %}
  168. {% endblock %}