jqh 5 tahun lalu
induk
melakukan
a91828770b

+ 4 - 7
src/Form.php

@@ -7,7 +7,6 @@ use Dcat\Admin\Form\Builder;
 use Dcat\Admin\Form\Condition;
 use Dcat\Admin\Form\Field;
 use Dcat\Admin\Form\Row;
-use Dcat\Admin\Form\StepBuilder;
 use Dcat\Admin\Form\Tab;
 use Dcat\Admin\Contracts\Repository;
 use Dcat\Admin\Traits\HasBuilderEvents;
@@ -277,16 +276,14 @@ class Form implements Renderable
      */
     public function __construct(?Repository $repository = null, ?Closure $callback = null, Request $request = null)
     {
-        $this->repository = $repository ? Admin::repository($repository) : null;
-        $this->callback = $callback;
-        $this->request = $request ?: request();
-        $this->builder = new Builder($this);
+        $this->repository    = $repository ? Admin::repository($repository) : null;
+        $this->callback      = $callback;
+        $this->request       = $request ?: request();
+        $this->builder       = new Builder($this);
         $this->isSoftDeletes = $repository ? $this->repository->isSoftDeletes() : false;
 
         $this->setModel(new Fluent());
-
         $this->prepareModalForm();
-
         $this->callResolving();
     }
 

+ 26 - 28
src/Form/Builder.php

