Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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