Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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