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.

index.html.twig 16KB

3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
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. <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 css %}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.label ? field.label|raw : field.getProperty|raw }} <i
  78. class="fa fa-fw {{ column_icon }}"></i>
  79. </a>
  80. {% else %}
  81. <span>{{ field.getProperty|lc_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. </thead>
  93. <tbody>
  94. {% block table_body %}
  95. {% for entity in entities %}
  96. {% if not entity.isAccessible %}
  97. {% set some_results_are_hidden = true %}
  98. {% else %}
  99. <tr data-id="{{ entity.primaryKeyValueAsString }}">
  100. {% if has_batch_actions %}
  101. <td><input type="checkbox" class="form-batch-checkbox"
  102. value="{{ entity.primaryKeyValue }}"></td>
  103. {% endif %}
  104. {% for field in entity.fields %}
  105. <td class="{{ field.property == sort_field_name ? 'sorted' }} text-{{ field.textAlign }} {{ field.cssClass }}"
  106. dir="{{ ea.i18n.textDirection }}">
  107. {{ include(field.templatePath, { field: field, entity: entity }, with_context = false) }}
  108. </td>
  109. {% endfor %}
  110. {% block entity_actions %}
  111. <td class="actions text-right">
  112. {% set in_dropdown_class = 'in-dropdown' %}
  113. {% for action in entity.actions %}
  114. {% if not (in_dropdown_class in action.cssClass) %}
  115. {{ include(action.templatePath, { action: action, entity: entity, isIncludedInDropdown: 0 }, with_context = false) }}
  116. {% endif %}
  117. {% endfor %}
  118. <div class="dropdown dropdown-actions">
  119. <a class="dropdown-toggle btn btn-secondary btn-sm" href="#"
  120. role="button" data-toggle="dropdown" aria-haspopup="true"
  121. aria-expanded="false">
  122. </a>
  123. <div class="dropdown-menu dropdown-menu-right">
  124. {% for action in entity.actions %}
  125. {% if in_dropdown_class in action.cssClass %}
  126. {{ include(action.templatePath, { action: action, isIncludedInDropdown: 1 }, with_context = false) }}
  127. {% endif %}
  128. {% endfor %}
  129. </div>
  130. </div>
  131. {% if not ea.crud.showEntityActionsAsDropdown %}
  132. {% else %}
  133. {% endif %}
  134. </td>
  135. {% endblock entity_actions %}
  136. </tr>
  137. {% endif %}
  138. {% else %}
  139. <tr>
  140. <td class="no-results" colspan="100">
  141. {{ 'datagrid.no_results'|trans(ea.i18n.translationParameters, 'EasyAdminBundle') }}
  142. </td>
  143. </tr>
  144. {% endfor %}
  145. {% if some_results_are_hidden %}
  146. <tr class="datagrid-row-empty">
  147. <td class="text-center" colspan="{{ entities|first.fields|length + 1 }}">
  148. <span class="datagrid-row-empty-message"><i
  149. class="fa fa-lock mr-1"></i> {{ 'datagrid.hidden_results'|trans({}, 'EasyAdminBundle') }}</span>
  150. </td>
  151. </tr>
  152. {% endif %}
  153. {% endblock table_body %}
  154. </tbody>
  155. </table>
  156. </div>
  157. {% endblock %}
  158. {% block footer %}
  159. <div class="row">
  160. {% block paginator %}
  161. {{ include(ea.templatePath('crud/paginator')) }}
  162. {% endblock paginator %}
  163. </div>
  164. {% endblock %}
  165. {% endembed %}
  166. {% block delete_form %}
  167. {{ include('@EasyAdmin/crud/includes/_delete_form.html.twig', with_context = false) }}
  168. {% endblock delete_form %}
  169. {% if has_filters %}
  170. {{ include('@EasyAdmin/crud/includes/_filters_modal.html.twig') }}
  171. {% endif %}
  172. {% if has_batch_actions %}
  173. {{ include('@EasyAdmin/crud/includes/_batch_action_modal.html.twig', {}, with_context = false) }}
  174. {% endif %}
  175. </div>
  176. {% endblock main %}
  177. {% block body_javascript %}
  178. {{ parent() }}
  179. <script type="text/javascript">
  180. $(function () {
  181. /* $('.action-delete').on('click', function (e) {
  182. e.preventDefault();
  183. const formAction = $(this).attr('formaction');
  184. $('#modal-delete').modal({backdrop: true, keyboard: true})
  185. .off('click', '#modal-delete-button')
  186. .on('click', '#modal-delete-button', function () {
  187. let deleteForm = $('#delete-form');
  188. deleteForm.attr('action', formAction);
  189. deleteForm.submit();
  190. });
  191. });*/
  192. {% if filters|length > 0 %}
  193. const filterModal = document.querySelector('#modal-filters');
  194. const removeFilter = function (field) {
  195. field.closest('form').querySelectorAll('input[name^="filters[' + field.dataset.filterProperty + ']"]').forEach(hidden => {
  196. hidden.remove();
  197. });
  198. field.remove();
  199. }
  200. document.querySelector('#modal-clear-button').addEventListener('click', function () {
  201. filterModal.querySelectorAll('.filter-field').forEach(filterField => {
  202. removeFilter(filterField);
  203. });
  204. filterModal.querySelector('form').submit();
  205. });
  206. document.querySelector('#modal-apply-button').addEventListener('click', function () {
  207. filterModal.querySelectorAll('.filter-checkbox:not(:checked)').forEach(notAppliedFilter => {
  208. removeFilter(notAppliedFilter.closest('.filter-field'));
  209. });
  210. filterModal.querySelector('form').submit();
  211. });
  212. // HTML5 specifies that a <script> tag inserted with innerHTML should not execute
  213. // https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML#Security_considerations
  214. // That's why we can't use just 'innerHTML'. See https://stackoverflow.com/a/47614491/2804294
  215. let setInnerHTML = function (element, htmlContent) {
  216. element.innerHTML = htmlContent;
  217. Array.from(element.querySelectorAll('script')).forEach(oldScript => {
  218. const newScript = document.createElement('script');
  219. Array.from(oldScript.attributes)
  220. .forEach(attr => newScript.setAttribute(attr.name, attr.value));
  221. newScript.appendChild(document.createTextNode(oldScript.innerHTML));
  222. oldScript.parentNode.replaceChild(newScript, oldScript);
  223. });
  224. };
  225. let filterButton = document.querySelector('.action-filters-button');
  226. filterButton.addEventListener('click', function (event) {
  227. let filterModal = document.querySelector(filterButton.dataset.modal);
  228. let filterModalBody = filterModal.querySelector('.modal-body');
  229. $(filterModal).modal({backdrop: true, keyboard: true});
  230. filterModalBody.innerHTML = '<div class="fa-3x px-3 py-3 text-muted text-center"><i class="fas fa-circle-notch fa-spin"></i></div>';
  231. $.get(filterButton.getAttribute('href'), function (response) {
  232. setInnerHTML(filterModalBody, response);
  233. });
  234. event.preventDefault();
  235. event.stopPropagation();
  236. });
  237. filterButton.setAttribute('href', filterButton.getAttribute('data-href'));
  238. filterButton.removeAttribute('data-href');
  239. filterButton.classList.remove('disabled');
  240. {% endif %}
  241. {% if has_batch_actions %}
  242. {% endif %}
  243. });
  244. </script>
  245. {% if app.request.get('query') is not empty %}
  246. <script type="text/javascript">
  247. const search_query = "{{ ea.search.query|default('')|e('js') }}";
  248. // the original query is prepended to allow matching exact phrases in addition to single words
  249. $('#main').find('table tbody td:not(.actions)').highlight($.merge([search_query], search_query.split(' ')));
  250. </script>
  251. {% endif %}
  252. {% endblock %}