jqh 6 rokov pred
rodič
commit
0b08245fc5
3 zmenil súbory, kde vykonal 99 pridanie a 0 odobranie
  1. 21 0
      src/Form.php
  2. 55 0
      src/Form/Field/Fieldset.php
  3. 23 0
      src/Widgets/Form.php

+ 21 - 0
src/Form.php

@@ -404,6 +404,27 @@ class Form implements Renderable
         return $this;
     }
 
+    /**
+     * Add a fieldset to form.
+     *
+     * @param string  $title
+     * @param Closure $setCallback
+     *
+     * @return Field\Fieldset
+     */
+    public function fieldset(string $title, Closure $setCallback)
+    {
+        $fieldset = new Field\Fieldset();
+
+        $this->html($fieldset->start($title))->plain();
+
+        $setCallback($this);
+
+        $this->html($fieldset->end())->plain();
+
+        return $fieldset;
+    }
+
     /**
      * Use tab to split form.
      *

+ 55 - 0
src/Form/Field/Fieldset.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace Dcat\Admin\Form\Field;
+
+use Dcat\Admin\Admin;
+
+class Fieldset
+{
+    protected $name = '';
+
+    public function __construct()
+    {
+        $this->name = uniqid('fieldset-');
+    }
+
+    public function start($title)
+    {
+        $script = <<<SCRIPT
+$('.{$this->name}-title').click(function () {
+    $("i", this).toggleClass("fa-angle-double-down fa-angle-double-up");
+});
+SCRIPT;
+
+        Admin::script($script);
+
+        return <<<HTML
+<div>
+    <div style="height: 20px; border-bottom: 1px solid #eee; text-align: center;margin-top: 20px;margin-bottom: 20px;">
+      <span style="font-size: 16px; background-color: #ffffff; padding: 0 10px;">
+        <a data-toggle="collapse" href="#{$this->name}" class="{$this->name}-title">
+          <i class="fa fa-angle-double-up"></i>&nbsp;&nbsp;{$title}
+        </a>
+      </span>
+    </div>
+    <div class="collapse in" id="{$this->name}">
+HTML;
+    }
+
+    public function end()
+    {
+        return '</div></div>';
+    }
+
+    public function collapsed()
+    {
+        $script = <<<SCRIPT
+$("#{$this->name}").removeClass("in");
+$(".{$this->name}-title i").toggleClass("fa-angle-double-down fa-angle-double-up");
+SCRIPT;
+
+        Admin::script($script);
+
+        return $this;
+    }
+}

+ 23 - 0
src/Widgets/Form.php

@@ -2,6 +2,7 @@
 
 namespace Dcat\Admin\Widgets;
 
+use Closure;
 use Dcat\Admin\Admin;
 use Dcat\Admin\Form\Field;
 use Illuminate\Contracts\Support\Arrayable;
@@ -166,6 +167,28 @@ class Form implements Renderable
         return $this->attribute('method', strtoupper($method));
     }
 
+    /**
+     * Add a fieldset to form.
+     *
+     * @param string  $title
+     * @param Closure $setCallback
+     *
+     * @return Field\Fieldset
+     */
+    public function fieldset(string $title, Closure $setCallback)
+    {
+        $fieldset = new Field\Fieldset();
+
+        $this->html($fieldset->start($title))->plain();
+
+        $setCallback($this);
+
+        $this->html($fieldset->end())->plain();
+
+        return $fieldset;
+    }
+
+
     /**
      * Add form attributes.
      *