您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

340 行
18KB

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