Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

134 Zeilen
5.8KB

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