jqh 4 år sedan
förälder
incheckning
95c90057be
3 ändrade filer med 44 tillägg och 22 borttagningar
  1. 3 15
      resources/views/form/tab.blade.php
  2. 21 0
      src/Form/Layout.php
  3. 20 7
      src/Form/Tab.php

+ 3 - 15
resources/views/form/tab.blade.php

@@ -11,22 +11,10 @@
     <div class="tab-content fields-group mt-2 pt-1 pb-1">
         @foreach($tabObj->getTabs() as $tab)
             <div class="tab-pane {{ $tab['active'] ? 'active' : '' }}" id="{{ $tab['id'] }}">
-                @if($rows)
-                    <div class="ml-2 mb-2" style="margin-top: -1rem">
-                        @foreach($rows as $row)
-                            {!! $row->render() !!}
-                        @endforeach
-
-                        @foreach($fields as $field)
-                            @if($field instanceof \Dcat\Admin\Form\Field\Hidden)
-                                {!! $field->render() !!}
-                            @endif
-                        @endforeach
-                    </div>
-                @elseif($layout->hasColumns())
-                    {!! $layout->build() !!}
+                @if($tab['layout']->hasColumns())
+                    {!! $tab['layout']->build() !!}
                 @else
-                    @foreach($fields as $field)
+                    @foreach($tab['fields'] as $field)
                         {!! $field->render() !!}
                     @endforeach
                 @endif

+ 21 - 0
src/Form/Layout.php

@@ -157,6 +157,27 @@ class Layout
         return $html.'</div>';
     }
 
+    public function getColumns()
+    {
+        return $this->columns;
+    }
+
+    public function setColumns(array $columns)
+    {
+        $this->columns = $columns;
+
+        return $this;
+    }
+
+    public function reset()
+    {
+        $this->hasColumn = false;
+
+        $this->resetCurrentFields();
+
+        $this->setColumns([]);
+    }
+
     protected function resetCurrentFields()
     {
         $this->currentFields = [];

+ 20 - 7
src/Form/Tab.php

@@ -24,6 +24,11 @@ class Tab
      */
     protected $offset = 0;
 
+    /**
+     * @var int
+     */
+    protected $columnOffset = 0;
+
     /**
      * Tab constructor.
      *
@@ -47,11 +52,14 @@ class Tab
      */
     public function append($title, \Closure $content, $active = false)
     {
-        $fields = $this->collectFields($content);
+        call_user_func($content, $this->form);
+
+        $fields = $this->collectFields();
+        $layout = $this->collectColumnLayout();
 
         $id = 'tab-form-'.($this->tabs->count() + 1).'-'.mt_rand(0, 9999);
 
-        $this->tabs->push(compact('id', 'title', 'fields', 'active'));
+        $this->tabs->push(compact('id', 'title', 'fields', 'active', 'layout'));
 
         return $this;
     }
@@ -59,14 +67,10 @@ class Tab
     /**
      * Collect fields under current tab.
      *
-     * @param \Closure $content
-     *
      * @return Collection
      */
-    protected function collectFields(\Closure $content)
+    protected function collectFields()
     {
-        call_user_func($content, $this->form);
-
         $fields = clone $this->form->fields();
 
         $all = $fields->toArray();
@@ -98,6 +102,15 @@ class Tab
         return $fields;
     }
 
+    protected function collectColumnLayout()
+    {
+        $layout = clone $this->form->layout();
+
+        $this->form->layout()->reset();
+
+        return $layout;
+    }
+
     /**
      * Get all tabs.
      *