jqh 5 лет назад
Родитель
Сommit
01dfaf6e73

+ 3 - 7
src/Form/Field/Currency.php

@@ -2,10 +2,11 @@
 
 
 namespace Dcat\Admin\Form\Field;
 namespace Dcat\Admin\Form\Field;
 
 
-use Dcat\Admin\Admin;
-
 class Currency extends Text
 class Currency extends Text
 {
 {
+    public static $js = 'jquery.inputmask';
+    public static $css = 'jquery.inputmask';
+
     /**
     /**
      * @var string
      * @var string
      */
      */
@@ -69,9 +70,4 @@ class Currency extends Text
 
 
         return parent::render();
         return parent::render();
     }
     }
-
-    public static function collectAssets()
-    {
-        Admin::collectAssets('jquery.inputmask');
-    }
 }
 }

+ 3 - 7
src/Form/Field/Date.php

@@ -2,10 +2,11 @@
 
 
 namespace Dcat\Admin\Form\Field;
 namespace Dcat\Admin\Form\Field;
 
 
-use Dcat\Admin\Admin;
-
 class Date extends Text
 class Date extends Text
 {
 {
+    public static $js = 'bootstrap-datetimepicker';
+    public static $css = 'bootstrap-datetimepicker';
+
     protected $format = 'yyyy-mm-dd';
     protected $format = 'yyyy-mm-dd';
 
 
     public function format($format)
     public function format($format)
@@ -37,9 +38,4 @@ class Date extends Text
 
 
         return parent::render();
         return parent::render();
     }
     }
-
-    public static function collectAssets()
-    {
-        Admin::collectAssets('bootstrap-datetimepicker');
-    }
 }
 }

+ 3 - 5
src/Form/Field/DateRange.php

@@ -7,6 +7,9 @@ use Dcat\Admin\Form\Field;
 
 
 class DateRange extends Field
 class DateRange extends Field
 {
 {
+    public static $js = 'bootstrap-datetimepicker';
+    public static $css = 'bootstrap-datetimepicker';
+
     protected $format = 'yyyy-mm-dd';
     protected $format = 'yyyy-mm-dd';
 
 
     /**
     /**
@@ -85,9 +88,4 @@ JS;
 
 
         return $result;
         return $result;
     }
     }
-
-    public static function collectAssets()
-    {
-        Admin::collectAssets('bootstrap-datetimepicker');
-    }
 }
 }

+ 3 - 7
src/Form/Field/Decimal.php

@@ -2,10 +2,11 @@
 
 
 namespace Dcat\Admin\Form\Field;
 namespace Dcat\Admin\Form\Field;
 
 
-use Dcat\Admin\Admin;
-
 class Decimal extends Text
 class Decimal extends Text
 {
 {
+    public static $js = 'jquery.inputmask';
+    public static $css = 'jquery.inputmask';
+
     /**
     /**
      * @see https://github.com/RobinHerbots/Inputmask#options
      * @see https://github.com/RobinHerbots/Inputmask#options
      *
      *
@@ -25,9 +26,4 @@ class Decimal extends Text
 
 
         return parent::render();
         return parent::render();
     }
     }
-
-    public static function collectAssets()
-    {
-        Admin::collectAssets('jquery.inputmask');
-    }
 }
 }

+ 3 - 7
src/Form/Field/Icon.php

@@ -2,10 +2,11 @@
 
 
 namespace Dcat\Admin\Form\Field;
 namespace Dcat\Admin\Form\Field;
 
 
-use Dcat\Admin\Admin;
-
 class Icon extends Text
 class Icon extends Text
 {
 {
+    public static $js = 'fontawesome-iconpicker';
+    public static $css = 'fontawesome-iconpicker';
+
     public function render()
     public function render()
     {
     {
         $this->script = <<<JS
         $this->script = <<<JS
@@ -19,9 +20,4 @@ JS;
 
 
         return parent::render();
         return parent::render();
     }
     }
-
-    public static function collectAssets()
-    {
-        Admin::collectAssets('fontawesome-iconpicker');
-    }
 }
 }

+ 3 - 7
src/Form/Field/Ip.php

@@ -2,10 +2,11 @@
 
 
 namespace Dcat\Admin\Form\Field;
 namespace Dcat\Admin\Form\Field;
 
 
-use Dcat\Admin\Admin;
-
 class Ip extends Text
 class Ip extends Text
 {
 {
+    public static $js = 'jquery.inputmask';
+    public static $css = 'jquery.inputmask';
+
     protected $rules = ['nullable', 'ip'];
     protected $rules = ['nullable', 'ip'];
 
 
     /**
     /**
@@ -17,11 +18,6 @@ class Ip extends Text
         'alias' => 'ip',
         'alias' => 'ip',
     ];
     ];
 
 
-    public static function collectAssets()
-    {
-        Admin::collectAssets('jquery.inputmask');
-    }
-
     public function render()
     public function render()
     {
     {
         $this->inputmask($this->options);
         $this->inputmask($this->options);

+ 3 - 7
src/Form/Field/Listbox.php

@@ -2,8 +2,6 @@
 
 
 namespace Dcat\Admin\Form\Field;
 namespace Dcat\Admin\Form\Field;
 
 
-use Dcat\Admin\Admin;
-
 /**
 /**
  * Class ListBox.
  * Class ListBox.
  *
  *
@@ -11,6 +9,9 @@ use Dcat\Admin\Admin;
  */
  */
 class Listbox extends MultipleSelect
 class Listbox extends MultipleSelect
 {
 {
+    public static $js = 'jquery.bootstrap-duallistbox';
+    public static $css = 'jquery.bootstrap-duallistbox';
+
     protected $settings = [];
     protected $settings = [];
 
 
     public function settings(array $settings)
     public function settings(array $settings)
@@ -38,9 +39,4 @@ JS;
 
 
         return parent::render();
         return parent::render();
     }
     }
-
-    public static function collectAssets()
-    {
-        Admin::collectAssets('jquery.bootstrap-duallistbox');
-    }
 }
 }

