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.

edit.html.twig 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 %}