Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

132 linhas
5.7KB

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