base_list.html.twig 15 KB

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