From 73225949aa4c9d300e8f88bc1ebccc81ce5dea49 Mon Sep 17 00:00:00 2001 From: pxpm Date: Thu, 4 Sep 2025 16:14:42 +0100 Subject: [PATCH 01/24] wip --- src/app/View/Components/DataFormModal.php | 63 +++ src/app/View/Components/Dataform.php | 1 - .../components/dataform/modal-form.blade.php | 364 ++++++++++++++++++ .../views/crud/fields/summernote.blade.php | 4 + .../views/crud/form_content.blade.php | 20 +- .../views/crud/inc/show_fields.blade.php | 5 +- 6 files changed, 446 insertions(+), 11 deletions(-) create mode 100644 src/app/View/Components/DataFormModal.php create mode 100644 src/resources/views/crud/components/dataform/modal-form.blade.php diff --git a/src/app/View/Components/DataFormModal.php b/src/app/View/Components/DataFormModal.php new file mode 100644 index 0000000000..a66031edca --- /dev/null +++ b/src/app/View/Components/DataFormModal.php @@ -0,0 +1,63 @@ + $this->crud, + 'id' => $this->id, + 'operation' => $this->operation, + 'formRouteOperation' => $this->formRouteOperation, + 'hasUploadFields' => $this->hasUploadFields, + 'refreshDatatable' => $this->refreshDatatable, + 'action' => $this->action, + 'method' => $this->method, + 'title' => $this->title, + 'classes' => $this->classes, + ]); + } +} \ No newline at end of file diff --git a/src/app/View/Components/Dataform.php b/src/app/View/Components/Dataform.php index 42479f1bb8..62cae01c9a 100644 --- a/src/app/View/Components/Dataform.php +++ b/src/app/View/Components/Dataform.php @@ -30,7 +30,6 @@ public function __construct( public $entry = null, public ?Closure $setup = null, public bool $focusOnFirstField = false, - ) { // Get CRUD panel instance from the controller CrudManager::setActiveController($controller); diff --git a/src/resources/views/crud/components/dataform/modal-form.blade.php b/src/resources/views/crud/components/dataform/modal-form.blade.php new file mode 100644 index 0000000000..dd7fa1aa92 --- /dev/null +++ b/src/resources/views/crud/components/dataform/modal-form.blade.php @@ -0,0 +1,364 @@ + {{-- Modal HTML (initially hidden from DOM) --}} + @php + if(isset($formRouteOperation)) { + if(!\Str::isUrl($formRouteOperation)) { + $formRouteOperation = url($crud->route . '/' . $formRouteOperation); + } + } + @endphp +@push('after_scripts') @if (request()->ajax()) @endpush @endif +
+ +
+@if (!request()->ajax()) @endpush @endif +@push('after_scripts') @if (request()->ajax()) @endpush @endif + +@if (!request()->ajax()) @endpush @endif \ No newline at end of file diff --git a/src/resources/views/crud/fields/summernote.blade.php b/src/resources/views/crud/fields/summernote.blade.php index 4a8e08d4b8..8f53f8a468 100644 --- a/src/resources/views/crud/fields/summernote.blade.php +++ b/src/resources/views/crud/fields/summernote.blade.php @@ -41,6 +41,10 @@ .note-editor.note-frame .note-status-output, .note-editor.note-airframe .note-status-output { height: auto; } + + .note-modal { + z-index: 1060 !important; /* Higher than Bootstrap's default modal z-index */ + } @endBassetBlock @endpush diff --git a/src/resources/views/crud/form_content.blade.php b/src/resources/views/crud/form_content.blade.php index 54c1e81eb2..0a173df67e 100644 --- a/src/resources/views/crud/form_content.blade.php +++ b/src/resources/views/crud/form_content.blade.php @@ -1,4 +1,4 @@ -route) }}> + {{-- See if we're using tabs --}} @@ -100,8 +100,9 @@ function handleFocusOnSelect2Field(firstField){ jQuery('document').ready(function($){ - // trigger the javascript for all fields that have their js defined in a separate method - initializeFieldsWithJavascript('form'); + @if(! isset($initFields) || $initFields !== false) + initializeFieldsWithJavascript('form'); + @endif // Retrieves the current form data function getFormData() { @@ -215,14 +216,15 @@ function preventUnload(event) { @else focusField = getFirstFocusableField($('form')); @endif + if(focusField.length !== 0) { + const fieldOffset = focusField.offset().top; + const scrollTolerance = $(window).height() / 2; - const fieldOffset = focusField.offset().top; - const scrollTolerance = $(window).height() / 2; - - triggerFocusOnFirstInputField(focusField); + triggerFocusOnFirstInputField(focusField); - if( fieldOffset > scrollTolerance ){ - $('html, body').animate({scrollTop: (fieldOffset - 30)}); + if( fieldOffset > scrollTolerance ){ + $('html, body').animate({scrollTop: (fieldOffset - 30)}); + } } @endif diff --git a/src/resources/views/crud/inc/show_fields.blade.php b/src/resources/views/crud/inc/show_fields.blade.php index 74a05da7b9..0557f5ce74 100644 --- a/src/resources/views/crud/inc/show_fields.blade.php +++ b/src/resources/views/crud/inc/show_fields.blade.php @@ -1,5 +1,8 @@ {{-- Show the inputs --}} @foreach ($fields as $field) - @include($crud->getFirstFieldView($field['type'], $field['view_namespace'] ?? false), $field) + @include($crud->getFirstFieldView($field['type'], $field['view_namespace'] ?? false), [ + 'field' => $field, + 'inlineCreate' => $inlineCreate ?? false, + ]) @endforeach From 4a8fda0a3e2c09ef0cc9c0474327a4a29348e1f8 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 4 Sep 2025 15:15:01 +0000 Subject: [PATCH 02/24] Apply fixes from StyleCI [ci skip] [skip ci] --- src/app/View/Components/DataFormModal.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/View/Components/DataFormModal.php b/src/app/View/Components/DataFormModal.php index a66031edca..5e6e8aea70 100644 --- a/src/app/View/Components/DataFormModal.php +++ b/src/app/View/Components/DataFormModal.php @@ -1,6 +1,7 @@ $this->classes, ]); } -} \ No newline at end of file +} From 642c1204bc8c723b71173d005eee458a2749b470 Mon Sep 17 00:00:00 2001 From: pxpm Date: Thu, 4 Sep 2025 16:26:35 +0100 Subject: [PATCH 03/24] wip --- .../dataform/ajax_response.blade.php | 24 +++++++++++++++++++ .../datatable/datatable_logic.blade.php | 6 +++++ 2 files changed, 30 insertions(+) create mode 100644 src/resources/views/crud/components/dataform/ajax_response.blade.php diff --git a/src/resources/views/crud/components/dataform/ajax_response.blade.php b/src/resources/views/crud/components/dataform/ajax_response.blade.php new file mode 100644 index 0000000000..9a18e2fedc --- /dev/null +++ b/src/resources/views/crud/components/dataform/ajax_response.blade.php @@ -0,0 +1,24 @@ +@php +\Alert::flush(); +@endphp +
+{!! csrf_field() !!} +@include('crud::form_content', ['fields' => $crud->fields(), 'action' => 'edit', 'inlineCreate' => true, 'initFields' => false]) +
{{ json_encode(Basset::loaded()) }}
+
+ + +@foreach (app('widgets')->toArray() as $currentWidget) +@php + $currentWidget = \Backpack\CRUD\app\Library\Widget::add($currentWidget); +@endphp + @if($currentWidget->getAttribute('inline')) + @include($currentWidget->getFinalViewPath(), ['widget' => $currentWidget->toArray()]) + @endif +@endforeach + + +@stack('after_styles') +@stack('after_scripts') \ No newline at end of file diff --git a/src/resources/views/crud/components/datatable/datatable_logic.blade.php b/src/resources/views/crud/components/datatable/datatable_logic.blade.php index ca64d1def6..0a7862a16f 100644 --- a/src/resources/views/crud/components/datatable/datatable_logic.blade.php +++ b/src/resources/views/crud/components/datatable/datatable_logic.blade.php @@ -613,6 +613,12 @@ function setupTableEvents(tableId, config) { // on DataTable draw event run all functions in the queue $(`#${tableId}`).on('draw.dt', function() { + + document.getElementById(tableId).querySelectorAll('[id^="modalTemplate"]').forEach(function(modal) { + const newModal = modal.cloneNode(true); + document.body.appendChild(newModal); + modal.remove(); + }); // in datatables 2.0.3 the implementation was changed to use `replaceChildren`, for that reason scripts // that came with the response are no longer executed, like the delete button script or any other ajax // button created by the developer. For that reason, we move them to the end of the body From 52b042a3f9f0a1f6db6a941fb51a22d086fa927a Mon Sep 17 00:00:00 2001 From: pxpm Date: Mon, 8 Sep 2025 12:47:50 +0100 Subject: [PATCH 04/24] wip --- .../Controllers/Operations/CreateOperation.php | 4 +++- .../Controllers/Operations/UpdateOperation.php | 5 ++++- src/app/View/Components/DataFormModal.php | 5 +++-- src/resources/assets/css/common.css | 5 ++++- .../crud/components/dataform/modal-form.blade.php | 14 +++++++------- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/app/Http/Controllers/Operations/CreateOperation.php b/src/app/Http/Controllers/Operations/CreateOperation.php index e6282ff68f..06cbc3108e 100644 --- a/src/app/Http/Controllers/Operations/CreateOperation.php +++ b/src/app/Http/Controllers/Operations/CreateOperation.php @@ -60,7 +60,9 @@ public function create() $this->data['title'] = $this->crud->getTitle() ?? trans('backpack::crud.add').' '.$this->crud->entity_name; // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package - return view($this->crud->getCreateView(), $this->data); + return request()->ajax() ? + view('crud::components.dataform.ajax_response', $this->data) : + view($this->crud->getCreateView(), $this->data); } /** diff --git a/src/app/Http/Controllers/Operations/UpdateOperation.php b/src/app/Http/Controllers/Operations/UpdateOperation.php index f0c656092c..1b17d48578 100644 --- a/src/app/Http/Controllers/Operations/UpdateOperation.php +++ b/src/app/Http/Controllers/Operations/UpdateOperation.php @@ -82,9 +82,12 @@ public function edit($id) $this->data['id'] = $id; // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package - return view($this->crud->getEditView(), $this->data); + return request()->ajax() ? + view('crud::components.dataform.ajax_response', $this->data) : + view($this->crud->getEditView(), $this->data); } + /** * Update the specified resource in the database. * diff --git a/src/app/View/Components/DataFormModal.php b/src/app/View/Components/DataFormModal.php index 5e6e8aea70..98d2872591 100644 --- a/src/app/View/Components/DataFormModal.php +++ b/src/app/View/Components/DataFormModal.php @@ -4,7 +4,7 @@ use Closure; -class FormModal extends DataForm +class DataformModal extends DataForm { /** * Create a new component instance. @@ -27,6 +27,7 @@ public function __construct( public string $controller, public string $id = 'backpack-form', public string $operation = 'create', + public string $name = '', public string $formRouteOperation = 'create', public ?string $action = null, public string $method = 'post', @@ -38,7 +39,7 @@ public function __construct( public string $classes = 'modal-dialog modal-lg', public bool $refreshDatatable = false, ) { - parent::__construct($controller, $id, $operation, $action, $method); + parent::__construct($controller, $id, $name, $operation, $action, $method, $hasUploadFields, $entry, $setup, $focusOnFirstField); } /** diff --git a/src/resources/assets/css/common.css b/src/resources/assets/css/common.css index 4c6a13ac23..d73e2ef735 100644 --- a/src/resources/assets/css/common.css +++ b/src/resources/assets/css/common.css @@ -2,6 +2,7 @@ --table-row-hover: #f2f1ff; --select2-selected-item-background: #7c69ef; --select2-selected-item-color: #fff; + --btn-close-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000000'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e"); } .sidebar .nav-dropdown-items .nav-dropdown { @@ -254,7 +255,9 @@ div[id$="_wrapper"] .dt-processing { .modal .details-control { display: none; } - +.modal .btn-close, .modal .close { + background: transparent var(--btn-close-bg) center / .75rem auto no-repeat; +} .dtr-bs-modal .modal-body { padding: 0; } diff --git a/src/resources/views/crud/components/dataform/modal-form.blade.php b/src/resources/views/crud/components/dataform/modal-form.blade.php index dd7fa1aa92..f17378657f 100644 --- a/src/resources/views/crud/components/dataform/modal-form.blade.php +++ b/src/resources/views/crud/components/dataform/modal-form.blade.php @@ -1,11 +1,11 @@ - {{-- Modal HTML (initially hidden from DOM) --}} - @php - if(isset($formRouteOperation)) { - if(!\Str::isUrl($formRouteOperation)) { - $formRouteOperation = url($crud->route . '/' . $formRouteOperation); - } +{{-- Modal HTML (initially hidden from DOM) --}} +@php + if(isset($formRouteOperation)) { + if(!\Str::isUrl($formRouteOperation)) { + $formRouteOperation = url($crud->route . '/' . $formRouteOperation); } - @endphp + } +@endphp @push('after_scripts') @if (request()->ajax()) @endpush @endif