base_list.html.twig 11 KB

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