+ 3 - 7
src/Form/Field/Mobile.php

@@ -2,10 +2,11 @@
 
 
 namespace Dcat\Admin\Form\Field;
 namespace Dcat\Admin\Form\Field;
 
 
-use Dcat\Admin\Admin;
-
 class Mobile extends Text
 class Mobile extends Text
 {
 {
+    public static $js = 'jquery.inputmask';
+    public static $css = 'jquery.inputmask';
+
     /**
     /**
      * @see https://github.com/RobinHerbots/Inputmask#options
      * @see https://github.com/RobinHerbots/Inputmask#options
      *
      *
@@ -24,9 +25,4 @@ class Mobile extends Text
 
 
         return parent::render();
         return parent::render();
     }
     }
-
-    public static function collectAssets()
-    {
-        Admin::collectAssets('jquery.inputmask');
-    }
 }
 }

+ 4 - 5
src/Form/Field/Select.php

@@ -11,6 +11,10 @@ use Illuminate\Support\Str;
 
 
 class Select extends Field
 class Select extends Field
 {
 {
+    public static $js = 'select2';
+    public static $css = 'select2';
+
+
     /**
     /**
      * @var array
      * @var array
      */
      */
@@ -387,9 +391,4 @@ JS;
 
 
         return parent::render();
         return parent::render();
     }
     }
-
-    public static function collectAssets()
-    {
-        Admin::collectAssets('select2');
-    }
 }
 }

+ 3 - 5
src/Form/Field/SwitchField.php

@@ -7,6 +7,9 @@ use Dcat\Admin\Form\Field;
 
 
 class SwitchField extends Field
 class SwitchField extends Field
 {
 {
+    public static $js = 'switchery';
+    public static $css = 'switchery';
+
     public function primary()
     public function primary()
     {
     {
         return $this->color(Admin::color()->primary());
         return $this->color(Admin::color()->primary());
@@ -112,9 +115,4 @@ JS
 
 
         return parent::render();
         return parent::render();
     }
     }
-
-    public static function collectAssets()
-    {
-        Admin::collectAssets('switchery');
-    }
 }
 }

