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.

190 lines
8.2KB

  1. {# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
  2. {# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
  3. {% extends ea.templatePath('layout') %}
  4. {% form_theme new_form with ea.crud.formThemes only %}
  5. {% trans_default_domain ea.i18n.translationDomain %}
  6. {% block body_id 'ea-new-' ~ entity.name ~ '-' ~ entity.primaryKeyValue %}
  7. {% block body_class 'ea-new ea-new-' ~ entity.name %}
  8. {% block configured_head_contents %}
  9. {{ parent() }}
  10. {% for htmlContent in new_form.vars.ea_crud_form.assets.headContents %}
  11. {{ htmlContent|raw }}
  12. {% endfor %}
  13. {% endblock %}
  14. {% block configured_stylesheets %}
  15. {{ parent() }}
  16. {% for css_asset in new_form.vars.ea_crud_form.assets.cssFiles %}
  17. <link rel="stylesheet" href="{{ asset(css_asset) }}">
  18. {% endfor %}
  19. {% for webpack_encore_entry in new_form.vars.ea_crud_form.assets.webpackEncoreEntries %}
  20. {{ ea_call_function_if_exists('encore_entry_link_tags', webpack_encore_entry) }}
  21. {% endfor %}
  22. {% endblock %}
  23. {% block configured_javascripts %}
  24. {{ parent() }}
  25. {% for js_asset in new_form.vars.ea_crud_form.assets.jsFiles %}
  26. <script src="{{ asset(js_asset) }}"></script>
  27. {% endfor %}
  28. {% for webpack_encore_entry in new_form.vars.ea_crud_form.assets.webpackEncoreEntries %}
  29. {{ ea_call_function_if_exists('encore_entry_script_tags', webpack_encore_entry) }}
  30. {% endfor %}
  31. {% endblock %}
  32. {% block content_title %}
  33. {# {%- apply spaceless -%}
  34. {% set default_title = ea.crud.defaultPageTitle('new')|trans(ea.i18n.translationParameters, 'EasyAdminBundle') %}
  35. {{ ea.crud.customPageTitle is null ? default_title|raw : ea.crud.customPageTitle('new')|trans(ea.i18n.translationParameters)|raw }}
  36. {%- endapply -%}#}
  37. {% endblock %}
  38. {% block content_header_wrapper %}
  39. {# {% for action in entity.actions %}
  40. {{ include(action.templatePath, { action: action }, with_context = false) }}
  41. {% endfor %}#}
  42. {% endblock %}
  43. {% block main %}
  44. <div class="col-8">
  45. <div class="card">
  46. <div class="card-status-top bg-primary"></div>
  47. <div class="card-header ">
  48. {% set default_title = ea.crud.defaultPageTitle('new')|trans(ea.i18n.translationParameters, 'EasyAdminBundle') %}
  49. <h2 class="card-title">{{ ea.crud.customPageTitle is null ? default_title|raw : ea.crud.customPageTitle('new')|trans(ea.i18n.translationParameters)|raw }}</h2>
  50. </div>
  51. <div class="card-body">
  52. <button type="button" data-bs-toggle="modal" data-bs-target="#niche">Launch modal</button>
  53. <div class="modal-dialog" role="document" id="niche">
  54. <div class="modal-content">
  55. <div class="modal-header">
  56. <h5 class="modal-title">Modal title</h5>
  57. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  58. </div>
  59. <div class="modal-body">
  60. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci animi beatae delectus deleniti dolorem eveniet facere fuga iste nemo nesciunt nihil odio perspiciatis, quia quis reprehenderit sit tempora totam unde.
  61. </div>
  62. <div class="modal-footer">
  63. <button type="button" class="btn me-auto" data-bs-dismiss="modal">Close</button>
  64. <button type="button" class="btn btn-primary" data-bs-dismiss="modal">Save changes</button>
  65. </div>
  66. </div>
  67. </div>
  68. {% block new_form %}
  69. {{ form(new_form) }}
  70. {% endblock new_form %}
  71. </div>
  72. </div>
  73. </div>
  74. {% endblock %}
  75. {% block body_javascript %}
  76. {{ parent() }}
  77. {# <script type="text/javascript">
  78. $(function () {
  79. $('.ea-new-form').areYouSure({'message': '{{ 'form.are_you_sure'|trans({}, 'EasyAdminBundle')|e('js') }}'});
  80. const entityForm = document.querySelector('form.ea-new-form');
  81. const inputFieldsSelector = 'input,select,textarea';
  82. // Adding visual feedback for invalid fields: any ".form-group" with invalid fields
  83. // receives "has-error" class. The class is removed on click on the ".form-group"
  84. // itself to support custom/complex fields.
  85. entityForm.addEventListener('submit', function (submitEvent) {
  86. entityForm.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  87. if (!input.validity.valid) {
  88. const formGroup = input.closest('div.form-group');
  89. formGroup.classList.add('has-error');
  90. formGroup.addEventListener('click', function onFormGroupClick() {
  91. formGroup.classList.remove('has-error');
  92. formGroup.removeEventListener('click', onFormGroupClick);
  93. });
  94. }
  95. });
  96. const eaEvent = new CustomEvent('ea.form.submit', {
  97. cancelable: true,
  98. detail: {page: 'new', form: entityForm}
  99. });
  100. const eaEventResult = document.dispatchEvent(eaEvent);
  101. if (false === eaEventResult) {
  102. submitEvent.preventDefault();
  103. submitEvent.stopPropagation();
  104. }
  105. });
  106. // forms with tabs require some special treatment for errors. The problem
  107. // is when the field with errors is included in a tab not currently visible.
  108. // Browser shows this error "An invalid form control with name='...' is not focusable."
  109. // So, the user clicks on Submit button, the form is not submitted and the error
  110. // is not displayed. This JavaScript code ensures that each tab shows a badge with
  111. // the number of errors in it.
  112. entityForm.addEventListener('submit', function () {
  113. const formTabPanes = entityForm.querySelectorAll('.tab-pane');
  114. if (0 === formTabPanes.length) {
  115. return;
  116. }
  117. let firstNavTabItemWithError = null;
  118. formTabPanes.forEach(function (tabPane) {
  119. let tabPaneNumErrors = 0;
  120. tabPane.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  121. if (!input.validity.valid) {
  122. tabPaneNumErrors++;
  123. }
  124. });
  125. let navTabItem = entityForm.querySelector('.nav-item a[href="#' + tabPane.id + '"]');
  126. let existingErrorBadge = navTabItem.querySelector('span.badge.badge-danger');
  127. if (null !== existingErrorBadge) {
  128. navTabItem.removeChild(existingErrorBadge);
  129. }
  130. if (tabPaneNumErrors > 0) {
  131. let newErrorBadge = document.createElement('span');
  132. newErrorBadge.classList.add('badge', 'badge-danger');
  133. newErrorBadge.title = 'form.tab.error_badge_title';
  134. newErrorBadge.textContent = tabPaneNumErrors;
  135. navTabItem.appendChild(newErrorBadge);
  136. if (null === firstNavTabItemWithError) {
  137. firstNavTabItemWithError = navTabItem;
  138. }
  139. }
  140. });
  141. if (firstNavTabItemWithError) {
  142. firstNavTabItemWithError.click();
  143. }
  144. });
  145. // prevent multiple form submissions to avoid creating duplicated entities
  146. entityForm.addEventListener('submit', function () {
  147. // this timeout is needed to include the disabled button into the submitted form
  148. setTimeout(function () {
  149. const submitButtons = entityForm.querySelectorAll('[type="submit"]');
  150. submitButtons.forEach(function (button) {
  151. button.setAttribute('disabled', 'disabled');
  152. });
  153. }, 1);
  154. }, false);
  155. });
  156. </script>
  157. {{ include('@EasyAdmin/crud/includes/_select2_widget.html.twig') }}#}
  158. {% endblock %}