From df6adc60273d0913859e84481813cf2447cda86b Mon Sep 17 00:00:00 2001 From: pxpm Date: Tue, 10 Jun 2025 12:24:03 +0100 Subject: [PATCH 01/13] wip --- src/CrudPanelManager.php | 11 +- .../Operations/CreateOperation.php | 30 +++ src/app/View/Components/Form.php | 46 ++++ src/app/View/Components/FormModal.php | 47 ++++ .../views/crud/components/form/form.blade.php | 64 ++++++ .../crud/components/form/modal_form.blade.php | 213 ++++++++++++++++++ .../crud/fields/form/create_form.blade.php | 33 +++ .../crud/fields/form/show_fields.blade.php | 8 + .../crud/fields/form/tabbed_fields.blade.php | 62 +++++ .../views/crud/form_content.blade.php | 23 +- 10 files changed, 525 insertions(+), 12 deletions(-) create mode 100644 src/app/View/Components/Form.php create mode 100644 src/app/View/Components/FormModal.php create mode 100644 src/resources/views/crud/components/form/form.blade.php create mode 100644 src/resources/views/crud/components/form/modal_form.blade.php create mode 100644 src/resources/views/crud/fields/form/create_form.blade.php create mode 100644 src/resources/views/crud/fields/form/show_fields.blade.php create mode 100644 src/resources/views/crud/fields/form/tabbed_fields.blade.php diff --git a/src/CrudPanelManager.php b/src/CrudPanelManager.php index cb7af75a2f..227fa77b08 100644 --- a/src/CrudPanelManager.php +++ b/src/CrudPanelManager.php @@ -69,8 +69,9 @@ public function setupCrudPanel(string $controller, ?string $operation = null): C $crud->setOperation($operation); $primaryControllerRequest = $this->cruds[array_key_first($this->cruds)]->getRequest(); - if (! $crud->isInitialized()) { + if (! $crud->isInitialized() || ! $this->isOperationInitialized($controller::class, $operation)) { self::setActiveController($controller::class); + $crud->initialized = false; $controller->initializeCrudPanel($primaryControllerRequest, $crud); self::unsetActiveController(); $crud = $this->cruds[$controller::class]; @@ -106,6 +107,14 @@ public function getInitializedOperations(string $controller): array return $this->initializedOperations[$controller] ?? []; } + /** + * Check if a specific operation has been initialized for a controller. + */ + public function isOperationInitialized(string $controller, string $operation): bool + { + return in_array($operation, $this->getInitializedOperations($controller), true); + } + /** * Store a CrudPanel instance for a specific controller. */ diff --git a/src/app/Http/Controllers/Operations/CreateOperation.php b/src/app/Http/Controllers/Operations/CreateOperation.php index e6282ff68f..089825f13b 100644 --- a/src/app/Http/Controllers/Operations/CreateOperation.php +++ b/src/app/Http/Controllers/Operations/CreateOperation.php @@ -27,6 +27,12 @@ protected function setupCreateRoutes($segment, $routeName, $controller) 'uses' => $controller.'@store', 'operation' => 'create', ]); + + Route::get($segment.'/create-form', [ + 'as' => $routeName.'.create-form', + 'uses' => $controller.'@createForm', + 'operation' => 'create', + ]); } /** @@ -63,6 +69,30 @@ public function create() return view($this->crud->getCreateView(), $this->data); } + public function createForm() + { + $this->crud->hasAccessOrFail('create'); + + // if the request isn't an AJAX request, return a 404 + if (! request()->ajax()) { + abort(404); + } + + return view( + $this->crud->getFirstFieldView('form.create_form'), + [ + 'fields' => $this->crud->getCreateFields(), + 'action' => 'create', + 'crud' => $this->crud, + 'modalClass' => request()->get('modal_class'), + 'parentLoadedAssets' => request()->get('parent_loaded_assets'), + ] + ); + + } + + + /** * Store a newly created resource in the database. * diff --git a/src/app/View/Components/Form.php b/src/app/View/Components/Form.php new file mode 100644 index 0000000000..65210956a5 --- /dev/null +++ b/src/app/View/Components/Form.php @@ -0,0 +1,46 @@ +crud = CrudManager::setupCrudPanel($controller, $operation); + $this->operation = $operation; + $this->formAction = $action ?? url($this->crud->route); + } + + /** + * Get the view / contents that represent the component. + * + * @return \Illuminate\Contracts\View\View|\Closure|string + */ + public function render() + { + return view('crud::components.form.form', [ + 'crud' => $this->crud, + 'operation' => $this->operation, + 'formAction' => $this->formAction, + 'formMethod' => $this->formMethod, + ]); + } +} \ No newline at end of file diff --git a/src/app/View/Components/FormModal.php b/src/app/View/Components/FormModal.php new file mode 100644 index 0000000000..4273474903 --- /dev/null +++ b/src/app/View/Components/FormModal.php @@ -0,0 +1,47 @@ + $this->crud, + 'operation' => $this->operation, + 'formAction' => $this->formAction, + 'formMethod' => $this->formMethod, + 'buttonText' => $this->buttonText, + 'modalTitle' => $this->modalTitle, + 'buttonClass' => $this->buttonClass, + ]); + } +} \ No newline at end of file diff --git a/src/resources/views/crud/components/form/form.blade.php b/src/resources/views/crud/components/form/form.blade.php new file mode 100644 index 0000000000..68e90809db --- /dev/null +++ b/src/resources/views/crud/components/form/form.blade.php @@ -0,0 +1,64 @@ +
+
+