+ 3 - 5
src/Form/Field/Tags.php

@@ -11,6 +11,9 @@ use Illuminate\Support\Collection;
 
 
 class Tags extends Field
 class Tags extends Field
 {
 {
+    public static $js = 'select2';
+    public static $css = 'select2';
+
     /**
     /**
      * @var array
      * @var array
      */
      */
@@ -222,9 +225,4 @@ $(document).off('keyup', '.select2-selection--multiple .select2-search__field').
 JS
 JS
         );
         );
     }
     }
-
-    public static function collectAssets()
-    {
-        Admin::collectAssets('select2');
-    }
 }
 }

+ 3 - 5
src/Form/Field/Tree.php

@@ -11,6 +11,9 @@ use Illuminate\Support\Arr;
 
 
 class Tree extends Field
 class Tree extends Field
 {
 {
+    public static $js = 'jstree';
+    public static $css = 'jstree';
+
     protected $options = [
     protected $options = [
         'plugins' => ['checkbox', 'types'],
         'plugins' => ['checkbox', 'types'],
         'core'    => [
         'core'    => [
@@ -280,9 +283,4 @@ class Tree extends Field
 
 
         return parent::render(); // TODO: Change the autogenerated stub
         return parent::render(); // TODO: Change the autogenerated stub
     }
     }
-
-    public static function collectAssets()
-    {
-        Admin::collectAssets('jstree');
-    }
 }
 }

+ 3 - 5
src/Grid/Displayers/DialogTree.php

@@ -8,6 +8,9 @@ use Illuminate\Contracts\Support\Arrayable;
 
 
 class DialogTree extends AbstractDisplayer
 class DialogTree extends AbstractDisplayer
 {
 {
+    public static $js = 'jstree';
+    public static $css = 'jstree';
+
     protected $url;
     protected $url;
 
 
     protected $title;
     protected $title;
@@ -268,9 +271,4 @@ $('.{$this->getSelectorPrefix()}-open-tree').off('click').click(function () {
 JS
 JS
         );
         );
     }
     }
-
-    protected function collectAssets()
-    {
-        Admin::collectAssets('jstree');
-    }
 }
 }

+ 3 - 0
src/Grid/Displayers/Select.php

