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.

500 lines
31KB

  1. {% set _entity_config = easyadmin_entity(app.request.query.get('entity')) %}
  2. {% trans_default_domain _entity_config.translation_domain %}
  3. {% set _trans_parameters = { '%entity_name%': _entity_config.name|trans, '%entity_label%': _entity_config.label|trans } %}
  4. {% extends _entity_config.templates.layout %}
  5. {% set _request_parameters = app.request.query.all|merge(_request_parameters|default({}))|merge({
  6. action: app.request.get('action'),
  7. entity: _entity_config.name,
  8. menuIndex: app.request.get('menuIndex'),
  9. submenuIndex: app.request.get('submenuIndex'),
  10. sortField: app.request.get('sortField'),
  11. sortDirection: app.request.get('sortDirection'),
  12. page: app.request.get('page', 1),
  13. maxResults: app.request.get('maxResults', _entity_config.list.max_results),
  14. filters: app.request.get('filters', []),
  15. referer: null
  16. }) %}
  17. {% if 'search' == app.request.get('action') %}
  18. {% set _request_parameters = _request_parameters|merge({
  19. query: app.request.get('query')|default(''),
  20. }) %}
  21. {% endif %}
  22. {% set _request_parameters = _request_parameters|merge({ referer: path('easyadmin', _request_parameters)|url_encode }) %}
  23. {% set _has_batch_actions = batch_form is defined and batch_form.vars.batch_actions|length > 0 %}
  24. {% set _has_filters = _entity_config.list.filters|default(false) %}
  25. {% block body_id 'easyadmin-list-' ~ _entity_config.name %}
  26. {# {% block body_class 'list list-' ~ _entity_config.name|lower %} #}
  27. {% block content_title %}
  28. {% apply spaceless %}
  29. {% if 'search' == app.request.get('action') %}
  30. {% set _default_title = 'search.page_title'|transchoice(paginator.nbResults, {}, 'EasyAdminBundle') %}
  31. {{ (_entity_config.search.title is defined ? _entity_config.search.title|transchoice(paginator.nbResults) : _default_title)|raw }}
  32. {% else %}
  33. {% set _default_title = 'list.page_title'|trans(_trans_parameters, 'EasyAdminBundle') %}
  34. {{ (_entity_config.list.title is defined ? _entity_config.list.title|trans(_trans_parameters) : _default_title)|raw }}
  35. {% endif %}
  36. {% endapply %}
  37. {% endblock %}
  38. {% block global_actions %}
  39. {# {% if easyadmin_action_is_enabled_for_list_view('new', _entity_config.name) %}
  40. {% set _action = easyadmin_get_action_for_list_view('new', _entity_config.name) %}
  41. {% block new_action %}
  42. <div class="button-action">
  43. <a class="{{ _action.css_class|default('') }}"
  44. href="{{ path('easyadmin', _request_parameters|merge({ action: _action.name })) }}"
  45. target="{{ _action.target }}">
  46. {% if _action.icon %}<i class="fa fa-fw fa-{{ _action.icon }}"></i>{% endif %}
  47. {{ _action.label is defined and not _action.label is empty ? _action.label|trans(_trans_parameters) }}
  48. </a>
  49. </div>
  50. {% endblock new_action %}
  51. {% endif %} #}
  52. {% endblock global_actions %}
  53. {% block batch_actions %}
  54. {% if _has_batch_actions %}
  55. <div class="batch-actions" style="display: none">
  56. {% form_theme batch_form with easyadmin_config('design.form_theme') only %}
  57. {{ form(batch_form) }}
  58. {{ include('@EasyAdmin/default/includes/_batch_action_modal.html.twig', {
  59. _translation_domain: _entity_config.translation_domain,
  60. _trans_parameters: _trans_parameters,
  61. _entity_config: _entity_config,
  62. }, with_context = false) }}
  63. </div>
  64. {% endif %}
  65. {% endblock batch_actions %}
  66. {% block content_header %}
  67. {{ parent() }}
  68. {{ block('batch_actions') }}
  69. {% if _has_filters %}
  70. {{ include('@EasyAdmin/default/includes/_filters_modal.html.twig') }}
  71. {% endif %}
  72. {% endblock content_header %}
  73. {% block main %}
  74. {% block main_append %}{% endblock %}
  75. {% set _fields_visible_by_user = fields|filter((metadata, field) => easyadmin_is_granted(metadata.permission)) %}
  76. {% set _number_of_hidden_results = 0 %}
  77. {% set _list_item_actions = easyadmin_get_actions_for_list_item(_entity_config.name) %}
  78. <div class="row" id="{% block list_id %}{% endblock %}">
  79. <div class="col-12">
  80. <div class="card card-outline card-primary">
  81. <div class="card-header">
  82. {% block card_header %}
  83. <h2 class="card-title text-lg ">
  84. <div class="btn-group">
  85. {% set itemsPerPage = [10,20,30,50,100,200] %}
  86. {% for itemPerPage in itemsPerPage %}
  87. <a href="{{ path('easyadmin', _request_parameters|merge({ maxResults: itemPerPage, page : "1" })) }}"
  88. class="btn btn-sm {{ paginator.maxPerPage == itemPerPage ? 'btn-outline-secondary' : 'btn-secondary' }}">{{ itemPerPage }}</a>
  89. {% endfor %}
  90. </div>
  91. {% block paginator_nb_results %}
  92. {# {{ "list.title"|trans({'%label%' : _entity_config['label']|lower }) }} #}
  93. {% if paginator.nbResultsTotal != paginator.nbResults %}
  94. <span data-toggle="tooltip" title="{{ "list.nbResultsFiltered"|trans }}"
  95. class="badge badge-info">{{ paginator.nbResults }} <i
  96. class="fa fa-search"></i> </span>
  97. |
  98. {% endif %}
  99. <span data-toggle="tooltip" title="{{ "list.nbResults"|trans }}"
  100. class="badge badge-primary">{{ paginator.nbResultsTotal }} <i
  101. class="fa fa-bars"></i> </span>
  102. {% if paginator.nbResultsOnline is defined %}<span data-toggle="tooltip"
  103. title="{{ "list.nbResultsOnline"|trans }}"
  104. class="badge badge-success">{{ paginator.nbResultsOnline }}
  105. <i class="fa fa-check"></i> </span>{% endif %}
  106. {% if paginator.nbResultsOffline is defined %}<span data-toggle="tooltip"
  107. title="{{ "list.nbResultsOffline"|trans }}"
  108. class="badge badge-danger">{{ paginator.nbResultsOffline }}
  109. <i class="fa fa-pen"></i></span>{% endif %}
  110. {% if is_granted('ROLE_SUPER_ADMIN') and paginator.nbResultsDeleted is defined %}<span
  111. data-toggle="tooltip" title="{{ "list.nbResultsDeleted"|trans }}"
  112. class="badge badge-secondary">{{ paginator.nbResultsDeleted }} <i
  113. class="fa fa-trash"></i>
  114. </span>{% endif %}
  115. {% endblock %}
  116. </h2>
  117. <div class="button-action">
  118. {% if easyadmin_action_is_enabled_for_list_view('new', _entity_config.name) %}
  119. {% set _action = easyadmin_get_action_for_list_view('new', _entity_config.name) %}
  120. {% block new_action %}
  121. <a class="float-right {{ _action.css_class|default('') }}"
  122. href="{{ path('easyadmin', _request_parameters|merge({ action: _action.name })) }}"
  123. target="{{ _action.target }}">
  124. <i class="fa fa-fw fa-plus"></i>
  125. {{ _action.label is defined and not _action.label is empty ? _action.label|trans(_trans_parameters) }}
  126. </a>
  127. {% endblock new_action %}
  128. {% endif %}
  129. {% if _entity_config['list']['btn_init_export_purchase_order'] is defined %}
  130. <a class="float-right btn-sm btn-success action-confirm"
  131. href="{{ path('easyadmin', { entity: 'Supplier', action: 'initExportPurchaseOrder' }) }}">
  132. <i class="fa fa-undo"></i> Réinitialiser export bons de commande
  133. </a>
  134. {% endif %}
  135. {% if _entity_config['list']['btn_download_purchase_order_archive'] is defined %}
  136. <a class="float-right btn-sm btn-success"
  137. href="{{ path('easyadmin', { entity: 'Supplier', action: 'exportOrderPurchasesAsArchive' }) }}">
  138. <i class="fa fa-download"></i> Récapitulatif des commandes
  139. </a>
  140. {% endif %}
  141. {% if _entity_config['list']['btn_history_purchase_order'] is defined %}
  142. <a class="float-right btn-sm btn-info"
  143. href="{{ path('easyadmin', { entity: 'PurchaseOrder', action: 'list' }) }}">
  144. <i class="fa fa-history"></i> Historiques des bons de commandes
  145. </a>
  146. {% endif %}
  147. {% if _entity_config['list']['btn_week_purchase_order'] is defined %}
  148. <a class="float-right btn-sm btn-info"
  149. href="{{ path('easyadmin', { entity: 'SupplierOrderPurchase', action: 'list' }) }}">
  150. <i class="fa fa-tractor"></i> Bons de commandes de la semaine
  151. </a>
  152. {% endif %}
  153. {% if _entity_config['list']['btn_add_purchase_order'] is defined %}
  154. <a class="float-right btn-sm btn-primary"
  155. href="{{ path('easyadmin', { entity: 'PurchaseOrder', action: 'new' }) }}">
  156. <i class="fa fa-plus"></i> Créer un bon de commande
  157. </a>
  158. {% endif %}
  159. {% if _entity_config['list']['edit_position'] is defined %}
  160. <a class="float-right btn-sm btn-success action-sort"
  161. href="{{ path('easyadmin', _request_parameters|merge({ action: 'sort' })) }}">
  162. <i class="fa fa-sort"></i> Modifier position
  163. </a>
  164. {% endif %}
  165. {% if app.request.get('action') == 'listChildren' and app.request.get('entity') == 'ProductCategory' %}
  166. <a class="float-right btn-sm btn-primary"
  167. href="{{ path('easyadmin', {action: 'list', entity: 'ProductCategory'}) }}">
  168. <i class="fa fa-chevron-left"></i> Retour à la catégorie parente
  169. </a>
  170. {% endif %}
  171. </div>
  172. {% endblock card_header %}
  173. </div>
  174. <div class="card-body p-0">
  175. {% block table %}
  176. <table class="table lc-table-list datagrid table-bordered table-hover table-striped ">
  177. <thead>
  178. {% block table_head %}
  179. <tr>
  180. {% if _has_batch_actions %}
  181. <th width="1px"><span><input type="checkbox"
  182. class="form-batch-checkbox-all"></span>
  183. </th>
  184. {% endif %}
  185. {% for field, metadata in _fields_visible_by_user %}
  186. {% set isSortingField = (metadata.property == app.request.get('sortField')) or ('association' == metadata.type and app.request.get('sortField') starts with metadata.property ~ '.') %}
  187. {% set nextSortDirection = isSortingField ? (app.request.get('sortDirection') == 'DESC' ? 'ASC' : 'DESC') : 'ASC' %}
  188. {% set _column_label = metadata.label|trans(_trans_parameters) %}
  189. {% set _column_icon = isSortingField ? (nextSortDirection == 'DESC' ? 'fa-arrow-up' : 'fa-arrow-down') : 'fa-sort' %}
  190. {% set isFilteredField = false %}
  191. {% if filters_form[field] is defined and filters_form[field].vars.value is not empty %}
  192. {% if (metadata['dataType'] == 'datetime' or metadata['dataType'] == 'date') %}
  193. {% if filters_form[field]['dateStart'].vars.value is not empty and filters_form[field]['dateEnd'].vars.value is not empty %}
  194. {% set isFilteredField = true %}
  195. {% endif %}
  196. {% else %}
  197. {% set isFilteredField = true %}
  198. {% endif %}
  199. {% endif %}
  200. <th class="{{ isSortingField ? 'sorted' }} {{ isFilteredField ? 'filtered': '' }} {{ metadata.virtual ? 'virtual' }} {{ metadata.dataType|lower }} {{ metadata.css_class }}" {{ easyadmin_config('design.rtl') ? 'dir="rtl"' }}>
  201. {% if metadata.sortable %}
  202. <a href="{{ path('easyadmin', _request_parameters|merge({ page: 1, sortField: metadata.property, sortDirection: nextSortDirection })) }}">
  203. {{ _column_label|raw }} <i class="fa fa-fw {{ _column_icon }}"></i>
  204. </a>
  205. {% else %}
  206. <span>{{ _column_label|raw }}</span>
  207. {% endif %}
  208. </th>
  209. {% endfor %}
  210. {# {% if _list_item_actions|length > 0 %}#}
  211. <th {% if _entity_config.list.collapse_actions %}width="10px"{% endif %} {{ easyadmin_config('design.rtl') ? 'dir="rtl"' }}>
  212. <span class="sr-only">{{ 'list.row_actions'|trans(_trans_parameters, 'EasyAdminBundle') }}</span>
  213. </th>
  214. {#{% endif %}#}
  215. </tr>
  216. {% endblock table_head %}
  217. {% block table_filters %}
  218. {% set fieldAreNotEmpty = false %}
  219. {% if filters_form is defined %}
  220. <tr class="table-filters-line">
  221. {% if _has_batch_actions %}
  222. <th></th>{% endif %}
  223. {% for field, metadata in _fields_visible_by_user %}
  224. <th>
  225. {% set field = utils.getFilterPropertyClean(field) %}
  226. {% if filters_form[field] is defined %}
  227. {% if filters_form[field].vars.value is not null and filters_form[field].vars.value is not empty %}{% set fieldAreNotEmpty = true %}{% endif %}
  228. {% if metadata['dataType'] == 'datetime' or metadata['dataType'] == 'date' %}
  229. <div class="input-group input-group-sm">
  230. <input type="text"
  231. class="form-control input-sm float-right date-range">
  232. <div class="hidden date-time-range-fields"
  233. style="display: none;">
  234. {{ form_widget(filters_form[field]['dateStart'], {"attr" : {'class' : 'date-start', 'form': 'filters-form'}}) }}
  235. {{ form_widget(filters_form[field]['dateEnd'], {"attr" : {'class' : 'date-end', 'form': 'filters-form'}}) }}
  236. </div>
  237. </div>
  238. {% else %}
  239. <div class="form-widget input-group-sm">
  240. {% if metadata.dataType == 'integer' or metadata.dataType== 'string' or metadata.dataType== 'text' %}
  241. {{ form_widget(filters_form[field], {'attr': {'autocomplete': 'off', 'data-lc-autocomplete-url' : path('easyadmin', {
  242. action: 'autocomplete',
  243. field: field,
  244. entity: _entity_config.name,
  245. })|raw }}) }}
  246. {% else %}
  247. {{ form_widget(filters_form[field]) }}
  248. {% endif %}
  249. </div>
  250. {% endif %}
  251. {% endif %}
  252. </th>
  253. {% endfor %}
  254. {#{% if _list_item_actions|length > 0 %}#}
  255. <th class="actions">
  256. <button type="submit" form="filters-form" class="btn btn-sm btn-info"
  257. data-toggle="tooltip"
  258. title="{{ "action.apply"|trans({}, 'lcshop') }}"
  259. aria-label="{{ "action.apply"|trans({}, 'lcshop') }}">
  260. <i class="fa fa-search"></i>
  261. </button>
  262. {% if filters_form.vars.submitted or fieldAreNotEmpty %}
  263. <a href="{{ path('easyadmin', _request_parameters|merge({ 'filterClear' : 'clearAll', list_filter : null, referer : null })) }}"
  264. class="btn btn-sm btn-warning lc-reset-filters"
  265. data-toggle="tooltip"
  266. title="{{ "action.reset"|trans({}, 'lcshop') }}"
  267. aria-label="{{ "action.reset"|trans({}, 'lcshop') }}">
  268. <i class="fa fa-eraser"></i>
  269. </a>
  270. {% endif %}
  271. </th>
  272. {# {% endif %}#}
  273. </tr>
  274. {% endif %}
  275. {% endblock table_filters %}
  276. {% block table_search %}
  277. {% endblock %}
  278. </thead>
  279. <tbody>
  280. {% block table_body %}
  281. {% for item in paginator.currentPageResults %}
  282. {% if not easyadmin_is_granted(_entity_config.list.item_permission, item) %}
  283. {% set _number_of_hidden_results = _number_of_hidden_results + 1 %}
  284. {% else %}
  285. {# the empty string concatenation is needed when the primary key is an object (e.g. an Uuid object) #}
  286. {% set _item_id = '' ~ attribute(item, _entity_config.primary_key_field_name) %}
  287. <tr id="tr-entity-id-{{ _item_id }}" data-id="{{ _item_id }}">
  288. {% if _has_batch_actions %}
  289. <td><input type="checkbox" class="form-batch-checkbox"
  290. value="{{ _item_id }}"></td>
  291. {% endif %}
  292. {% for field, metadata in _fields_visible_by_user %}
  293. {% set isSortingField = metadata.property == app.request.get('sortField') %}
  294. {% set _column_label = (metadata.label ?: field|humanize)|trans(_trans_parameters) %}
  295. <td class="{{ isSortingField ? 'sorted' }} {{ metadata.dataType|lower }} {{ metadata.css_class }}" {{ easyadmin_config('design.rtl') ? 'dir="rtl"' }}>
  296. {% if (field == 'title' or field== 'id') and (metadata.dataType=="string" or metadata.dataType=="integer") and _entity_config.name != 'ProductFamilyAdvancedEditing' %}
  297. <a class="link-as-text"
  298. href="{{ path('easyadmin', _request_parameters|merge({ action: 'edit', id: item.id })) }}">
  299. {{ easyadmin_render_field_for_list_view(_entity_config.name, item, metadata) }}
  300. </a>
  301. {% else %}
  302. {# {% if metadatafieldName =="supplier" %}
  303. {{ dump(metadata) }}
  304. {% endif %} #}
  305. {{ easyadmin_render_field_for_list_view(_entity_config.name, item, metadata) }}
  306. {% endif %}
  307. </td>
  308. {% endfor %}
  309. <td class="actions">
  310. {% if _list_item_actions|length > 0 %}
  311. {% set _column_label = 'list.row_actions'|trans(_trans_parameters, 'EasyAdminBundle') %}
  312. {% block item_actions %}
  313. {% set _actions_template = '@LcShop/backend/default/block/actions.html.twig' %}
  314. {{ include(_actions_template, {
  315. actions: _list_item_actions,
  316. entity_config: _entity_config,
  317. request_parameters: _request_parameters,
  318. translation_domain: _entity_config.translation_domain,
  319. trans_parameters: _trans_parameters,
  320. item_id: _item_id,
  321. item: item
  322. }, with_context = false) }}
  323. {% endblock item_actions %}
  324. {% endif %}
  325. </td>
  326. </tr>
  327. {% endif %}
  328. {% else %}
  329. <tr>
  330. <td class="no-results" colspan="{{ _fields_visible_by_user|length + 1 }}">
  331. {{ 'search.no_results'|trans(_trans_parameters, 'EasyAdminBundle') }}
  332. </td>
  333. </tr>
  334. {% endfor %}
  335. {% if _number_of_hidden_results > 0 %}
  336. <tr class="datagrid-row-empty">
  337. <td class="text-center" colspan="{{ _fields_visible_by_user|length + 1 }}">
  338. <span class="datagrid-row-empty-message"><i
  339. class="fa fa-lock mr-1"></i> {{ 'security.list.hidden_results'|trans({}, 'EasyAdminBundle') }}</span>
  340. </td>
  341. </tr>
  342. {% endif %}
  343. {% endblock table_body %}
  344. </tbody>
  345. </table>
  346. {% endblock table %}
  347. {% block filters_form %}
  348. {% if filters_form is defined %}
  349. {{ form_start(filters_form, {'attr' :{'id' : 'filters-form'}}) }}
  350. {% form_theme filters_form '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
  351. <input type="hidden" name="entity" value="{{ _entity_config.name }}">
  352. <input type="hidden" name="menuIndex" value="{{ app.request.get('menuIndex') }}">
  353. <input type="hidden" name="submenuIndex" value="{{ app.request.get('submenuIndex') }}">
  354. <input type="hidden" name="sortField" value="{{ app.request.get('sortField', '') }}">
  355. <input type="hidden" name="sortDirection"
  356. value="{{ app.request.get('sortDirection', 'DESC') }}">
  357. <input type="hidden" name="action" value="{{ app.request.get('action') }}">
  358. {{ form_end(filters_form) }}
  359. {% endif %}
  360. {% endblock filters_form %}
  361. {% block delete_form %}
  362. {% set referer = paginator.currentPage == paginator.nbPages and 1 != paginator.currentPage and 1 == paginator.currentPageResults|length
  363. ? path('easyadmin', app.request.query|merge({ page: app.request.query.get('page') - 1 }))
  364. : app.request.requestUri %}
  365. {{ include('@EasyAdmin/default/includes/_delete_form.html.twig', {
  366. view: 'list',
  367. referer: referer,
  368. delete_form: delete_form_template,
  369. _translation_domain: _entity_config.translation_domain,
  370. _trans_parameters: _trans_parameters,
  371. _entity_config: _entity_config,
  372. }, with_context = false) }}
  373. {% endblock delete_form %}
  374. </div>
  375. </div>
  376. </div>
  377. </div>
  378. {% endblock main %}
  379. {% block content_footer %}
  380. <div class="container-fluid">
  381. {% block paginator %}
  382. {{ include(_entity_config.templates.paginator) }}
  383. {% endblock paginator %}
  384. </div>
  385. {% endblock %}
  386. {% block head_stylesheets %}
  387. {{ parent() }}
  388. <link rel="stylesheet"
  389. href="{{ asset('bundles/lcshop/css/backend/adminlte/plugins/daterange/daterangepicker.css') }}">
  390. {% endblock %}
  391. {% block plugin_javascript %}
  392. {{ parent() }}
  393. <script src="{{ asset('bundles/lcshop/js/backend/plugin/daterange/moment.min.js') }}"></script>
  394. <script src="{{ asset('bundles/lcshop/js/backend/plugin/daterange/daterangepicker.js') }}"></script>
  395. <script src="{{ asset('bundles/lcshop/js/backend/plugin/datatables/jquery.highlight.js') }}"></script>
  396. <script src="{{ asset('bundles/lcshop/js/backend/plugin/autocomplete/bootstrap-autocomplete.min.js') }}"></script>
  397. {# <script src="{{ asset('bundles/lcshop/js/backend/plugin/datatables/responsive.bootstrap4.min.js') }}"></script> #}
  398. {% endblock %}
  399. {% block script_javascript %}
  400. {{ parent() }}
  401. <script src="{{ asset('bundles/lcshop/js/backend/script/default/init-list.js')|lc_cache }}"></script>
  402. <script type="text/javascript">
  403. $(document).ready(function () {
  404. const toggles = document.querySelectorAll('.custom-switch input[type="checkbox"]');
  405. for (i = 0; i < toggles.length; i++) {
  406. toggles[i].addEventListener('change', function () {
  407. const toggle = this;
  408. const newValue = this.checked;
  409. const oldValue = !newValue;
  410. const propertyName = this.closest('.custom-switch').dataset.propertyname;
  411. const toggleUrl = "{{ path('easyadmin', { action: 'edit', entity: _entity_config.name, view: 'list' })|raw }}"
  412. + "&id=" + this.closest('tr').dataset.id
  413. + "&property=" + propertyName
  414. + "&newValue=" + newValue.toString();
  415. let toggleRequest = $.ajax({type: "GET", url: toggleUrl, data: {}, dataType: 'json'});
  416. toggleRequest.done(function (response) {
  417. setFlashMessages(response.flashMessages);
  418. });
  419. toggleRequest.fail(function () {
  420. // in case of error, restore the original value and disable the toggle
  421. toggle.checked = oldValue;
  422. toggle.disabled = true;
  423. toggle.closest('.checkbox-switch').classList.add('disabled');
  424. });
  425. });
  426. }
  427. });
  428. </script>
  429. {% endblock %}