You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

287 lines
14KB

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