base_list.html.twig 11 KB

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