Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

edit.html.twig 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. {# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
  2. {# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
  3. {% extends ea.templatePath('layout') %}
  4. {% form_theme edit_form with ea.crud.formThemes only %}
  5. {% trans_default_domain ea.i18n.translationDomain %}
  6. {% block body_id 'ea-edit-' ~ entity.name ~ '-' ~ entity.primaryKeyValue %}
  7. {% block body_class 'ea-edit ea-edit-' ~ entity.name %}
  8. {% block configured_head_contents %}
  9. {{ parent() }}
  10. {% for htmlContent in edit_form.vars.ea_crud_form.assets.headContents %}
  11. {{ htmlContent|raw }}
  12. {% endfor %}
  13. {% endblock %}
  14. {% block configured_body_contents %}
  15. {{ parent() }}
  16. {% for htmlContent in edit_form.vars.ea_crud_form.assets.bodyContents %}
  17. {{ htmlContent|raw }}
  18. {% endfor %}
  19. {% endblock %}
  20. {% block configured_stylesheets %}
  21. {{ parent() }}
  22. {% for css_asset in edit_form.vars.ea_crud_form.assets.cssFiles %}
  23. <link rel="stylesheet" href="{{ asset(css_asset) }}">
  24. {% endfor %}
  25. {% for webpack_encore_entry in edit_form.vars.ea_crud_form.assets.webpackEncoreEntries %}
  26. {{ ea_call_function_if_exists('encore_entry_link_tags', webpack_encore_entry) }}
  27. {% endfor %}
  28. {% endblock %}
  29. {% block configured_javascripts %}
  30. {{ parent() }}
  31. {% for js_asset in edit_form.vars.ea_crud_form.assets.jsFiles %}
  32. <script src="{{ asset(js_asset) }}"></script>
  33. {% endfor %}
  34. {% for webpack_encore_entry in edit_form.vars.ea_crud_form.assets.webpackEncoreEntries %}
  35. {{ ea_call_function_if_exists('encore_entry_script_tags', webpack_encore_entry) }}
  36. {% endfor %}
  37. {% endblock %}
  38. {% block content_title %}
  39. {%- apply spaceless -%}
  40. {{ ea.crud.customPageTitle is null
  41. ? (ea.crud.defaultPageTitle|trans(ea.i18n.translationParameters, 'EasyAdminBundle'))|raw
  42. : ea.crud.customPageTitle|trans(ea.i18n.translationParameters)|raw }}
  43. {%- endapply -%}
  44. {% endblock %}
  45. {% block page_actions %}
  46. {% for action in entity.actions %}
  47. {{ include(action.templatePath, { action: action }, with_context = false) }}
  48. {% endfor %}
  49. {% endblock %}
  50. {% block main %}
  51. <div class="col-8">
  52. <div class="card">
  53. <div class="card-body">
  54. {% block edit_form %}
  55. {{ form(edit_form) }}
  56. {% endblock edit_form %}
  57. {% block delete_form %}
  58. {{ include('@EasyAdmin/crud/includes/_delete_form.html.twig', { entity_id: entity.primaryKeyValue }, with_context = false) }}
  59. {% endblock delete_form %}
  60. </div>
  61. </div>
  62. </div>
  63. {% endblock %}
  64. {% block body_javascript %}
  65. {{ parent() }}
  66. <script type="text/javascript">
  67. $(function () {
  68. $('.ea-edit-form').areYouSure({'message': '{{ 'form.are_you_sure'|trans({}, 'EasyAdminBundle')|e('js') }}'});
  69. const entityForm = document.querySelector('form.ea-edit-form');
  70. const inputFieldsSelector = 'input,select,textarea';
  71. // Adding visual feedback for invalid fields: any ".form-group" with invalid fields
  72. // receives "has-error" class. The class is removed on click on the ".form-group"
  73. // itself to support custom/complex fields.
  74. entityForm.addEventListener('submit', function (submitEvent) {
  75. entityForm.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  76. if (!input.validity.valid) {
  77. const formGroup = input.closest('div.form-group');
  78. formGroup.classList.add('has-error');
  79. formGroup.addEventListener('click', function onFormGroupClick() {
  80. formGroup.classList.remove('has-error');
  81. formGroup.removeEventListener('click', onFormGroupClick);
  82. });
  83. }
  84. });
  85. const eaEvent = new CustomEvent('ea.form.submit', {
  86. cancelable: true,
  87. detail: {page: 'edit', form: entityForm}
  88. });
  89. const eaEventResult = document.dispatchEvent(eaEvent);
  90. if (false === eaEventResult) {
  91. submitEvent.preventDefault();
  92. submitEvent.stopPropagation();
  93. }
  94. });
  95. // forms with tabs require some special treatment for errors. The problem
  96. // is when the field with errors is included in a tab not currently visible.
  97. // Browser shows this error "An invalid form control with name='...' is not focusable."
  98. // So, the user clicks on Submit button, the form is not submitted and the error
  99. // is not displayed. This JavaScript code ensures that each tab shows a badge with
  100. // the number of errors in it.
  101. entityForm.addEventListener('submit', function () {
  102. const formTabPanes = entityForm.querySelectorAll('.tab-pane');
  103. if (0 === formTabPanes.length) {
  104. return;
  105. }
  106. let firstNavTabItemWithError = null;
  107. formTabPanes.forEach(function (tabPane) {
  108. let tabPaneNumErrors = 0;
  109. tabPane.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  110. if (!input.validity.valid) {
  111. tabPaneNumErrors++;
  112. }
  113. });
  114. let navTabItem = entityForm.querySelector('.nav-item a[href="#' + tabPane.id + '"]');
  115. let existingErrorBadge = navTabItem.querySelector('span.badge.badge-danger');
  116. if (null !== existingErrorBadge) {
  117. navTabItem.removeChild(existingErrorBadge);
  118. }
  119. if (tabPaneNumErrors > 0) {
  120. let newErrorBadge = document.createElement('span');
  121. newErrorBadge.classList.add('badge', 'badge-danger');
  122. newErrorBadge.title = 'form.tab.error_badge_title';
  123. newErrorBadge.textContent = tabPaneNumErrors;
  124. navTabItem.appendChild(newErrorBadge);
  125. if (null === firstNavTabItemWithError) {
  126. firstNavTabItemWithError = navTabItem;
  127. }
  128. }
  129. });
  130. if (firstNavTabItemWithError) {
  131. firstNavTabItemWithError.click();
  132. }
  133. });
  134. $('.action-delete').on('click', function (e) {
  135. e.preventDefault();
  136. const formAction = $(this).attr('formaction');
  137. $('#modal-delete').modal({backdrop: true, keyboard: true})
  138. .off('click', '#modal-delete-button')
  139. .on('click', '#modal-delete-button', function () {
  140. $('#delete-form').attr('action', formAction).trigger('submit');
  141. });
  142. });
  143. });
  144. </script>
  145. <
  146. {% endblock %}