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.

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