]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5468 @7
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 19 Oct 2022 10:36:18 +0000 (12:36 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 19 Oct 2022 10:36:18 +0000 (12:36 +0200)
app/Fields/FluidbookLinkEditor/LinkType.php
app/SubForms/Link/Base.php
resources/linkeditor/style/form.sass [new file with mode: 0644]
resources/linkeditor/style/style.sass
resources/views/fluidbook_publication/link_editor.blade.php
resources/views/fluidbook_publication/link_editor_form.blade.php [new file with mode: 0644]

index 146c22d65145ca37483c74e26d177a825eea415a..4be979496750c5155115eb8b867d3bbe1a976dda 100644 (file)
@@ -8,12 +8,14 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 class LinkType extends SelectFromArray
 {
     protected $_allowsHTML = true;
+    protected $_ajax = false;
+    protected $_allowNull = false;
 
     public function getOptions()
     {
         $res = [];
         foreach (Base::types() as $type) {
-            $res[$type['type']] = '<span class="linkeditor-linktype" data-color="' . $type['color'] . '">' . $type['label'] . '</span>';
+            $res[$type['type']] = '<span class="linkeditor-linktype" data-type="' . $type['type'] . '">' . $type['label'] . '</span>';
         }
         return $res;
     }
index c58051f459db4684aa50931bbb4f6c1a6c3598a6..8855a3605d2608afd925e46ec749795044478052 100644 (file)
@@ -8,9 +8,9 @@ use App\Fields\FluidbookLinkEditor\MultimediaIntegration;
 use Cubist\Backpack\Magic\Fields\FormSection;
 use Cubist\Backpack\Magic\Fields\Number;
 use Cubist\Backpack\Magic\Fields\Text;
-use Cubist\Backpack\Magic\SubForm;
+use Cubist\Backpack\Magic\Form;
 
-class Base extends SubForm
+class Base extends Form
 {
     const WEB_INFOS = 1;
     const PRODUCT = 1;
@@ -68,10 +68,10 @@ class Base extends SubForm
     public static function types()
     {
         return [
-            ['type' => self::WEB_INFOS, 'label' => __('Lien web « plus d\'infos »'), 'color' => '#ff0000', 'class' => WebInfos::class, 'class' => Web::class],
-            ['type' => self::WEB, 'label' => __('Lien web'), 'color' => '#3399cc', 'class' => Web::class, 'class' => Web::class],
-            ['type' => self::EMAIL, 'label' => __('Adresse e-mail'), 'color' => '#6c6360', 'class' => Web::class],
-            ['type' => self::VIDEO, 'label' => __('Vidéo'), 'color' => '#33ff00', 'class' => Web::class],
+            ['type' => self::WEB_INFOS, 'label' => __('Lien web « plus d\'infos »'), 'color' => '#ff0000', 'class' => WebInfos::class],
+            ['type' => self::WEB, 'label' => __('Lien web'), 'color' => '#3399cc', 'class' => Web::class],
+            ['type' => self::EMAIL, 'label' => __('Adresse e-mail'), 'color' => '#6c6360', 'class' => Email::class],
+            ['type' => self::VIDEO, 'label' => __('Vidéo'), 'color' => '#33ff00', 'class' => Video::class],
             ['type' => self::INTERNAL, 'label' => __('Lien vers une page'), 'color' => '#c7b405', 'class' => Web::class],
             ['type' => self::MULTIMEDIA, 'label' => __('Multimédia'), 'color' => '#ff00ff', 'class' => Web::class],
             ['type' => self::CUSTOM, 'label' => __('Lien personnalisé'), 'color' => '#14511a', 'class' => Web::class],
@@ -183,4 +183,18 @@ class Base extends SubForm
     {
         $this->addField('header_settings', FormSection::class, __('Autres paramètres'));
     }
+
+    public function getType()
+    {
+        return $this->getValue('type');
+    }
+
+    /**
+     * @return string
+     */
+
+    public function render(callable $callback = null)
+    {
+        return view('fluidbook_publication.link_editor_form', ['form' => $this, 'crud' => $this->crud])->render($callback);
+    }
 }
diff --git a/resources/linkeditor/style/form.sass b/resources/linkeditor/style/form.sass
new file mode 100644 (file)
index 0000000..00af59c
--- /dev/null
@@ -0,0 +1,14 @@
+#linkeditor-form-templates
+    display: block
+
+
+.linkeditor-linktype
+    &::before
+        display: inline-block
+        width: 20px
+        height: 20px
+        border-radius: 2px
+        margin: 0 10px 0 0
+        content: ""
+        vertical-align: top
+        position: relative
index 2164e156509773733fd8255b6d324066f61418c9..f707ade68269551dafc606e6c2287d821e012a71 100644 (file)
@@ -144,3 +144,4 @@ body, #linkeditor, html
 @import "toolbar"
 @import "rulers"
 @import "links"
+@import "form"
index b3c9d11156393ae6bf8eccd02ce42ce8ac79d08c..a3d47ed0c6b08bed4a5fb78cf5f164c33f939765 100644 (file)
         </aside>
     </div>
     <div id="linkeditor-preload"></div>
+    <div id="linkeditor-form-templates">
+        @foreach(\App\SubForms\Link\Base::types() as $f)
+            @if(isset($f['disabled']) && $f['disabled'])
+                @continue;
+            @endif
+            @php
+                $instance=new $f['class']();
+                $instance->setValue('type',$f['type']);
+                echo $instance->render();
+            @endphp
+        @endforeach
+    </div>
 @endsection
 
 @push('after_scripts')
 @push('after_styles')
     <style>
         @foreach(\App\SubForms\Link\Base::types() as $type)
-            .link[fb-type="{{$type['type']}}"] {
+        .link[fb-type="{{$type['type']}}"] {
             color: {{$type['color']}};
             background-color: {{\Cubist\Util\Graphics\Color::colorToCSS($type['color'],0.25)}};
         }
+        .linkeditor-linktype[data-type="{{$type['type']}}"]::before{
+            background-color: {{$type['color']}};
+        }
         @endforeach
     </style>
     <link rel="stylesheet"
diff --git a/resources/views/fluidbook_publication/link_editor_form.blade.php b/resources/views/fluidbook_publication/link_editor_form.blade.php
new file mode 100644 (file)
index 0000000..486ef28
--- /dev/null
@@ -0,0 +1,21 @@
+@php
+    start_measure('Render form '.$form->getTitle());
+        $action='create';
+        $fields=$crud->fields();
+@endphp
+
+@if($form->getTitle())
+    <h2>{{$form->getTitle()}}</h2>
+@endif
+<form id="linkeditor-form-template-{{$form->getType()}}" action="{{$form->getAction()}}"
+      enctype="{{$form->getEnctype()}}" method="{{$form->getSafeMethod()}}">
+    <input type="hidden" name="_method" value="{{$form->getMethod()}}">
+    <input type="hidden" name="_referrer" value="{{request()->getRequestUri()}}">
+    @if($form->isCsrf())
+        @csrf
+    @endif
+    @include('crud::form_content')
+</form>
+@php
+    stop_measure('Render form '.$form->getTitle());
+@endphp