Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

index.html.twig 15KB

vor 3 Jahren
vor 3 Jahren
vor 3 Jahren
vor 3 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. {# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
  2. {# @var entities \EasyCorp\Bundle\EasyAdminBundle\Collection\EntityDtoCollection #}
  3. {# @var paginator \EasyCorp\Bundle\EasyAdminBundle\Orm\EntityPaginator #}
  4. {% extends ea.templatePath('layout') %}
  5. {% trans_default_domain ea.i18n.translationDomain %}
  6. {% block body_id entities|length > 0 ? 'ea-index-' ~ entities|first.name : '' %}
  7. {% block body_class 'index' ~ (entities|length > 0 ? ' index-' ~ entities|first.name : '') %}
  8. {% block content_title %}
  9. {{ 'index'|lc_trans_admin_title(ea.getEntity().getFqcn()) }}
  10. {% endblock %}
  11. {% block content_breadcrumb %}
  12. {{ include('@LcSov/adminlte/block/breadcrumb.html.twig') }}
  13. {% endblock content_breadcrumb %}
  14. {% set has_batch_actions = batch_actions|length > 0 %}
  15. {% block page_actions %}
  16. {% endblock page_actions %}
  17. {% block main %}
  18. {# sort can be multiple; let's consider the sorting field the first one #}
  19. {% set sort_field_name = app.request.get('sort')|keys|first %}
  20. {% set sort_order = app.request.get('sort')|first %}
  21. {% set some_results_are_hidden = false %}
  22. {% set has_footer = entities|length != 0 %}
  23. {% set has_search = ea.crud.isSearchEnabled %}
  24. {% set has_filters = filters|length > 0 %}
  25. {% set has_datagrid_tools = has_search or has_filters %}
  26. {% embed '@LcSov/adminlte/embed/card.html.twig' %}
  27. {% block css %}card-table card-outline card-primary{% endblock %}
  28. {% block header %}
  29. <span data-toggle="tooltip" class="badge badge-light" data-original-title="Total" title="Total">
  30. {{ paginator.numResults }} résultats
  31. </span>
  32. <div class="btn-list float-sm-right">
  33. {% block global_actions %}
  34. <div class="global-actions">
  35. {% for action in global_actions %}
  36. {{ include(action.templatePath, { action: action }, with_context = false) }}
  37. {% endfor %}
  38. </div>
  39. {% endblock global_actions %}
  40. {% block batch_actions %}
  41. {% if has_batch_actions %}
  42. <div class="batch-actions" style="display: none">
  43. {% for action in batch_actions %}
  44. {{ include(action.templatePath, { action: action }, with_context = false) }}
  45. {% endfor %}
  46. </div>
  47. {% endif %}
  48. {% endblock %}
  49. </div>
  50. {% endblock %}
  51. {% block body %}
  52. <div class="table-responsive">
  53. <table class="table table-bordered table-hover table-striped">
  54. <thead>
  55. {% block table_head %}
  56. <tr>
  57. {% if has_batch_actions %}
  58. <th class="">
  59. <input type="hidden" id="batch_form_entityIds" value=""/>
  60. <span><input type="checkbox"
  61. class="form-check-input m-0 align-middle form-batch-checkbox-all"></span>
  62. </th>
  63. {% endif %}
  64. {% set ea_sort_asc = constant('EasyCorp\\Bundle\\EasyAdminBundle\\Config\\Option\\SortOrder::ASC') %}
  65. {% set ea_sort_desc = constant('EasyCorp\\Bundle\\EasyAdminBundle\\Config\\Option\\SortOrder::DESC') %}
  66. {% for field in fields ?? [] %}
  67. {% set field = field.getAsDto() %}
  68. {% if field.isDisplayedOn('index') %}
  69. {% set is_sorting_field = ea.search.isSortingField(field.property) %}
  70. {% set next_sort_direction = is_sorting_field ? (ea.search.sortDirection(field.property) == ea_sort_desc ? ea_sort_asc : ea_sort_desc) : ea_sort_desc %}
  71. {% set column_icon = is_sorting_field ? (next_sort_direction == ea_sort_desc ? 'fa-arrow-up' : 'fa-arrow-down') : 'fa-sort' %}
  72. <th class="{{ is_sorting_field ? 'sorted' }} {{ field.isVirtual ? 'field-virtual' }} {% if field.textAlign %}text-{{ field.textAlign }}{% endif %}"
  73. dir="{{ ea.i18n.textDirection }}">
  74. {% if field.isSortable %}
  75. <a href="{{ ea_url({ page: 1, sort: { (field.property): next_sort_direction } }).includeReferrer() }}">
  76. {{ field.label ? field.label|raw : field.getProperty|raw }} <i
  77. class="fa fa-fw {{ column_icon }}"></i>
  78. </a>
  79. {% else %}
  80. <span>{{ field.getProperty|lc_trans_admin_field(ea.getEntity().getFqcn()) }}</span>
  81. {% endif %}
  82. </th>
  83. {% endif %}
  84. {% endfor %}
  85. <th class="w-1" {% if ea.crud.showEntityActionsAsDropdown %}width="10px"{% endif %}
  86. dir="{{ ea.i18n.textDirection }}">
  87. <span class="sr-only">{{ 'action.entity_actions'|trans(ea.i18n.translationParameters, 'EasyAdminBundle') }}</span>
  88. </th>
  89. </tr>
  90. {% endblock table_head %}
  91. </thead>
  92. <tbody>
  93. {% block table_body %}
  94. {% for entity in entities %}
  95. {% if not entity.isAccessible %}
  96. {% set some_results_are_hidden = true %}
  97. {% else %}
  98. <tr data-id="{{ entity.primaryKeyValueAsString }}">
  99. {% if has_batch_actions %}
  100. <td><input type="checkbox" class="form-batch-checkbox"
  101. value="{{ entity.primaryKeyValue }}"></td>
  102. {% endif %}
  103. {% for field in entity.fields %}
  104. <td class="{{ field.property == sort_field_name ? 'sorted' }} text-{{ field.textAlign }} {{ field.cssClass }}"
  105. dir="{{ ea.i18n.textDirection }}">
  106. {{ include(field.templatePath, { field: field, entity: entity }, with_context = false) }}
  107. </td>
  108. {% endfor %}
  109. {% block entity_actions %}
  110. <td class="actions text-right">
  111. {% set in_dropdown_class = 'in-dropdown' %}
  112. {% for action in entity.actions %}
  113. {% if not (in_dropdown_class in action.cssClass) %}
  114. {{ include(action.templatePath, { action: action, entity: entity, isIncludedInDropdown: 0 }, with_context = false) }}
  115. {% endif %}
  116. {% endfor %}
  117. <div class="dropdown dropdown-actions">
  118. <a class="dropdown-toggle btn btn-secondary btn-sm" href="#"
  119. role="button" data-toggle="dropdown" aria-haspopup="true"
  120. aria-expanded="false">
  121. </a>
  122. <div class="dropdown-menu dropdown-menu-right">
  123. {% for action in entity.actions %}
  124. {% if in_dropdown_class in action.cssClass %}
  125. {{ include(action.templatePath, { action: action, isIncludedInDropdown: 1 }, with_context = false) }}
  126. {% endif %}
  127. {% endfor %}
  128. </div>
  129. </div>
  130. {% if not ea.crud.showEntityActionsAsDropdown %}
  131. {% else %}
  132. {% endif %}
  133. </td>
  134. {% endblock entity_actions %}
  135. </tr>
  136. {% endif %}
  137. {% else %}
  138. <tr>
  139. <td class="no-results" colspan="100">
  140. {{ 'datagrid.no_results'|trans(ea.i18n.translationParameters, 'EasyAdminBundle') }}
  141. </td>
  142. </tr>
  143. {% endfor %}
  144. {% if some_results_are_hidden %}
  145. <tr class="datagrid-row-empty">
  146. <td class="text-center" colspan="{{ entities|first.fields|length + 1 }}">
  147. <span class="datagrid-row-empty-message"><i
  148. class="fa fa-lock mr-1"></i> {{ 'datagrid.hidden_results'|trans({}, 'EasyAdminBundle') }}</span>
  149. </td>
  150. </tr>
  151. {% endif %}
  152. {% endblock table_body %}
  153. </tbody>
  154. </table>
  155. </div>
  156. {% endblock %}
  157. {% block footer %}
  158. <div class="row">
  159. {% block paginator %}
  160. {{ include(ea.templatePath('crud/paginator')) }}
  161. {% endblock paginator %}
  162. </div>
  163. {% endblock %}
  164. {% endembed %}
  165. {% block delete_form %}
  166. {{ include('@EasyAdmin/crud/includes/_delete_form.html.twig', with_context = false) }}
  167. {% endblock delete_form %}
  168. {% if has_filters %}
  169. {{ include('@EasyAdmin/crud/includes/_filters_modal.html.twig') }}
  170. {% endif %}
  171. {% if has_batch_actions %}
  172. {{ include('@EasyAdmin/crud/includes/_batch_action_modal.html.twig', {}, with_context = false) }}
  173. {% endif %}
  174. {% endblock main %}
  175. {% block body_javascript %}
  176. {{ parent() }}
  177. <script type="text/javascript">
  178. $(function () {
  179. /* $('.action-delete').on('click', function (e) {
  180. e.preventDefault();
  181. const formAction = $(this).attr('formaction');
  182. $('#modal-delete').modal({backdrop: true, keyboard: true})
  183. .off('click', '#modal-delete-button')
  184. .on('click', '#modal-delete-button', function () {
  185. let deleteForm = $('#delete-form');
  186. deleteForm.attr('action', formAction);
  187. deleteForm.submit();
  188. });
  189. });*/
  190. {% if filters|length > 0 %}
  191. const filterModal = document.querySelector('#modal-filters');
  192. const removeFilter = function (field) {
  193. field.closest('form').querySelectorAll('input[name^="filters[' + field.dataset.filterProperty + ']"]').forEach(hidden => {
  194. hidden.remove();
  195. });
  196. field.remove();
  197. }
  198. document.querySelector('#modal-clear-button').addEventListener('click', function () {
  199. filterModal.querySelectorAll('.filter-field').forEach(filterField => {
  200. removeFilter(filterField);
  201. });
  202. filterModal.querySelector('form').submit();
  203. });
  204. document.querySelector('#modal-apply-button').addEventListener('click', function () {
  205. filterModal.querySelectorAll('.filter-checkbox:not(:checked)').forEach(notAppliedFilter => {
  206. removeFilter(notAppliedFilter.closest('.filter-field'));
  207. });
  208. filterModal.querySelector('form').submit();
  209. });
  210. // HTML5 specifies that a <script> tag inserted with innerHTML should not execute
  211. // https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML#Security_considerations
  212. // That's why we can't use just 'innerHTML'. See https://stackoverflow.com/a/47614491/2804294
  213. let setInnerHTML = function (element, htmlContent) {
  214. element.innerHTML = htmlContent;
  215. Array.from(element.querySelectorAll('script')).forEach(oldScript => {
  216. const newScript = document.createElement('script');
  217. Array.from(oldScript.attributes)
  218. .forEach(attr => newScript.setAttribute(attr.name, attr.value));
  219. newScript.appendChild(document.createTextNode(oldScript.innerHTML));
  220. oldScript.parentNode.replaceChild(newScript, oldScript);
  221. });
  222. };
  223. let filterButton = document.querySelector('.action-filters-button');
  224. filterButton.addEventListener('click', function (event) {
  225. let filterModal = document.querySelector(filterButton.dataset.modal);
  226. let filterModalBody = filterModal.querySelector('.modal-body');
  227. $(filterModal).modal({backdrop: true, keyboard: true});
  228. filterModalBody.innerHTML = '<div class="fa-3x px-3 py-3 text-muted text-center"><i class="fas fa-circle-notch fa-spin"></i></div>';
  229. $.get(filterButton.getAttribute('href'), function (response) {
  230. setInnerHTML(filterModalBody, response);
  231. });
  232. event.preventDefault();
  233. event.stopPropagation();
  234. });
  235. filterButton.setAttribute('href', filterButton.getAttribute('data-href'));
  236. filterButton.removeAttribute('data-href');
  237. filterButton.classList.remove('disabled');
  238. {% endif %}
  239. {% if has_batch_actions %}
  240. {% endif %}
  241. });
  242. </script>
  243. {% if app.request.get('query') is not empty %}
  244. <script type="text/javascript">
  245. const search_query = "{{ ea.search.query|default('')|e('js') }}";
  246. // the original query is prepended to allow matching exact phrases in addition to single words
  247. $('#main').find('table tbody td:not(.actions)').highlight($.merge([search_query], search_query.split(' ')));
  248. </script>
  249. {% endif %}
  250. {% endblock %}