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.

141 satır
5.9KB

  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. {% endblock %}
  38. {% block script_javascript %}
  39. {{ parent() }}
  40. <script src="{{ asset('bundles/lcshop/js/backend/script/default/init-edit.js') }}"></script>
  41. {#<script type="text/javascript">
  42. $(function() {
  43. $('.edit-form').areYouSure({ 'message': '{{ 'form.are_you_sure'|trans({}, 'EasyAdminBundle')|e('js') }}' });
  44. const entityForm = document.querySelector('form.edit-form');
  45. const formSubmitButton = entityForm.querySelector('button[type="submit"]');
  46. const inputFieldsSelector = 'input,select,textarea';
  47. // Adding visual feedback for invalid fields: any ".form-group" with invalid fields
  48. // receives "has-error" class. The class is removed on click on the ".form-group"
  49. // itself to support custom/complex fields.
  50. formSubmitButton.addEventListener('click', function() {
  51. entityForm.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  52. if (!input.validity.valid) {
  53. const formGroup = input.closest('div.form-group');
  54. formGroup.classList.add('has-error');
  55. formGroup.addEventListener('click', function onFormGroupClick() {
  56. formGroup.classList.remove('has-error');
  57. formGroup.removeEventListener('click', onFormGroupClick);
  58. });
  59. }
  60. });
  61. });
  62. // forms with tabs require some special treatment for errors. The problem
  63. // is when the field with errors is included in a tab not currently visible.
  64. // Browser shows this error "An invalid form control with name='...' is not focusable."
  65. // So, the user clicks on Submit button, the form is not submitted and the error
  66. // is not displayed. This JavaScript code ensures that each tab shows a badge with
  67. // the number of errors in it.
  68. formSubmitButton.addEventListener('click', function() {
  69. const formTabPanes = entityForm.querySelectorAll('.tab-pane');
  70. if (0 === formTabPanes.length) {
  71. return;
  72. }
  73. let firstNavTabItemWithError = null;
  74. formTabPanes.forEach(function (tabPane) {
  75. let tabPaneNumErrors = 0;
  76. tabPane.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  77. if (!input.validity.valid) {
  78. tabPaneNumErrors++;
  79. }
  80. });
  81. let navTabItem = entityForm.querySelector('.nav-item a[href="#' + tabPane.id + '"]');
  82. let existingErrorBadge = navTabItem.querySelector('span.badge.badge-danger');
  83. if (null !== existingErrorBadge) {
  84. navTabItem.removeChild(existingErrorBadge);
  85. }
  86. if (tabPaneNumErrors > 0) {
  87. let newErrorBadge = document.createElement('span');
  88. newErrorBadge.classList.add('badge', 'badge-danger');
  89. newErrorBadge.title = 'form.tab.error_badge_title';
  90. newErrorBadge.textContent = tabPaneNumErrors;
  91. navTabItem.appendChild(newErrorBadge);
  92. if (null === firstNavTabItemWithError) {
  93. firstNavTabItemWithError = navTabItem;
  94. }
  95. }
  96. });
  97. if (firstNavTabItemWithError) {
  98. firstNavTabItemWithError.click();
  99. }
  100. });
  101. $('a.action-delete').on('click', function(e) {
  102. e.preventDefault();
  103. $('#modal-delete').modal({ backdrop: true, keyboard: true })
  104. .off('click', '#modal-delete-button')
  105. .on('click', '#modal-delete-button', function () {
  106. $('#delete-form').trigger('submit');
  107. });
  108. });
  109. });
  110. </script>#}
  111. {% endblock %}