Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
3 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. {% block new_form %}
  53. {{ form(new_form) }}
  54. {% endblock new_form %}
  55. </div>
  56. </div>
  57. </div>
  58. {% endblock %}
  59. {% block body_javascript %}
  60. {{ parent() }}
  61. {# <script type="text/javascript">
  62. $(function () {
  63. $('.ea-new-form').areYouSure({'message': '{{ 'form.are_you_sure'|trans({}, 'EasyAdminBundle')|e('js') }}'});
  64. const entityForm = document.querySelector('form.ea-new-form');
  65. const inputFieldsSelector = 'input,select,textarea';
  66. // Adding visual feedback for invalid fields: any ".form-group" with invalid fields
  67. // receives "has-error" class. The class is removed on click on the ".form-group"
  68. // itself to support custom/complex fields.
  69. entityForm.addEventListener('submit', function (submitEvent) {
  70. entityForm.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  71. if (!input.validity.valid) {
  72. const formGroup = input.closest('div.form-group');
  73. formGroup.classList.add('has-error');
  74. formGroup.addEventListener('click', function onFormGroupClick() {
  75. formGroup.classList.remove('has-error');
  76. formGroup.removeEventListener('click', onFormGroupClick);
  77. });
  78. }
  79. });
  80. const eaEvent = new CustomEvent('ea.form.submit', {
  81. cancelable: true,
  82. detail: {page: 'new', form: entityForm}
  83. });
  84. const eaEventResult = document.dispatchEvent(eaEvent);
  85. if (false === eaEventResult) {
  86. submitEvent.preventDefault();
  87. submitEvent.stopPropagation();
  88. }
  89. });
  90. // forms with tabs require some special treatment for errors. The problem
  91. // is when the field with errors is included in a tab not currently visible.
  92. // Browser shows this error "An invalid form control with name='...' is not focusable."
  93. // So, the user clicks on Submit button, the form is not submitted and the error
  94. // is not displayed. This JavaScript code ensures that each tab shows a badge with
  95. // the number of errors in it.
  96. entityForm.addEventListener('submit', function () {
  97. const formTabPanes = entityForm.querySelectorAll('.tab-pane');
  98. if (0 === formTabPanes.length) {
  99. return;
  100. }
  101. let firstNavTabItemWithError = null;
  102. formTabPanes.forEach(function (tabPane) {
  103. let tabPaneNumErrors = 0;
  104. tabPane.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  105. if (!input.validity.valid) {
  106. tabPaneNumErrors++;
  107. }
  108. });
  109. let navTabItem = entityForm.querySelector('.nav-item a[href="#' + tabPane.id + '"]');
  110. let existingErrorBadge = navTabItem.querySelector('span.badge.badge-danger');
  111. if (null !== existingErrorBadge) {
  112. navTabItem.removeChild(existingErrorBadge);
  113. }
  114. if (tabPaneNumErrors > 0) {
  115. let newErrorBadge = document.createElement('span');
  116. newErrorBadge.classList.add('badge', 'badge-danger');
  117. newErrorBadge.title = 'form.tab.error_badge_title';
  118. newErrorBadge.textContent = tabPaneNumErrors;
  119. navTabItem.appendChild(newErrorBadge);
  120. if (null === firstNavTabItemWithError) {
  121. firstNavTabItemWithError = navTabItem;
  122. }
  123. }
  124. });
  125. if (firstNavTabItemWithError) {
  126. firstNavTabItemWithError.click();
  127. }
  128. });
  129. // prevent multiple form submissions to avoid creating duplicated entities
  130. entityForm.addEventListener('submit', function () {
  131. // this timeout is needed to include the disabled button into the submitted form
  132. setTimeout(function () {
  133. const submitButtons = entityForm.querySelectorAll('[type="submit"]');
  134. submitButtons.forEach(function (button) {
  135. button.setAttribute('disabled', 'disabled');
  136. });
  137. }, 1);
  138. }, false);
  139. });
  140. </script>
  141. {{ include('@EasyAdmin/crud/includes/_select2_widget.html.twig') }} #}
  142. {% endblock %}