@@ -6,6 +6,9 @@ use Dcat\Admin\Admin;
 
 
 class Select extends AbstractDisplayer
 class Select extends AbstractDisplayer
 {
 {
+    public static $js = 'select2';
+    public static $css = 'select2';
+
     public function display($options = [])
     public function display($options = [])
     {
     {
         if ($options instanceof \Closure) {
         if ($options instanceof \Closure) {

+ 3 - 5
src/Grid/Displayers/SwitchDisplay.php

@@ -6,6 +6,9 @@ use Dcat\Admin\Admin;
 
 
 class SwitchDisplay extends AbstractDisplayer
 class SwitchDisplay extends AbstractDisplayer
 {
 {
+    public static $js = 'switchery';
+    public static $css = 'switchery';
+
     /**
     /**
      * @var string
      * @var string
      */
      */
@@ -118,9 +121,4 @@ EOF;
 JS
 JS
         );
         );
     }
     }
-
-    protected function collectAssets()
-    {
-        Admin::collectAssets('switchery');
-    }
 }
 }

+ 2 - 2
src/Grid/Displayers/Tree.php

@@ -7,7 +7,7 @@ use Dcat\Admin\Admin;
 class Tree extends AbstractDisplayer
 class Tree extends AbstractDisplayer
 {
 {
     protected static $js = [
     protected static $js = [
-        'vendor/dcat-admin/dcat-admin/grid-extend.min.js',
+        'grid-extension',
     ];
     ];
 
 
     protected function setupScript()
     protected function setupScript()
@@ -21,7 +21,7 @@ class Tree extends AbstractDisplayer
         $showNextPage = $model->showAllChildrenNodes() ? 'false' : 'true';
         $showNextPage = $model->showAllChildrenNodes() ? 'false' : 'true';
 
 
         $script = <<<JS
         $script = <<<JS
-Dcat.grid.tree({
+Dcat.grid.Tree({
     button: '.{$tableId}-grid-load-children',
     button: '.{$tableId}-grid-load-children',
     table: '#{$tableId}',
     table: '#{$tableId}',
     url: '{$model->generateTreeUrl()}',
     url: '{$model->generateTreeUrl()}',

+ 8 - 5
src/Grid/Filter/Presenter/DateTime.php

@@ -7,6 +7,14 @@ use Illuminate\Support\Arr;
 
 
 class DateTime extends Presenter
 class DateTime extends Presenter
 {
 {
+    public static $js = [
+        'bootstrap-datetimepicker',
+    ];
+
+    public static $css = [
+        'bootstrap-datetimepicker',
+    ];
+
     /**
     /**
      * @var array
      * @var array
      */
      */
@@ -55,9 +63,4 @@ class DateTime extends Presenter
             'group' => $this->filter->group,
             'group' => $this->filter->group,
         ];
         ];
     }
     }
-
-    public static function collectAssets()
-    {
-        Admin::collectAssets('bootstrap-datetimepicker');
-    }
 }
 }

+ 7 - 5
src/Grid/Filter/Presenter/Select.php

@@ -9,6 +9,13 @@ use Illuminate\Support\Arr;
 
 
 class Select extends Presenter
 class Select extends Presenter
 {
 {
+    public static $js = [
+        'select2',
+    ];
+    public static $css = [
+        'select2',
+    ];
+
     /**
     /**
      * @var string
      * @var string
      */
      */
@@ -328,9 +335,4 @@ JS;
     {
     {
         return str_replace('.', '_', $target);
         return str_replace('.', '_', $target);
     }
     }
-
-    public static function collectAssets()
-    {
-        Admin::collectAssets('select2');
-    }
 }
 }

+ 3 - 12
src/Widgets/Chart/Chart.php

@@ -20,6 +20,9 @@ abstract class Chart extends Widget
 {
 {
     use HasAjaxRequest;
     use HasAjaxRequest;
 
 
+    public static $js = 'chartjs';
+    public static $css = 'chartjs';
+
     public static $globalSettings = [
     public static $globalSettings = [
         'defaultFontColor'  => '#555',
         'defaultFontColor'  => '#555',
         'defaultFontFamily' => 'Nunito,system-ui,sans-serif',
         'defaultFontFamily' => 'Nunito,system-ui,sans-serif',
@@ -511,16 +514,4 @@ HTML;
             $this->colors = Color::$chartTheme['blue'];
             $this->colors = Color::$chartTheme['blue'];
         }
         }
     }
     }
-
-    /**
-     * Collect assets.
-     *
-     * @return void
-     */
-    public function collectAssets()
-    {
-        $this->script && Admin::script($this->script);
-
-        Admin::collectAssets('chartjs');
-    }
 }
 }

+ 9 - 11
src/Widgets/DataCard/Card.php

@@ -13,6 +13,15 @@ class Card extends Widget
 {
 {
     use HasAjaxRequest;
     use HasAjaxRequest;
 
 
+    public static $js = [
+        'waypoints',
+        'jquery.counterup',
+    ];
+    public static $css = [
+        'waypoints',
+        'jquery.counterup',
+    ];
+
     protected $view = 'admin::widgets.data-card';
     protected $view = 'admin::widgets.data-card';
 
 
     protected $options = [
     protected $options = [
@@ -215,15 +224,4 @@ JS
     {
     {
         return response()->json(array_merge($this->buildJsonResponseArray(), $data));
         return response()->json(array_merge($this->buildJsonResponseArray(), $data));
     }
     }
-
-    /**
-     * @return void
-     */
-    public function collectAssets()
-    {
-        parent::collectAssets();
-
-        Admin::collectAssets('waypoints');
-        Admin::collectAssets('jquery.counterup');
-    }
 }
 }

+ 3 - 11
src/Widgets/Sparkline/Sparkline.php

@@ -24,6 +24,9 @@ class Sparkline extends Widget
 {
 {
     use HasAjaxRequest;
     use HasAjaxRequest;
 
 
+    public static $js = 'jquery.sparkline';
+    public static $css = 'jquery.sparkline';
+
     protected static $optionMethods = [
     protected static $optionMethods = [
         'highlightSpotColor',
         'highlightSpotColor',
         'highlightLineColor',
         'highlightLineColor',
@@ -277,15 +280,4 @@ HTML;
             $data
             $data
         ));
         ));
     }
     }
-
-    /**
-     * Collect assets.
-     *
-     * @return void
-     */
-    protected function collectAssets()
-    {
-        $this->script && Admin::script($this->script);
-        Admin::collectAssets('jquery.sparkline');
-    }
 }
 }

