Browse Source

添加:Form表单底部可设置‘查看’,‘继续编辑’,‘继续创建’等按钮默认勾选。

ving 4 years ago
parent
commit
d1efe752c6
1 changed files with 63 additions and 1 deletions
  1. 63 1
      src/Form/Footer.php

+ 63 - 1
src/Form/Footer.php

@@ -42,6 +42,13 @@ class Footer implements Renderable
      */
     protected $checkboxes = ['view' => true, 'continue_editing' => true, 'continue_creating' => true];
 
+    /**
+     * Default checked.
+     *
+     * @var arrays
+     */
+    protected $defaultcheckeds = ['view' => false, 'continue_editing' => false, 'continue_creating' => false];
+
     /**
      * Footer constructor.
      *
@@ -122,6 +129,48 @@ class Footer implements Renderable
         return $this;
     }
 
+    /**
+     * default View Checked.
+     *
+     * @param bool $checked
+     *
+     * @return $this
+     */
+    public function defaultViewChecked(bool $checked = false)
+    {
+        $this->defaultcheckeds['view'] = $checked;
+
+        return $this;
+    }
+
+    /**
+     * default Editing Checked.
+     *
+     * @param bool $checked
+     *
+     * @return $this
+     */
+    public function defaultEditingChecked(bool $checked = false)
+    {
+        $this->defaultcheckeds['continue_editing'] = $checked;
+
+        return $this;
+    }
+
+    /**
+     * default Creating Checked.
+     *
+     * @param bool $checked
+     *
+     * @return $this
+     */
+    public function defaultCreatingChecked(bool $checked = false)
+    {
+        $this->defaultcheckeds['continue_creating'] = $checked;
+
+        return $this;
+    }
+
     /**
      * Build checkboxes.
      *
@@ -134,6 +183,7 @@ class Footer implements Renderable
         }
 
         $options = [];
+        $checked = [];
 
         if ($this->checkboxes['continue_editing']) {
             $options[1] = sprintf('<span class="text-80 text-bold">%s</span>', trans('admin.continue_editing'));
@@ -147,11 +197,23 @@ class Footer implements Renderable
             $options[3] = sprintf('<span class="text-80 text-bold">%s</span>', trans('admin.view'));
         }
 
+        if ($this->defaultcheckeds['continue_editing']) {
+            $checked[] = 1;
+        }
+
+        if ($this->defaultcheckeds['continue_creating']) {
+            $checked[] = 2;
+        }
+
+        if ($this->defaultcheckeds['view']) {
+            $checked[] = 3;
+        }
+
         if (! $options) {
             return;
         }
 
-        return (new Checkbox('after-save', $options))->inline()->circle(true);
+        return (new Checkbox('after-save', $options))->check($checked)->inline()->circle(true);
     }
 
     /**