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.

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