base_list.html.twig 15 KB

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