Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

edit.html.twig 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. {% form_theme form with easyadmin_config('design.form_theme') only %}
  2. {% set _entity_config = easyadmin_entity(app.request.query.get('entity')) %}
  3. {% set _entity_id = attribute(entity, _entity_config.primary_key_field_name) %}
  4. {% trans_default_domain _entity_config.translation_domain %}
  5. {% set _trans_parameters = { '%entity_name%': _entity_config.name|trans, '%entity_label%': _entity_config.label|trans, '%entity_id%': _entity_id } %}
  6. {% extends _entity_config.templates.layout %}
  7. {% block body_id 'easyadmin-edit-' ~ _entity_config.name ~ '-' ~ _entity_id %}
  8. {% block body_class 'edit edit-' ~ _entity_config.name|lower %}
  9. {% block content_title %}
  10. {% apply spaceless %}
  11. {% set _default_title = 'edit.page_title'|trans(_trans_parameters, 'EasyAdminBundle') %}
  12. {{ _entity_config.edit.title is defined ? _entity_config.edit.title|trans(_trans_parameters) : _default_title }}
  13. {% endapply %}
  14. {% endblock %}
  15. {% block content_footer_wrapper '' %}
  16. {% block main %}
  17. {% block entity_form %}
  18. {{ form(form) }}
  19. {% endblock entity_form %}
  20. {% block delete_form %}
  21. {{ include('@EasyAdmin/default/includes/_delete_form.html.twig', {
  22. view: 'edit',
  23. referer: app.request.query.get('referer', ''),
  24. delete_form: delete_form,
  25. _translation_domain: _entity_config.translation_domain,
  26. _trans_parameters: _trans_parameters,
  27. _entity_config: _entity_config,
  28. }, with_context = false) }}
  29. {% endblock delete_form %}
  30. {% endblock %}
  31. {% block head_stylesheets %}
  32. {{ parent() }}
  33. <link rel="stylesheet" href="{{ asset('bundles/lcshop/css/backend/adminlte/plugins/jquery-ui/jquery-ui.min.css') }}">
  34. {% endblock %}
  35. {% block body_javascript %}
  36. {{ parent() }}
  37. <script src="{{ asset('bundles/lcshop/js/backend/plugin/jquery-ui/jquery-ui.min.js') }}"></script>
  38. {#<script type="text/javascript">
  39. $(function() {
  40. $('.edit-form').areYouSure({ 'message': '{{ 'form.are_you_sure'|trans({}, 'EasyAdminBundle')|e('js') }}' });
  41. const entityForm = document.querySelector('form.edit-form');
  42. const formSubmitButton = entityForm.querySelector('button[type="submit"]');
  43. const inputFieldsSelector = 'input,select,textarea';
  44. // Adding visual feedback for invalid fields: any ".form-group" with invalid fields
  45. // receives "has-error" class. The class is removed on click on the ".form-group"
  46. // itself to support custom/complex fields.
  47. formSubmitButton.addEventListener('click', function() {
  48. entityForm.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  49. if (!input.validity.valid) {
  50. const formGroup = input.closest('div.form-group');
  51. formGroup.classList.add('has-error');
  52. formGroup.addEventListener('click', function onFormGroupClick() {
  53. formGroup.classList.remove('has-error');
  54. formGroup.removeEventListener('click', onFormGroupClick);
  55. });
  56. }
  57. });
  58. });
  59. // forms with tabs require some special treatment for errors. The problem
  60. // is when the field with errors is included in a tab not currently visible.
  61. // Browser shows this error "An invalid form control with name='...' is not focusable."
  62. // So, the user clicks on Submit button, the form is not submitted and the error
  63. // is not displayed. This JavaScript code ensures that each tab shows a badge with
  64. // the number of errors in it.
  65. formSubmitButton.addEventListener('click', function() {
  66. const formTabPanes = entityForm.querySelectorAll('.tab-pane');
  67. if (0 === formTabPanes.length) {
  68. return;
  69. }
  70. let firstNavTabItemWithError = null;
  71. formTabPanes.forEach(function (tabPane) {
  72. let tabPaneNumErrors = 0;
  73. tabPane.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  74. if (!input.validity.valid) {
  75. tabPaneNumErrors++;
  76. }
  77. });
  78. let navTabItem = entityForm.querySelector('.nav-item a[href="#' + tabPane.id + '"]');
  79. let existingErrorBadge = navTabItem.querySelector('span.badge.badge-danger');
  80. if (null !== existingErrorBadge) {
  81. navTabItem.removeChild(existingErrorBadge);
  82. }
  83. if (tabPaneNumErrors > 0) {
  84. let newErrorBadge = document.createElement('span');
  85. newErrorBadge.classList.add('badge', 'badge-danger');
  86. newErrorBadge.title = 'form.tab.error_badge_title';
  87. newErrorBadge.textContent = tabPaneNumErrors;
  88. navTabItem.appendChild(newErrorBadge);
  89. if (null === firstNavTabItemWithError) {
  90. firstNavTabItemWithError = navTabItem;
  91. }
  92. }
  93. });
  94. if (firstNavTabItemWithError) {
  95. firstNavTabItemWithError.click();
  96. }
  97. });
  98. $('a.action-delete').on('click', function(e) {
  99. e.preventDefault();
  100. $('#modal-delete').modal({ backdrop: true, keyboard: true })
  101. .off('click', '#modal-delete-button')
  102. .on('click', '#modal-delete-button', function () {
  103. $('#delete-form').trigger('submit');
  104. });
  105. });
  106. });
  107. </script>#}
  108. {% endblock %}