base_list.html.twig 11 KB

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