]> _ Git - fluidbook-toolbox.git/commitdiff
wip #4213 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 7 Jul 2022 18:27:40 +0000 (20:27 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 7 Jul 2022 18:27:40 +0000 (20:27 +0200)
app/Fields/FluidbookChapterLevel.php [new file with mode: 0644]
app/SubForms/FluidbookChapter.php
resources/views/fields/fluidbook_chapter_level.blade.php [new file with mode: 0644]
resources/views/fields/fluidbook_chapters.blade.php

diff --git a/app/Fields/FluidbookChapterLevel.php b/app/Fields/FluidbookChapterLevel.php
new file mode 100644 (file)
index 0000000..896ac3d
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Fields;
+
+use Cubist\Backpack\Magic\Fields\Integer;
+
+class FluidbookChapterLevel extends Integer
+{
+    protected $_adminType = 'fluidbook_chapter_level';
+    protected $_viewNamespace = 'fields';
+
+}
index 1da327c3a56be58c3fd3268ed53d4aef4db30a4a..210c736dd6eb8d6e535ad9f686d8e919bb1c2e9d 100644 (file)
@@ -2,8 +2,8 @@
 
 namespace App\SubForms;
 
+use App\Fields\FluidbookChapterLevel;
 use Cubist\Backpack\Magic\Fields\Color;
-use Cubist\Backpack\Magic\Fields\Hidden;
 use Cubist\Backpack\Magic\Fields\SelectFromArray;
 use Cubist\Backpack\Magic\Fields\Text;
 use Cubist\Backpack\Magic\SubForm;
@@ -14,11 +14,10 @@ class FluidbookChapter extends SubForm
     {
         parent::init();
 
-
         $when = ['type' => ['regular', 'column_head']];
-        $this->addField('label', Text::class, __('Nom du chapitre'), ['when' => $when]);
-        $this->addField('page', Text::class, __('Page'), ['when' => $when]);
-        $this->addField('color', Color::class, __('Couleur'), ['when' => $when]);
+        $this->addField('label', Text::class, __('Nom du chapitre'), ['when' => $when, 'placeholder' => __('Label')]);
+        $this->addField('page', Text::class, __('Page'), ['when' => $when, 'placeholder' => __('Page')]);
+        $this->addField('color', Color::class, __('Couleur'), ['when' => $when, 'allows_empty' => true, 'allows_alpha' => false, 'default' => null]);
         $this->addField('type', SelectFromArray::class, __('Type'), ['default' => 'regular', 'options' =>
             [
                 'regular' => __('Chapitre normal'),
@@ -28,7 +27,7 @@ class FluidbookChapter extends SubForm
                 'separator' => __('Séparateur') . ' (----)',
             ]
         ]);
-        $this->addField('level', Hidden::class, __('Niveau'));
+        $this->addField('level', FluidbookChapterLevel::class, __('Niveau'), ['default' => 1, 'min' => 1, 'max' => 4]);
 
     }
 }
diff --git a/resources/views/fields/fluidbook_chapter_level.blade.php b/resources/views/fields/fluidbook_chapter_level.blade.php
new file mode 100644 (file)
index 0000000..f482130
--- /dev/null
@@ -0,0 +1,77 @@
+@php
+    $v=old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '';
+    if(!is_string($v)){
+        $v=json_encode($v);
+    }
+@endphp
+
+@if (!isset($seenFluidbookChapterLevel))
+    @php $seenFluidbookChapterLevel=true;@endphp
+    @push('crud_fields_scripts')
+        <script>
+            $(document).on('click', ".fluidbook_chapter_level a", function () {
+
+                var p = $(this).closest('.fluidbook_chapter_level');
+                var input = $(p).find('input');
+                var v = parseInt(input.val());
+                var min = parseInt(input.data('min'));
+                var max = parseInt(input.data('max'));
+                var v1 = $(this).hasClass('left') ? -1 : 1;
+                v = Math.min(max, Math.max(min, v + v1));
+                $(input).val(v);
+                $(this).closest('.item').attr('data-level', v);
+                $(document).trigger('bunchmultiple.toresize');
+                return false;
+            });
+
+            $(document).on('cubist.bunchmultiple.added', function () {
+                $('.fluidbook_chapter_level').each(function () {
+                    $(this).closest('.item').attr('data-level', $(this).find('input').val());
+                });
+            });
+        </script>
+    @endpush
+
+    @push('crud_fields_styles')
+        <style>
+            .fluidbook_chapter_level a {
+                color: inherit;
+                margin-top: 5px;
+                display: inline-block;
+            }
+
+            .item[data-level="1"] {
+                padding-left: 0;
+            }
+
+            .item[data-level="2"] {
+                padding-left: 20px;
+            }
+
+            .item[data-level="3"] {
+                padding-left: 40px;
+            }
+
+            .item[data-level="4"] {
+                padding-left: 60px;
+            }
+        </style>
+    @endpush
+@endif
+
+@include('crud::fields.inc.wrapper_start')
+<span class="fluidbook_chapter_level">
+<input
+    type="hidden"
+    name="{{ $field['name'] }}"
+    value="{{ $v }}"
+    data-min="{{$field['min']}}"
+    data-max="{{$field['max']}}"
+    @include('crud::fields.inc.attributes')
+>
+<a href="#" class="noedit left" title="{{__('Retirer un niveau')}}"><i class="las la-caret-left"></i></a>
+<a href="#" class="noedit right" title="{{__('Ajouter un niveau')}}"><i class="las la-caret-right"></i></a>
+</span>
+@include('crud::fields.inc.wrapper_end')
+
+
index 23358c513d8d5482d65840c8b403eac120f6ac2d..d9762ffe63168b8e986e59716d65d850b928660c 100644 (file)
@@ -2,14 +2,18 @@
     @php $seenFluidbookChapters=true;@endphp
     @push('crud_fields_scripts')
         <script>
-
+            $(document).trigger('fluidbook_chapters.level.change');
         </script>
     @endpush
 
     @push('crud_fields_styles')
         <style>
+            .bunchmultiple.bunchmultiple_oneline .bunchmultiple__wrapper .legendsize .form-group {
+                padding: 0 2px !important;
+            }
+
             .bunchmultiple_oneline .bunchmultiple__wrapper .item .legend .legendsize .form-group[data-name="label"] {
-                width: calc(100% - 330px);
+                width: calc(100% - 360px);
             }
 
             .bunchmultiple_oneline .bunchmultiple__wrapper .item .legend .legendsize .form-group[data-name="page"] {
@@ -17,7 +21,7 @@
             }
 
             .bunchmultiple_oneline .bunchmultiple__wrapper .item .legend .legendsize .form-group[data-name="color"] {
-                width: 70px;
+                width: 54px;
             }
 
             .bunchmultiple_oneline .bunchmultiple__wrapper .item .legend .legendsize .form-group[data-name="type"] {
@@ -26,5 +30,6 @@
         </style>
     @endpush
 @endif
+
 @include('cubist_back::fields.bunch_oneline_multiple')