+ 36 - 14
src/Widgets/Tree.php

@@ -8,8 +8,21 @@ use Illuminate\Support\Str;
 
 
 class Tree extends Widget
 class Tree extends Widget
 {
 {
+    public static $js = [
+        'jstree',
+    ];
+    public static $css = [
+        'jstree',
+    ];
+
+    /**
+     * @var string
+     */
     protected $view = 'admin::widgets.tree';
     protected $view = 'admin::widgets.tree';
 
 
+    /**
+     * @var array
+     */
     protected $options = [
     protected $options = [
         'plugins' => ['checkbox', 'types'],
         'plugins' => ['checkbox', 'types'],
         'core'    => [
         'core'    => [
@@ -30,10 +43,10 @@ class Tree extends Widget
         ],
         ],
     ];
     ];
 
 
-    public function __construct($nodes = [])
-    {
-        $this->nodes($nodes);
-    }
+    /**
+     * @var string
+     */
+    protected $id;
 
 
     /**
     /**
      * @var array
      * @var array
@@ -44,11 +57,27 @@ class Tree extends Widget
         'parent' => 'parent_id',
         'parent' => 'parent_id',
     ];
     ];
 
 
+    /**
+     * @var array
+     */
     protected $nodes = [];
     protected $nodes = [];
 
 
+    /**
+     * @var array
+     */
     protected $value = [];
     protected $value = [];
 
 
-    protected $checkedAll;
+    /**
+     * @var bool
+     */
+    protected $checkedAll = false;
+
+    public function __construct($nodes = [])
+    {
+        $this->nodes($nodes);
+
+        $this->id = 'widget-tree-'.Str::random(8);
+    }
 
 
     public function checkedAll()
     public function checkedAll()
     {
     {
@@ -107,16 +136,14 @@ class Tree extends Widget
 
 
     public function render()
     public function render()
     {
     {
-        $id = 'widget-tree-'.Str::random(8);
-
-        $this->id($id);
+        $this->id($this->id);
         $this->class('jstree-wrapper');
         $this->class('jstree-wrapper');
         $this->defaultHtmlAttribute('style', 'border:0;padding:5px 0');
         $this->defaultHtmlAttribute('style', 'border:0;padding:5px 0');
 
 
         $this->formatNodes();
         $this->formatNodes();
 
 
         $this->variables = [
         $this->variables = [
-            'id'    => $id,
+            'id'    => $this->id,
             'nodes' => &$this->nodes,
             'nodes' => &$this->nodes,
         ];
         ];
 
 
@@ -169,9 +196,4 @@ class Tree extends Widget
 
 
         $this->nodes = &$nodes;
         $this->nodes = &$nodes;
     }
     }
-
-    protected function collectAssets()
-    {
-        Admin::collectAssets('jstree');
-    }
 }
 }