{!! $crud->getSubheading() ?? trans('backpack::crud.add').' '.$crud->entity_name !!}

+
+
+
+ @include('crud::inc.grouped_errors') + +
hasUploadFields($operation)) + enctype="multipart/form-data" + @endif + > + {!! csrf_field() !!} + @if($formMethod !== 'post') + @method($formMethod) + @endif + + {{-- Include the form fields --}} + @include('crud::form_content', ['fields' => $crud->fields(), 'action' => $operation]) + + {{-- This makes sure that all field assets are loaded. --}} +
{{ json_encode(Basset::loaded()) }}
+ + {{-- Include form save buttons --}} + @if(!isset($hideButtons) || !$hideButtons) +
+ + {{ trans('backpack::crud.cancel') }} +
+ @endif +
+
+
+
+ +@push('after_scripts') + +@endpush \ No newline at end of file diff --git a/src/resources/views/crud/components/form/modal_form.blade.php b/src/resources/views/crud/components/form/modal_form.blade.php new file mode 100644 index 0000000000..229184abf3 --- /dev/null +++ b/src/resources/views/crud/components/form/modal_form.blade.php @@ -0,0 +1,213 @@ + {{-- Button to trigger modal --}} + + {{-- Modal HTML (initially hidden from DOM) --}} + @push('after_scripts') +
+ +
+@endpush + +@push('after_scripts') + +@endpush \ No newline at end of file diff --git a/src/resources/views/crud/fields/form/create_form.blade.php b/src/resources/views/crud/fields/form/create_form.blade.php new file mode 100644 index 0000000000..681ef5c570 --- /dev/null +++ b/src/resources/views/crud/fields/form/create_form.blade.php @@ -0,0 +1,33 @@ + +
hasUploadFields('create')) + enctype="multipart/form-data" + @endif +> + {!! csrf_field() !!} + + +{{-- See if we're using tabs --}} +@if ($crud->tabsEnabled() && count($crud->getTabs())) + @include($crud->getFirstFieldView('form.tabbed_fields')) + +@else +
+
+ @include($crud->getFirstFieldView('form.show_fields'), ['fields' => $crud->fields()]) +
+
+@endif + +
+ +@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 \ No newline at end of file diff --git a/src/resources/views/crud/fields/form/show_fields.blade.php b/src/resources/views/crud/fields/form/show_fields.blade.php new file mode 100644 index 0000000000..c252f317c3 --- /dev/null +++ b/src/resources/views/crud/fields/form/show_fields.blade.php @@ -0,0 +1,8 @@ +{{-- Show the inputs --}} +@foreach ($fields as $field) + @php + $fieldView = $crud->getFirstFieldView($field['type'], $field['view_namespace'] ?? false); + @endphp + + @include($fieldView, ['field' => $field, 'inlineCreate' => true]) +@endforeach \ No newline at end of file diff --git a/src/resources/views/crud/fields/form/tabbed_fields.blade.php b/src/resources/views/crud/fields/form/tabbed_fields.blade.php new file mode 100644 index 0000000000..17436b6ecf --- /dev/null +++ b/src/resources/views/crud/fields/form/tabbed_fields.blade.php @@ -0,0 +1,62 @@ +@php + $horizontalTabs = $crud->getTabsType()=='horizontal' ? true : false; + + if ($errors->any() && array_key_exists(array_keys($errors->messages())[0], $crud->getCurrentFields()) && + array_key_exists('tab', $crud->getCurrentFields()[array_keys($errors->messages())[0]])) { + $tabWithError = ($crud->getCurrentFields()[array_keys($errors->messages())[0]]['tab']); + } +@endphp + +@push('crud_fields_styles') + +@endpush + +@if ($crud->getFieldsWithoutATab()->filter(function ($value, $key) { return $value['type'] != 'hidden'; })->count()) +
+
+ @include($crud->getFirstFieldView('relationship.inc.show_fields'), ['fields' => $crud->getFieldsWithoutATab()]) +
+
+@else + @include($crud->getFirstFieldView('relationship.inc.show_fields'), ['fields' => $crud->getFieldsWithoutATab()]) +@endif + +
+ + +
+ diff --git a/src/resources/views/crud/form_content.blade.php b/src/resources/views/crud/form_content.blade.php index 705a3785ad..92ee70187b 100644 --- a/src/resources/views/crud/form_content.blade.php +++ b/src/resources/views/crud/form_content.blade.php @@ -15,19 +15,19 @@ {{-- Define blade stacks so css and js can be pushed from the fields to these sections. --}} -@section('after_styles') +@push('after_styles') {{-- CRUD FORM CONTENT - crud_fields_styles stack --}} @stack('crud_fields_styles') -@endsection +@endpush -@section('after_scripts') +@push('after_scripts') {{-- CRUD FORM CONTENT - crud_fields_scripts stack --}} @stack('crud_fields_scripts') - @include('crud::inc.form_fields_script') -@endsection +@endpush From b93bc1d84b82975e5e06489cbeb83476bdb21cf6 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 10 Jun 2025 11:26:02 +0000 Subject: [PATCH 02/13] Apply fixes from StyleCI [ci skip] [skip ci] --- src/CrudPanelManager.php | 2 +- .../Controllers/Operations/CreateOperation.php | 13 +++++-------- src/app/View/Components/Form.php | 10 +++++----- src/app/View/Components/FormModal.php | 16 ++++++++-------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/CrudPanelManager.php b/src/CrudPanelManager.php index 227fa77b08..e7cfe4add7 100644 --- a/src/CrudPanelManager.php +++ b/src/CrudPanelManager.php @@ -107,7 +107,7 @@ public function getInitializedOperations(string $controller): array return $this->initializedOperations[$controller] ?? []; } - /** + /** * Check if a specific operation has been initialized for a controller. */ public function isOperationInitialized(string $controller, string $operation): bool diff --git a/src/app/Http/Controllers/Operations/CreateOperation.php b/src/app/Http/Controllers/Operations/CreateOperation.php index 089825f13b..0d3b3ae0ff 100644 --- a/src/app/Http/Controllers/Operations/CreateOperation.php +++ b/src/app/Http/Controllers/Operations/CreateOperation.php @@ -81,17 +81,14 @@ public function createForm() return view( $this->crud->getFirstFieldView('form.create_form'), [ - 'fields' => $this->crud->getCreateFields(), - 'action' => 'create', - 'crud' => $this->crud, - 'modalClass' => request()->get('modal_class'), + 'fields' => $this->crud->getCreateFields(), + 'action' => 'create', + 'crud' => $this->crud, + 'modalClass' => request()->get('modal_class'), 'parentLoadedAssets' => request()->get('parent_loaded_assets'), ] ); - - } - - + } /** * Store a newly created resource in the database. diff --git a/src/app/View/Components/Form.php b/src/app/View/Components/Form.php index 65210956a5..dcea4bb86f 100644 --- a/src/app/View/Components/Form.php +++ b/src/app/View/Components/Form.php @@ -12,10 +12,10 @@ class Form extends Component /** * Create a new component instance. * - * @param string $controller The CRUD controller class name - * @param string $operation The operation to use (create, update, etc.) - * @param string|null $action Custom form action URL - * @param string $method Form method (post, put, etc.) + * @param string $controller The CRUD controller class name + * @param string $operation The operation to use (create, update, etc.) + * @param string|null $action Custom form action URL + * @param string $method Form method (post, put, etc.) */ public function __construct( public string $controller, @@ -43,4 +43,4 @@ public function render() 'formMethod' => $this->formMethod, ]); } -} \ No newline at end of file +} diff --git a/src/app/View/Components/FormModal.php b/src/app/View/Components/FormModal.php index 4273474903..2064ea975b 100644 --- a/src/app/View/Components/FormModal.php +++ b/src/app/View/Components/FormModal.php @@ -7,13 +7,13 @@ class FormModal extends Form /** * Create a new component instance. * - * @param string $controller The CRUD controller class name - * @param string $operation The operation to use (create, update, etc.) - * @param string|null $action Custom form action URL - * @param string $method Form method (post, put, etc.) - * @param string $buttonText Text to display on the button that opens the modal - * @param string $modalTitle Title for the modal - * @param string $buttonClass CSS classes for the button + * @param string $controller The CRUD controller class name + * @param string $operation The operation to use (create, update, etc.) + * @param string|null $action Custom form action URL + * @param string $method Form method (post, put, etc.) + * @param string $buttonText Text to display on the button that opens the modal + * @param string $modalTitle Title for the modal + * @param string $buttonClass CSS classes for the button */ public function __construct( public string $controller, @@ -44,4 +44,4 @@ public function render() 'buttonClass' => $this->buttonClass, ]); } -} \ No newline at end of file +} From 1b77eb3b385b0147b54a754fa2725aec81312ca5 Mon Sep 17 00:00:00 2001 From: pxpm Date: Fri, 13 Jun 2025 14:42:11 +0100 Subject: [PATCH 03/13] wip --- .../Operations/CreateOperation.php | 10 +- .../Operations/UpdateOperation.php | 6 +- src/app/View/Components/Form.php | 13 ++- src/app/View/Components/FormModal.php | 16 +-- .../views/crud/components/form/form.blade.php | 57 ++++----- .../components/form/form_ajax_view.blade.php | 33 ++++++ .../crud/components/form/modal_form.blade.php | 108 +++++++++++------- .../views/crud/widgets/form.blade.php | 18 +++ 8 files changed, 160 insertions(+), 101 deletions(-) create mode 100644 src/resources/views/crud/components/form/form_ajax_view.blade.php create mode 100644 src/resources/views/crud/widgets/form.blade.php diff --git a/src/app/Http/Controllers/Operations/CreateOperation.php b/src/app/Http/Controllers/Operations/CreateOperation.php index 0d3b3ae0ff..b5e47adbe2 100644 --- a/src/app/Http/Controllers/Operations/CreateOperation.php +++ b/src/app/Http/Controllers/Operations/CreateOperation.php @@ -27,12 +27,6 @@ protected function setupCreateRoutes($segment, $routeName, $controller) 'uses' => $controller.'@store', 'operation' => 'create', ]); - - Route::get($segment.'/create-form', [ - 'as' => $routeName.'.create-form', - 'uses' => $controller.'@createForm', - 'operation' => 'create', - ]); } /** @@ -66,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.form.form_ajax_view', $this->data) : + view($this->crud->getCreateView(), $this->data); } public function createForm() diff --git a/src/app/Http/Controllers/Operations/UpdateOperation.php b/src/app/Http/Controllers/Operations/UpdateOperation.php index f0c656092c..91fa4d4930 100644 --- a/src/app/Http/Controllers/Operations/UpdateOperation.php +++ b/src/app/Http/Controllers/Operations/UpdateOperation.php @@ -61,7 +61,7 @@ protected function setupUpdateDefaults() * @param int $id * @return \Illuminate\Contracts\View\View */ - public function edit($id) + public function edit($id, $view = true) { $this->crud->hasAccessOrFail('update'); @@ -82,7 +82,9 @@ 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::form_ajax_view', $this->data) : + view($this->crud->getEditView(), $this->data); } /** diff --git a/src/app/View/Components/Form.php b/src/app/View/Components/Form.php index dcea4bb86f..c23dcbc7d7 100644 --- a/src/app/View/Components/Form.php +++ b/src/app/View/Components/Form.php @@ -19,14 +19,15 @@ class Form extends Component */ public function __construct( public string $controller, + public string $id = 'backpack-form', public string $operation = 'create', - public ?string $formAction = null, - public string $formMethod = 'post' + public ?string $action = null, + public string $method = 'post' ) { // Get CRUD panel instance from the controller $this->crud = CrudManager::setupCrudPanel($controller, $operation); $this->operation = $operation; - $this->formAction = $action ?? url($this->crud->route); + $this->action = $action ?? url($this->crud->route); } /** @@ -38,9 +39,11 @@ public function render() { return view('crud::components.form.form', [ 'crud' => $this->crud, + 'saveAction' => $this->crud->getSaveAction(), + 'id' => $this->id, 'operation' => $this->operation, - 'formAction' => $this->formAction, - 'formMethod' => $this->formMethod, + 'action' => $this->action, + 'method' => $this->method, ]); } } diff --git a/src/app/View/Components/FormModal.php b/src/app/View/Components/FormModal.php index 2064ea975b..cbe43faf1d 100644 --- a/src/app/View/Components/FormModal.php +++ b/src/app/View/Components/FormModal.php @@ -17,14 +17,15 @@ class FormModal extends Form */ public function __construct( public string $controller, + public string $id = 'backpack-form', public string $operation = 'create', + public string $formRouteOperation = 'create', public ?string $action = null, public string $method = 'post', - public string $buttonText = 'Open Form', public string $modalTitle = 'Form', - public string $buttonClass = 'btn btn-primary' + public string $modalClasses = "modal-dialog modal-lg" ) { - parent::__construct($controller, $operation, $action, $method); + parent::__construct($controller, $id, $operation, $action, $method); } /** @@ -36,12 +37,13 @@ public function render() { return view('crud::components.form.modal_form', [ 'crud' => $this->crud, + 'id' => $this->id, 'operation' => $this->operation, - 'formAction' => $this->formAction, - 'formMethod' => $this->formMethod, - 'buttonText' => $this->buttonText, + 'formRouteOperation' => $this->formRouteOperation, + 'action' => $this->action, + 'method' => $this->method, 'modalTitle' => $this->modalTitle, - 'buttonClass' => $this->buttonClass, + 'modalClasses' => $this->modalClasses, ]); } } diff --git a/src/resources/views/crud/components/form/form.blade.php b/src/resources/views/crud/components/form/form.blade.php index 68e90809db..1952fb4c6e 100644 --- a/src/resources/views/crud/components/form/form.blade.php +++ b/src/resources/views/crud/components/form/form.blade.php @@ -1,47 +1,32 @@ -
-
-

{!! $crud->getSubheading() ?? trans('backpack::crud.add').' '.$crud->entity_name !!}

-
-
-
- @include('crud::inc.grouped_errors') +
+ @include('crud::inc.grouped_errors') -
hasUploadFields($operation)) - enctype="multipart/form-data" - @endif - > - {!! csrf_field() !!} - @if($formMethod !== 'post') - @method($formMethod) - @endif + hasUploadFields($operation)) + enctype="multipart/form-data" + @endif + > + {!! csrf_field() !!} + @if($method !== 'post') + @formMethod($method) + @endif - {{-- Include the form fields --}} - @include('crud::form_content', ['fields' => $crud->fields(), 'action' => $operation]) - - {{-- This makes sure that all field assets are loaded. --}} -
{{ json_encode(Basset::loaded()) }}
+ {{-- Include the form fields --}} + @include('crud::form_content', ['fields' => $crud->fields(), 'action' => $operation]) + + {{-- This makes sure that all field assets are loaded. --}} +
{{ json_encode(Basset::loaded()) }}
- {{-- Include form save buttons --}} - @if(!isset($hideButtons) || !$hideButtons) -
- - {{ trans('backpack::crud.cancel') }} -
- @endif -
-
-
+ @include('crud::inc.form_save_buttons') +
+ @push('after_scripts') +@endBassetBlock @endpush \ No newline at end of file diff --git a/src/resources/views/crud/widgets/form.blade.php b/src/resources/views/crud/widgets/form.blade.php new file mode 100644 index 0000000000..c2cd824b4c --- /dev/null +++ b/src/resources/views/crud/widgets/form.blade.php @@ -0,0 +1,18 @@ +@includeWhen(!empty($widget['wrapper']), backpack_view('widgets.inc.wrapper_start')) +
+ @if (isset($widget['content']['header'])) +
+
{!! $widget['content']['header'] !!}
+
+ @endif +
+ + {!! $widget['content']['body'] ?? '' !!} + +
+ +
+ +
+
+@includeWhen(!empty($widget['wrapper']), backpack_view('widgets.inc.wrapper_end')) \ No newline at end of file From ad0dd30f61669e472e61630fbf9d3b5787f14290 Mon Sep 17 00:00:00 2001 From: pxpm Date: Fri, 13 Jun 2025 17:50:23 +0100 Subject: [PATCH 04/13] wip --- .../components/form/form_ajax_view.blade.php | 25 +++---- .../crud/components/form/modal_form.blade.php | 66 +++++++++++++++++-- .../views/crud/inc/show_fields.blade.php | 5 +- 3 files changed, 72 insertions(+), 24 deletions(-) diff --git a/src/resources/views/crud/components/form/form_ajax_view.blade.php b/src/resources/views/crud/components/form/form_ajax_view.blade.php index afea9dad3f..a4a9a92526 100644 --- a/src/resources/views/crud/components/form/form_ajax_view.blade.php +++ b/src/resources/views/crud/components/form/form_ajax_view.blade.php @@ -1,4 +1,3 @@ -
{!! csrf_field() !!} - - -{{-- See if we're using tabs --}} -@if ($crud->tabsEnabled() && count($crud->getTabs())) - @include('crud::inc.show_tabbed_fields') - -@else -
-
- @include('crud::inc.show_fields', ['fields' => $crud->fields()]) -
-
-@endif - +@include('crud::form_content', ['fields' => $crud->fields(), 'action' => 'create', 'inlineCreate' => true]) +
{{ json_encode(Basset::loaded()) }}
+ @foreach (app('widgets')->toArray() as $currentWidget) @php @@ -30,4 +18,9 @@ @if($currentWidget->getAttribute('inline')) @include($currentWidget->getFinalViewPath(), ['widget' => $currentWidget->toArray()]) @endif -@endforeach \ No newline at end of file +@endforeach + +@stack('crud_fields_styles') +@stack('crud_fields_scripts') +@stack('after_styles') +@stack('after_scripts') \ No newline at end of file diff --git a/src/resources/views/crud/components/form/modal_form.blade.php b/src/resources/views/crud/components/form/modal_form.blade.php index cf1dd6914e..124b222e55 100644 --- a/src/resources/views/crud/components/form/modal_form.blade.php +++ b/src/resources/views/crud/components/form/modal_form.blade.php @@ -30,7 +30,7 @@ @endpush @push('after_scripts') -@bassetBlock('form-modal-initialization') +@bassetBlock('form-modal-initialization.js') -@endBassetBlock -@endpush \ No newline at end of file +@if (!request()->ajax()) @endpush @endif diff --git a/src/resources/views/crud/form_content.blade.php b/src/resources/views/crud/form_content.blade.php index 92ee70187b..9763ab3c61 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 --}} @if ($crud->tabsEnabled() && count($crud->getTabs())) @@ -94,9 +94,10 @@ function handleFocusOnSelect2Field(firstField){ }); jQuery('document').ready(function($){ - // trigger the javascript for all fields that have their js defined in a separate method + @if(! isset($initFields) || $initFields !== false) initializeFieldsWithJavascript('form'); + @endif // Retrieves the current form data function getFormData() { diff --git a/src/resources/views/crud/inc/form_fields_script.blade.php b/src/resources/views/crud/inc/form_fields_script.blade.php index 17c7872874..82ee9d101a 100644 --- a/src/resources/views/crud/inc/form_fields_script.blade.php +++ b/src/resources/views/crud/inc/form_fields_script.blade.php @@ -6,6 +6,7 @@ * javascript manipulations, and makes it easy to do custom stuff * too, by exposing the main components (name, wrapper, input). */ + if (typeof CrudField === 'undefined') { class CrudField { constructor(name) { this.name = name; @@ -186,7 +187,7 @@ class CrudField { window.crud = { ...window.crud, - action: "{{ $action ?? "" }}", + action: "{{ $action ?? '' }}", // Subfields callbacks holder subfieldsCallbacks: [], @@ -197,4 +198,5 @@ class CrudField { // Create all fields from a given name list fields: names => names.map(window.crud.field), }; +} From 6ad70f9b4608eae63ce9666add2fadf7b9ee056a Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 17 Jun 2025 12:57:04 +0000 Subject: [PATCH 08/13] Apply fixes from StyleCI [ci skip] [skip ci] --- src/app/View/Components/Form.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/View/Components/Form.php b/src/app/View/Components/Form.php index a387aad7b0..a174955743 100644 --- a/src/app/View/Components/Form.php +++ b/src/app/View/Components/Form.php @@ -27,13 +27,13 @@ public function __construct( ) { // Get CRUD panel instance from the controller - if(CrudManager::hasCrudPanel($controller)) { + if (CrudManager::hasCrudPanel($controller)) { $previousOperation = CrudManager::getCrudPanel($controller)->getOperation(); } $this->crud = CrudManager::setupCrudPanel($controller, $operation); - - if(isset(($previousOperation))) { + + if (isset($previousOperation)) { $this->crud->setOperation($previousOperation); } From 7cbc80b66afe8fc061a0fc63b7b9a759f64f1a49 Mon Sep 17 00:00:00 2001 From: pxpm Date: Tue, 17 Jun 2025 14:06:20 +0100 Subject: [PATCH 09/13] wip --- .../crud/components/form/modal_form.blade.php | 118 ++++++++++-------- 1 file changed, 65 insertions(+), 53 deletions(-) diff --git a/src/resources/views/crud/components/form/modal_form.blade.php b/src/resources/views/crud/components/form/modal_form.blade.php index d2f7db0889..f4bcbfaf8c 100644 --- a/src/resources/views/crud/components/form/modal_form.blade.php +++ b/src/resources/views/crud/components/form/modal_form.blade.php @@ -44,63 +44,75 @@ @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/components/form/form_ajax_view.blade.php b/src/resources/views/crud/components/form/ajax_response.blade.php similarity index 100% rename from src/resources/views/crud/components/form/form_ajax_view.blade.php rename to src/resources/views/crud/components/form/ajax_response.blade.php diff --git a/src/resources/views/crud/components/form/modal.blade.php b/src/resources/views/crud/components/form/modal.blade.php new file mode 100644 index 0000000000..918b6813f9 --- /dev/null +++ b/src/resources/views/crud/components/form/modal.blade.php @@ -0,0 +1,47 @@ + {{-- 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 +@basset(base_path('vendor/backpack/crud/resources/assets/js/form_modal.js')) +@if (!request()->ajax()) @endpush @endif From b390e4a6134104ac4c69919098f17690e602aa0e Mon Sep 17 00:00:00 2001 From: pxpm Date: Thu, 19 Jun 2025 12:16:42 +0100 Subject: [PATCH 12/13] fixes --- src/app/Library/CrudPanel/CrudButton.php | 5 +- src/resources/assets/css/common.css | 5 + .../crud/components/form/modal.blade.php | 319 +++++++++++++++++- .../views/crud/fields/summernote.blade.php | 4 + 4 files changed, 330 insertions(+), 3 deletions(-) diff --git a/src/app/Library/CrudPanel/CrudButton.php b/src/app/Library/CrudPanel/CrudButton.php index 98f0ce667d..469b76812c 100644 --- a/src/app/Library/CrudPanel/CrudButton.php +++ b/src/app/Library/CrudPanel/CrudButton.php @@ -295,12 +295,13 @@ public function section($stack) * The HTML itself of the button. * * @param object|null $entry The eloquent Model for the current entry or null if no current entry. + * @param CrudPanel|null $crud The CrudPanel object, if not passed it will be retrieved from the service container. * @return \Illuminate\Contracts\View\View */ - public function getHtml($entry = null) + public function getHtml($entry = null, $crud = null) { $button = $this; - $crud = $this->crud(); + $crud = $crud ?? $this->crud(); if ($this->type == 'model_function') { if (is_null($entry)) { diff --git a/src/resources/assets/css/common.css b/src/resources/assets/css/common.css index 4036c0396d..80c4d95afe 100644 --- a/src/resources/assets/css/common.css +++ b/src/resources/assets/css/common.css @@ -1,5 +1,6 @@ :root { --table-row-hover: #f2f1ff; + --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 { @@ -212,6 +213,10 @@ form .select2.select2-container { overflow: visible; } +.modal .btn-close, .modal .close { + background: transparent var(--btn-close-bg) center / .75rem auto no-repeat; +} + /* SELECT 2 */ .select2-container--bootstrap .select2-selection { box-shadow: none !important; diff --git a/src/resources/views/crud/components/form/modal.blade.php b/src/resources/views/crud/components/form/modal.blade.php index 918b6813f9..c2f1a6296a 100644 --- a/src/resources/views/crud/components/form/modal.blade.php +++ b/src/resources/views/crud/components/form/modal.blade.php @@ -43,5 +43,322 @@
@if (!request()->ajax()) @endpush @endif @push('after_scripts') @if (request()->ajax()) @endpush @endif -@basset(base_path('vendor/backpack/crud/resources/assets/js/form_modal.js')) + @if (!request()->ajax()) @endpush @endif diff --git a/src/resources/views/crud/fields/summernote.blade.php b/src/resources/views/crud/fields/summernote.blade.php index 4a8e08d4b8..4623a338d6 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; } + /* Ensure Summernote's modal elements don't interfere with our modals */ + .note-modal { + z-index: 1060 !important; /* Higher than Bootstrap's default modal z-index */ + } @endBassetBlock @endpush From 97e7ab6dad558048f58c1eba339044b5e01f973f Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 19 Jun 2025 11:32:35 +0000 Subject: [PATCH 13/13] Apply fixes from StyleCI [ci skip] [skip ci] --- src/app/View/Components/Datatable.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/View/Components/Datatable.php b/src/app/View/Components/Datatable.php index b25b8b6041..b906c1be04 100644 --- a/src/app/View/Components/Datatable.php +++ b/src/app/View/Components/Datatable.php @@ -18,7 +18,6 @@ public function __construct( private ?\Closure $setup = null, private ?string $name = null, ) { - // Set active controller for proper context CrudManager::setActiveController($controller);