base_list.html.twig 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. <li>{% include 'SonataAdminBundle:Core:create_button.html.twig' %}</li>
  10. {% endblock %}
  11. {% block tab_menu %}{{ knp_menu_render(admin.sidemenu(action), {'currentClass' : 'active'}, 'list') }}{% endblock %}
  12. {% block list_table %}
  13. {{ sonata_block_render_event('sonata.admin.list.table.top', { 'admin': admin }) }}
  14. {% block list_header %}{% endblock %}
  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. <input type="hidden" name="_sonata_csrf_token" value="{{ csrf_token }}">
  20. {% endif %}
  21. <table class="table table-bordered table-striped">
  22. {% block table_header %}
  23. <thead>
  24. <tr class="sonata-ba-list-field-header">
  25. {% for field_description in admin.list.elements %}
  26. {% if admin.hasRoute('batch') and field_description.getOption('code') == '_batch' and batchactions|length > 0 %}
  27. <th class="sonata-ba-list-field-header sonata-ba-list-field-header-batch">
  28. <input type="checkbox" id="list_batch_checkbox">
  29. </th>
  30. {% elseif field_description.getOption('code') == '_select' %}
  31. <th class="sonata-ba-list-field-header sonata-ba-list-field-header-select"></th>
  32. {% elseif field_description.name == '_action' and app.request.isXmlHttpRequest %}
  33. {# Action buttons disabled in ajax view! #}
  34. {% elseif field_description.getOption('ajax_hidden') == true and app.request.isXmlHttpRequest %}
  35. {# Disable fields with 'ajax_hidden' option set to true #}
  36. {% else %}
  37. {% set sortable = false %}
  38. {% if field_description.options.sortable is defined and field_description.options.sortable %}
  39. {% set sortable = true %}
  40. {% set sort_parameters = admin.modelmanager.sortparameters(field_description, admin.datagrid) %}
  41. {% set current = admin.datagrid.values._sort_by == field_description or admin.datagrid.values._sort_by.fieldName == sort_parameters.filter._sort_by %}
  42. {% set sort_active_class = current ? 'sonata-ba-list-field-order-active' : '' %}
  43. {% set sort_by = current ? admin.datagrid.values._sort_order : field_description.options._sort_order %}
  44. {% endif %}
  45. {% spaceless %}
  46. <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 %}">
  47. {% if sortable %}<a href="{{ admin.generateUrl('list', sort_parameters) }}">{% endif %}
  48. {{ admin.trans(field_description.label, {}, field_description.translationDomain) }}
  49. {% if sortable %}</a>{% endif %}
  50. </th>
  51. {% endspaceless %}
  52. {% endif %}
  53. {% endfor %}
  54. </tr>
  55. </thead>
  56. {% endblock %}
  57. {% block table_body %}
  58. <tbody>
  59. {% for object in admin.datagrid.results %}
  60. <tr>
  61. {% include admin.getTemplate('inner_list_row') %}
  62. </tr>
  63. {% endfor %}
  64. </tbody>
  65. {% endblock %}
  66. {% block table_footer %}
  67. <tr>
  68. <th colspan="{{ admin.list.elements|length - (app.request.isXmlHttpRequest ? (admin.list.has('_action') + admin.list.has('batch')) : 0) }}">
  69. <div class="form-inline">
  70. {% if not app.request.isXmlHttpRequest %}
  71. {% if admin.hasRoute('batch') and batchactions|length > 0 %}
  72. {% block batch %}
  73. <script>
  74. {% block batch_javascript %}
  75. jQuery(document).ready(function ($) {
  76. $('#list_batch_checkbox').click(function () {
  77. $(this).closest('table').find("td input[type='checkbox']").attr('checked', $(this).is(':checked')).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
  78. });
  79. $("td.sonata-ba-list-field-batch input[type='checkbox']").change(function () {
  80. $(this).parent().parent().toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'));
  81. });
  82. });
  83. {% endblock %}
  84. </script>
  85. {% block batch_actions %}
  86. <label class="checkbox" for="{{ admin.uniqid }}_all_elements">
  87. <input type="checkbox" name="all_elements" id="{{ admin.uniqid }}_all_elements">
  88. {{ 'all_elements'|trans({}, 'SonataAdminBundle') }}
  89. ({{ admin.datagrid.pager.nbresults }})
  90. </label>
  91. <select name="action" style="width: auto; height: auto">
  92. {% for action, options in batchactions %}
  93. <option value="{{ action }}">{{ options.label }}</option>
  94. {% endfor %}
  95. </select>
  96. {% endblock %}
  97. <input type="submit" class="btn btn-small btn-primary" value="{{ 'btn_batch'|trans({}, 'SonataAdminBundle') }}">
  98. {% endblock %}
  99. {% endif %}
  100. <div class="pull-right">
  101. {% if admin.hasRoute('export') and admin.isGranted("EXPORT") and admin.getExportFormats()|length %}
  102. {{ "label_export_download"|trans({}, "SonataAdminBundle") }}
  103. {% for format in admin.getExportFormats() %}
  104. <a href="{{ admin.generateUrl('export', admin.modelmanager.paginationparameters(admin.datagrid, 0) + {'format' : format}) }}">{{ format }}</a>{% if not loop.last %},{% endif %}
  105. {% endfor %}
  106. &nbsp;-&nbsp;
  107. {% endif %}
  108. {% block pager_results %}
  109. {% include admin.getTemplate('pager_results') %}
  110. {% endblock %}
  111. </div>
  112. {% endif %}
  113. </div>
  114. </th>
  115. </tr>
  116. {% block pager_links %}
  117. {% if admin.datagrid.pager.haveToPaginate() %}
  118. {% include admin.getTemplate('pager_links') %}
  119. {% endif %}
  120. {% endblock %}
  121. {% endblock %}
  122. </table>
  123. {% if admin.hasRoute('batch') %}
  124. </form>
  125. {% endif %}
  126. {% else %}
  127. <p class="notice">
  128. {{ 'no_result'|trans({}, 'SonataAdminBundle') }}
  129. </p>
  130. {% endif %}
  131. {% block list_footer %}{% endblock %}
  132. {{ sonata_block_render_event('sonata.admin.list.table.bottom', { 'admin': admin }) }}
  133. {% endblock %}
  134. {% block list_filters %}
  135. {% if admin.datagrid.filters %}
  136. {% form_theme form "SonataAdminBundle:Form:filter_admin_fields.html.twig" %}
  137. <div class="box box-primary">
  138. <div class="box-header">
  139. <h4 class="box-title filter_legend {{ admin.datagrid.hasActiveFilters ? 'active' : 'inactive' }}">{{ 'label_filters'|trans({}, 'SonataAdminBundle') }}</h4>
  140. </div>
  141. <div class="box-body">
  142. <form class="sonata-filter-form {{ admin.isChild and 1 == admin.datagrid.filters|length ? 'hide' : '' }}" action="{{ admin.generateUrl('list') }}" method="GET" role="form">
  143. {{ form_errors(form) }}
  144. <div class="filter_container {{ admin.datagrid.hasActiveFilters ? 'active' : 'inactive' }}">
  145. {% for filter in admin.datagrid.filters %}
  146. <div class="form-group">
  147. <label for="{{ form.children[filter.formName].children['value'].vars.id }}">{{ admin.trans(filter.label, {}, filter.translationDomain) }}</label>
  148. {% set attr = form.children[filter.formName].children['type'].vars.attr|default({}) %}
  149. {% set attr = attr|merge({'class': (attr.class|default('') ~ ' sonata-filter-option')|trim}) %}
  150. {{ form_widget(form.children[filter.formName].children['type'], {'attr': attr}) }}
  151. {{ form_widget(form.children[filter.formName].children['value']) }}
  152. </div>
  153. {% endfor %}
  154. <input type="hidden" name="filter[_page]" id="filter__page" value="1">
  155. {% set foo = form.children['_page'].setRendered() %}
  156. {{ form_rest(form) }}
  157. <button type="submit" class="btn btn-primary"><i class="fa fa-filter"></i> {{ 'btn_filter'|trans({}, 'SonataAdminBundle') }}</button>
  158. <a class="btn btn-default" href="{{ admin.generateUrl('list', {filters: 'reset'}) }}">{{ 'link_reset_filter'|trans({}, 'SonataAdminBundle') }}</a>
  159. </div>
  160. {% for paramKey, paramValue in admin.persistentParameters %}
  161. <input type="hidden" name="{{ paramKey }}" value="{{ paramValue }}">
  162. {% endfor %}
  163. </form>
  164. </div>
  165. </div>
  166. {% endif %}
  167. {% endblock %}