Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

320 lines
17KB

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