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.

142 lines
6.0KB

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