@@ -147,8 +147,7 @@ class Builder
      */
     public function __construct(Form $form)
     {
-        $this->form = $form;
-
+        $this->form   = $form;
         $this->fields = new Collection();
         $this->layout = new Layout($form);
         $this->tools  = new Tools($this);
@@ -695,13 +694,12 @@ class Builder
 
         $this->addRedirectUrlField();
 
-        $attributes['id']     = $this->getFormId();
-        $attributes['action'] = $this->getAction();
-        $attributes['method'] = Arr::get($options, 'method', 'post');
+        $attributes['id']             = $this->getFormId();
+        $attributes['action']         = $this->getAction();
+        $attributes['method']         = Arr::get($options, 'method', 'post');
         $attributes['accept-charset'] = 'UTF-8';
-        $attributes['data-toggle'] = 'validator';
-
-        $attributes['class'] = Arr::get($options, 'class');
+        $attributes['data-toggle']    = 'validator';
+        $attributes['class']          = Arr::get($options, 'class');
 
         if ($this->hasFile()) {
             $attributes['enctype'] = 'multipart/form-data';
@@ -873,27 +871,27 @@ JS
         $formId = $this->getFormId();
 
         $script = <<<JS
-
-var hash = document.location.hash;
-if (hash) {
-    $('#$formId .nav-tabs a[href="' + hash + '"]').tab('show');
-}
-
-// Change hash for page-reload
-$('#$formId .nav-tabs a').on('shown.bs.tab', function (e) {
-    history.pushState(null,null, e.target.hash);
-});
-
-if ($('#$formId .has-error').length) {
-    $('#$formId .has-error').each(function () {
-        var tabId = '#'+$(this).closest('.tab-pane').attr('id');
-        $('li a[href="'+tabId+'"] i').removeClass('hide');
+(function () {
+    var hash = document.location.hash;
+    if (hash) {
+        $('#$formId .nav-tabs a[href="' + hash + '"]').tab('show');
+    }
+    
+    // Change hash for page-reload
+    $('#$formId .nav-tabs a').on('shown.bs.tab', function (e) {
+        history.pushState(null,null, e.target.hash);
     });
-
-    var first = $('#$formId .has-error:first').closest('.tab-pane').attr('id');
-    $('li a[href="#'+first+'"]').tab('show');
-}
-
+    
+    if ($('#$formId .has-error').length) {
+        $('#$formId .has-error').each(function () {
+            var tabId = '#'+$(this).closest('.tab-pane').attr('id');
+            $('li a[href="'+tabId+'"] i').removeClass('hide');
+        });
+    
+        var first = $('#$formId .has-error:first').closest('.tab-pane').attr('id');
+        $('li a[href="#'+first+'"]').tab('show');
+    }
+})();
 JS;
         Admin::script($script);
     }

+ 1 - 1
src/Form/Condition.php

@@ -28,7 +28,7 @@ class Condition
     public function __construct($condition, Form $form)
     {
         $this->condition = $condition;
-        $this->form = $form;
+        $this->form      = $form;
     }
 
     public function then(\Closure $closure)

+ 7 - 8
src/Form/Field/Captcha.php

@@ -2,29 +2,29 @@
 
 namespace Dcat\Admin\Form\Field;
 
-use Dcat\Admin\Form;
-
 class Captcha extends Text
 {
     protected $rules = ['required', 'captcha'];
 
     protected $view = 'admin::form.captcha';
 
-    public function __construct($column, $arguments = [])
+    public function __construct()
     {
         if (!class_exists(\Mews\Captcha\Captcha::class)) {
             throw new \Exception('To use captcha field, please install [mews/captcha] first.');
         }
 
         $this->column = '__captcha__';
-        $this->label = trans('admin.captcha');
+        $this->label  = trans('admin.captcha');
     }
 
-    public function setForm(Form $form = null)
+    public function setForm($form = null)
     {
-        $this->form = $form;
+        parent::setForm($form);
 
-        $this->form->ignore($this->column);
+        if (method_exists($this->form, 'ignore')) {
+            $this->form->ignore($this->column);
+        }
 
         return $this;
     }
@@ -35,7 +35,6 @@ class Captcha extends Text
 $('#{$this->column}-captcha').click(function () {
     $(this).attr('src', $(this).attr('src')+'?'+Math.random());
 });
-
 JS;
 
         return parent::render();

+ 2 - 2
src/Grid/Column/Condition.php

@@ -37,8 +37,8 @@ class Condition
     public function __construct($condition, Column $column)
     {
         $this->condition = $condition;
-        $this->original = clone $column;
-        $this->column = $column;
+        $this->original  = clone $column;
+        $this->column    = $column;
     }
 
     public function then(\Closure $closure)

+ 2 - 2
src/Grid/Column/Help.php

@@ -30,8 +30,8 @@ class Help implements Renderable
      */
     public function __construct($message = '', ?string $style = null, ?string $placement = 'bottom')
     {
-        $this->message = value($message);
-        $this->style = $style;
+        $this->message   = value($message);
+        $this->style     = $style;
         $this->placement = $placement;
     }
 

+ 2 - 2
src/Grid/Header.php

@@ -31,8 +31,8 @@ class Header extends Widget
 
     public function __construct(Grid $grid, string $label, array $columnNames)
     {
-        $this->grid = $grid;
-        $this->label = admin_trans_field($label);
+        $this->grid        = $grid;
+        $this->label       = admin_trans_field($label);
         $this->columnNames = $columnNames;
 
         $this->setupAttributes();

+ 3 - 2
src/Grid/Responsive.php

@@ -23,10 +23,11 @@ class Responsive
     public function __construct(Grid $grid)
     {
         $this->grid = $grid;
+
         $this->options([
             'i18n' => [
-                'focus' => trans('admin.responsive.focus'),
-                'display' => trans('admin.responsive.display'),
+                'focus'      => trans('admin.responsive.focus'),
+                'display'    => trans('admin.responsive.display'),
                 'displayAll' => trans('admin.responsive.display_all'),
             ],
         ]);

+ 2 - 2
src/Show/Relation.php

@@ -46,9 +46,9 @@ class Relation extends Field
      */
     public function __construct($name, $builder, $title = '')
     {
-        $this->name = $name;
+        $this->name    = $name;
         $this->builder = $builder;
-        $this->title = $this->formatLabel($title);
+        $this->title   = $this->formatLabel($title);
     }
 
     /**

+ 2 - 2
src/Tree.php

@@ -130,9 +130,9 @@ class Tree implements Renderable
     public function __construct(Model $model = null, ?\Closure $callback = null)
     {
         $this->model = $model;
+        $this->path  = $this->path ?: request()->getPathInfo();
+        $this->url   = url($this->path);
 
-        $this->path = $this->path ?: request()->getPathInfo();
-        $this->url = url($this->path);
         $this->elementId .= uniqid();
 
         $this->setupTools();

+ 1 - 1
src/Tree/Tools.php

@@ -30,7 +30,7 @@ class Tools implements Renderable
      */
     public function __construct(Tree $tree)
     {
-        $this->tree = $tree;
+        $this->tree  = $tree;
         $this->tools = new Collection();
     }