No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

351 líneas
19KB

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