base_list.html.twig 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 btn-group">
  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. {% if admin.hasRoute('batch') %}
  18. <form action="{{ admin.generateUrl('batch', {'filter': admin.filterParameters}) }}" method="POST" >
  19. {% endif %}
  20. <table class="table table-bordered table-striped">
  21. {% block table_header %}
  22. <thead>
  23. <tr class="sonata-ba-list-field-header">
  24. {% for field_description in admin.list.elements %}
  25. {% if admin.hasRoute('batch') and field_description.getOption('code') == '_batch' and batchactions|length > 0 %}
  26. <th class="sonata-ba-list-field-header sonata-ba-list-field-header-batch">
  27. <input type="checkbox" id="list_batch_checkbox" />
  28. </th>
  29. {% elseif field_description.getOption('code') == '_select' %}
  30. <th class="sonata-ba-list-field-header sonata-ba-list-field-header-select"></th>
  31. {% elseif field_description.name == '_action' and app.request.isXmlHttpRequest %}
  32. {# Action buttons disabled in ajax view! #}
  33. {% else %}
  34. {% set sortable = false %}
  35. {% if field_description.options.sortable is defined and field_description.options.sortable%}
  36. {% set sortable = true %}
  37. {% set current = admin.datagrid.values._sort_by == field_description %}
  38. {% set sort_parameters = admin.modelmanager.sortparameters(field_description, admin.datagrid) %}
  39. {% set sort_active_class = current ? 'sonata-ba-list-field-order-active' : '' %}
  40. {% set sort_by = current ? admin.datagrid.values._sort_order : field_description.options._sort_order %}
  41. {% endif %}
  42. {% spaceless %}
  43. <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 %}">
  44. {% if sortable %}<a href="{{ admin.generateUrl('list', sort_parameters) }}">{% endif %}
  45. {{ admin.trans(field_description.label) }}
  46. {% if sortable %}</a>{% endif %}
  47. </th>
  48. {% endspaceless %}
  49. {% endif %}
  50. {% endfor %}
  51. </tr>
  52. </thead>
  53. {% endblock %}
  54. {% block table_body %}
  55. <tbody>
  56. {% for object in admin.datagrid.results %}
  57. <tr>
  58. {% include admin.getTemplate('inner_list_row') %}
  59. </tr>
  60. {% endfor %}
  61. </tbody>
  62. {% endblock %}
  63. {% block table_footer %}
  64. <tr>
  65. <th colspan="{{ admin.list.elements|length - (app.request.isXmlHttpRequest ? (admin.list.has('_action') + admin.list.has('batch')) : 0) }}">
  66. <div class="form-inline">
  67. {% if not app.request.isXmlHttpRequest %}
  68. {% if admin.hasRoute('batch') and batchactions|length > 0 %}
  69. {% block batch %}
  70. <script type="text/javascript">
  71. {% block batch_javascript %}
  72. jQuery(document).ready(function ($) {
  73. $('#list_batch_checkbox').click(function () {
  74. $(this).closest('table').find("td input[type='checkbox']").attr('checked', $(this).is(':checked')).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
  75. });
  76. $("td.sonata-ba-list-field-batch input[type='checkbox']").change(function () {
  77. $(this).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
  78. });
  79. });
  80. {% endblock %}
  81. </script>
  82. {% block batch_actions %}
  83. <label class="checkbox" for="{{ admin.uniqid }}_all_elements">
  84. <input type="checkbox" name="all_elements" id="{{ admin.uniqid }}_all_elements"/>
  85. {{ 'all_elements'|trans({}, 'SonataAdminBundle') }}
  86. </label>
  87. <select name="action" style="width: auto; height: auto">
  88. {% for action, options in batchactions %}
  89. <option value="{{ action }}">{{ options.label }}</option>
  90. {% endfor %}
  91. </select>
  92. {% endblock %}
  93. {% endblock %}
  94. <input type="submit" class="btn btn-small btn-primary" value="{{ 'btn_batch'|trans({}, 'SonataAdminBundle') }}"/>
  95. {% endif %}
  96. <div class="pull-right">
  97. {% if admin.hasRoute('export') and admin.isGranted("EXPORT") and admin.getExportFormats()|length %}
  98. {{ "label_export_download"|trans({}, "SonataAdminBundle") }}
  99. {% for format in admin.getExportFormats() %}
  100. <a href="{{ admin.generateUrl('export', admin.modelmanager.paginationparameters(admin.datagrid, 0) + {'format' : format}) }}">{{ format }}</a>{% if not loop.last %},{% endif %}
  101. {% endfor %}
  102. &nbsp;-&nbsp;
  103. {% endif %}
  104. {{ admin.datagrid.pager.page }} / {{ admin.datagrid.pager.lastpage }}
  105. &nbsp;-&nbsp;
  106. {% transchoice admin.datagrid.pager.nbresults with {'%count%': admin.datagrid.pager.nbresults} from 'SonataAdminBundle' %}list_results_count{% endtranschoice %}
  107. &nbsp;-&nbsp;
  108. <label class="control-label" for="{{ admin.uniqid }}_per_page">{% trans from 'SonataAdminBundle' %}label_per_page{% endtrans %}</label>
  109. <select class="per-page small" id="{{ admin.uniqid }}_per_page" style="width: auto; height: auto">
  110. {% for per_page in admin.getperpageoptions %}
  111. <option {% if per_page == admin.datagrid.pager.maxperpage %}selected="selected"{% endif %} value="{{ admin.generateUrl('list', {'filter': admin.datagrid.values | merge({'_per_page': per_page})}) }}">
  112. {{ per_page }}
  113. </option>
  114. {% endfor %}
  115. </select>
  116. </div>
  117. {% endif %}
  118. </div>
  119. </th>
  120. </tr>
  121. {% if admin.datagrid.pager.haveToPaginate() %}
  122. <tr>
  123. <td colspan="{{ admin.list.elements|length }}">
  124. <div class="pagination pagination-centered">
  125. <ul>
  126. {% if admin.datagrid.pager.page > 2 %}
  127. <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, 1)) }}" title="{{ 'link_first_pager'|trans({}, 'SonataAdminBundle') }}">&laquo;</a></li>
  128. {% endif %}
  129. {% if admin.datagrid.pager.page != admin.datagrid.pager.previouspage %}
  130. <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, admin.datagrid.pager.previouspage)) }}" title="{{ 'link_previous_pager'|trans({}, 'SonataAdminBundle') }}">&lsaquo;</a></li>
  131. {% endif %}
  132. {# Set the number of pages to display in the pager #}
  133. {% for page in admin.datagrid.pager.getLinks() %}
  134. {% if page == admin.datagrid.pager.page %}
  135. <li class="active"><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, page)) }}">{{ page }}</a></li>
  136. {% else %}
  137. <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, page)) }}">{{ page }}</a></li>
  138. {% endif %}
  139. {% endfor %}
  140. {% if admin.datagrid.pager.page != admin.datagrid.pager.nextpage %}
  141. <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, admin.datagrid.pager.nextpage)) }}" title="{{ 'link_next_pager'|trans({}, 'SonataAdminBundle') }}">&rsaquo;</a></li>
  142. {% endif %}
  143. {% if admin.datagrid.pager.page != admin.datagrid.pager.lastpage and admin.datagrid.pager.lastpage != admin.datagrid.pager.nextpage %}
  144. <li><a href="{{ admin.generateUrl('list', admin.modelmanager.paginationparameters(admin.datagrid, admin.datagrid.pager.lastpage)) }}" title="{{ 'link_last_pager'|trans({}, 'SonataAdminBundle') }}">&raquo;</a></li>
  145. {% endif %}
  146. </ul>
  147. </div>
  148. </td>
  149. </tr>
  150. {% endif %}
  151. {% endblock %}
  152. </table>
  153. {% if admin.hasRoute('batch') %}
  154. </form>
  155. {% endif %}
  156. {% else %}
  157. <p class="notice">
  158. {{ 'no_result'|trans({}, 'SonataAdminBundle') }}
  159. </p>
  160. {% endif %}
  161. {% endblock %}
  162. {% block list_filters %}
  163. {% if admin.datagrid.filters %}
  164. <form class="sonata-filter-form {{ admin.isChild and 1 == admin.datagrid.filters|length ? 'hide' : '' }}" action="{{ admin.generateUrl('list') }}" method="GET">
  165. <fieldset class="filter_legend">
  166. <legend class="filter_legend {{ admin.datagrid.hasActiveFilters ? 'active' : 'inactive' }}">{{ 'label_filters'|trans({}, 'SonataAdminBundle') }}</legend>
  167. <div class="filter_container {{ admin.datagrid.hasActiveFilters ? 'active' : 'inactive' }}">
  168. <div>
  169. {% for filter in admin.datagrid.filters %}
  170. <div class="clearfix">
  171. <label for="{{ form.children[filter.formName].children['value'].vars.id }}">{{ admin.trans(filter.label) }}</label>
  172. {{ form_widget(form.children[filter.formName].children['type'], {'attr': {'class': 'span8 sonata-filter-option'}}) }}
  173. {{ form_widget(form.children[filter.formName].children['value'], {'attr': {'class': 'span8'}}) }}
  174. </div>
  175. {% endfor %}
  176. </div>
  177. <input type="hidden" name="filter[_page]" id="filter__page" value="1" />
  178. {% set foo = form.children['_page'].setRendered() %}
  179. {{ form_rest(form) }}
  180. <input type="submit" class="btn btn-primary" value="{{ 'btn_filter'|trans({}, 'SonataAdminBundle') }}" />
  181. <a class="btn" href="{{ admin.generateUrl('list', {filters: 'reset'}) }}">{{ 'link_reset_filter'|trans({}, 'SonataAdminBundle') }}</a>
  182. </div>
  183. </fieldset>
  184. </form>
  185. {% endif %}
  186. {% endblock %}