base_list.html.twig 17 KB

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