]> _ Git - cubist_cms-back.git/commitdiff
wip #6570 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Dec 2023 07:51:20 +0000 (08:51 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Dec 2023 07:51:20 +0000 (08:51 +0100)
src/app/CubistCrudPanel.php
src/app/Magic/Fields/Checkbox.php
src/resources/views/create.blade.php
src/resources/views/edit.blade.php

index 86439dca92cfad914b0ad60185c4e692e299790b..30e9f24d78ac0b8b902d48c781aa753624599bd2 100644 (file)
@@ -61,15 +61,17 @@ class CubistCrudPanel extends CrudPanel
         return true;
     }
 
-    public function hasAccess($operation)
+    public function hasAccess($operation, $entry = null): bool
     {
         // First filter with standard backpack gate
-        if (!parent::hasAccess($operation)) {
+        if (!parent::hasAccess($operation, $entry)) {
             return false;
         }
 
+        $model = $entry ?? $this->entry ?? $this->model;
+
         // Then, apply model rules
-        if ($this->model instanceof CubistMagicAbstractModel) {
+        if ($model instanceof CubistMagicAbstractModel) {
             $funcMap = [
                 'show' => 'canList',
                 'infos' => 'canList',
@@ -89,7 +91,7 @@ class CubistCrudPanel extends CrudPanel
             } else {
                 $func = 'can' . ucfirst($operation);
             }
-            $model = $this->entry ?? $this->model;
+
             if (is_callable([$model, $func])) {
                 return $model->$func(backpack_user());
             }
@@ -103,34 +105,6 @@ class CubistCrudPanel extends CrudPanel
         return request()->get('embeded', '0') != '0';
     }
 
-    public function hasAccessOrFail($operation)
-    {
-        if (!$this->hasAccess($operation)) {
-            throw new AccessDeniedException(trans('backpack::crud.unauthorized_access', ['access' => $operation]));
-        }
-        return true;
-    }
-
-    public function hasAccessToAll($operation_array)
-    {
-        foreach ((array)$operation_array as $key => $operation) {
-            if (!$this->hasAccess($operation)) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    public function hasAccessToAny($operation_array)
-    {
-        foreach ((array)$operation_array as $key => $operation) {
-            if ($this->hasAccess($operation) == true) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     /**
      * @param $model CubistMagicAbstractModel
      */
index 64b30fc40c67dbc7b2e30ada9e0b9afef1e3f092..a14737946d0dd36bb7a8b3c303708df1dcd44d3c 100644 (file)
@@ -6,11 +6,10 @@ namespace Cubist\Backpack\Magic\Fields;
 
 class Checkbox extends Field
 {
-    protected $_adminType = 'toggle';
+    protected $_adminType = 'switch';
     protected $_databaseType = 'boolean';
     protected $_columnType = 'check';
     protected $_cast = 'boolean';
-    protected $_viewNamespace = 'toggle-field-for-backpack::fields';
     protected $_filterType = 'dropdown';
 
     public function filterDefault($value)
index 9fc72e5c15adcd8b15a8ac5e1360373707b8fd30..ef4c5e1386cc68871d04f34a63ee892d52813d23 100644 (file)
 @endphp
 
 @section('header')
-    <section class="container-fluid">
-        <h2>
-            <span class="text-capitalize">{!! $crud->getHeading() ?? $crud->entity_name_plural !!}</span>
-            <small>{!! $crud->getSubheading() ?? trans('backpack::crud.add').' '.$crud->entity_name !!}.</small>
-
+    <section class="header-operation container-fluid animated fadeIn d-flex mb-2 align-items-baseline d-print-none" bp-section="page-header">
+        <h1 class="text-capitalize mb-0" bp-section="page-heading">{!! $crud->getHeading() ?? $crud->entity_name_plural !!}</h1>
+        <p class="ms-2 ml-2 mb-0" bp-section="page-subheading">{!! $crud->getSubheading() ?? trans('backpack::crud.add').' '.$crud->entity_name !!}.</p>
             @if ($crud->hasAccess('list'))
-                <small><a href="{{ url($crud->route) }}" class="hidden-print font-sm"><i class="la la-angle-double-{{ config('backpack.base.html_direction') == 'rtl' ? 'right' : 'left' }}"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></a></small>
+            <p class="mb-0 ms-2 ml-2" bp-section="page-subheading-back-button">
+                <small>
+                    <a href="{{ url($crud->route) }}" class="d-print-none font-sm">
+                        <span><i class="la la-angle-double-{{ config('backpack.base.html_direction') == 'rtl' ? 'right' : 'left' }}"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></span>
+                    </a>
+                </small>
+            </p>
             @endif
-        </h2>
     </section>
 @endsection
 
 @section('content')
 
-    <div class="row">
+<div class="row" bp-section="crud-operation-create">
         <div class="{{ $crud->getCreateContentClass() }}">
-            <!-- Default box -->
+               {{-- Default box --}}
 
             @include('crud::inc.grouped_errors')
 
                 @endif
             >
             {!! csrf_field() !!}
-            <!-- load the view from the application if it exists, otherwise load the one in the package -->
+                     {{-- load the view from the application if it exists, otherwise load the one in the package --}}
                 @if(view()->exists('vendor.backpack.crud.form_content'))
                     @include('vendor.backpack.crud.form_content', [ 'fields' => $crud->fields(), 'action' => 'create' ])
                 @else
                     @include('crud::form_content', [ 'fields' => $crud->fields(), 'action' => 'create' ])
                 @endif
-
+                {{-- This makes sure that all field assets are loaded. --}}
+                <div class="d-none" id="parentLoadedAssets">{{ json_encode(Basset::loaded()) }}</div>
                 @include('crud::inc.form_save_buttons')
             </form>
         </div>
index d92d863f767309c5184c04f3a9e7e1acf7c74d7c..12d5d248a1982479a837f7796630b8b99f560318 100644 (file)
 @endphp
 
 @section('header')
-    <section class="container-fluid">
-        <h2>
-            <span class="text-capitalize">{!! $crud->getHeading() ?? $crud->entity_name_plural !!}</span>
-            <small>{!! $crud->getSubheading() ?? trans('backpack::crud.edit').' '.$crud->entity_name !!}.</small>
-
+    <section class="header-operation container-fluid animated fadeIn d-flex mb-2 align-items-baseline d-print-none" bp-section="page-header">
+        <h1 class="text-capitalize mb-0" bp-section="page-heading">{!! $crud->getHeading() ?? $crud->entity_name_plural !!}</h1>
+        <p class="ms-2 ml-2 mb-0" bp-section="page-subheading">{!! $crud->getSubheading() ?? trans('backpack::crud.edit').' '.$crud->entity_name !!}.</p>
             @if ($crud->hasAccess('list'))
-                <small><a href="{{ url($crud->route) }}" class="d-print-none font-sm"><i
-                            class="la la-angle-double-{{ config('backpack.base.html_direction') == 'rtl' ? 'right' : 'left' }}"></i> {{ trans('backpack::crud.back_to_all') }}
-                        <span>{{ $crud->entity_name_plural }}</span></a></small>
+            <p class="mb-0 ms-2 ml-2" bp-section="page-subheading-back-button">
+                <small><a href="{{ url($crud->route) }}" class="d-print-none font-sm"><i class="la la-angle-double-{{ config('backpack.base.html_direction') == 'rtl' ? 'right' : 'left' }}"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></a></small>
+            </p>
             @endif
-        </h2>
     </section>
 @endsection
 
 @section('content')
-    <div class="row">
+<div class="row" bp-section="crud-operation-update">
         <div class="{{ $crud->getEditContentClass() }}">
             {{-- Default box --}}
 
@@ -74,8 +71,7 @@
                     <div class="mb-2 text-right">
                         {{-- Single button --}}
                         <div class="btn-group">
-                            <button type="button" class="btn btn-sm btn-primary dropdown-toggle" data-toggle="dropdown"
-                                    aria-haspopup="true" aria-expanded="false">
+                                 <button type="button" class="btn btn-sm btn-primary dropdown-toggle" data-toggle="dropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                 {{trans('backpack::crud.language')}}
                                 : {{ $crud->model->getAvailableLocales()[request()->input('_locale')?request()->input('_locale'):App::getLocale()] }}
                                 &nbsp; <span class="caret"></span>
@@ -96,7 +92,7 @@
                     @include('crud::form_content', ['fields' => $crud->fields(), 'action' => 'edit'])
                 @endif
                 {{-- This makes sure that all field assets are loaded. --}}
-                <div class="d-none" id="parentLoadedAssets">{{ json_encode(Assets::loaded()) }}</div>
+            <div class="d-none" id="parentLoadedAssets">{{ json_encode(Basset::loaded()) }}</div>
                 @include('crud::inc.form_save_buttons')
             </form>
         </div>