jqh 5 vuotta sitten
vanhempi
commit
1a2c144daf

+ 8 - 0
resources/assets/dcat/sass/components/_slider.scss

@@ -3,11 +3,19 @@
   right: -450px;
   box-shadow: $menu-shadow;
   z-index: 48;
+
+  .customizer-content {
+    width: 450px;
+  }
 }
 
 @media (max-width: 576px) {
   .customizer {
     width: 410px;
     right: -410px;
+
+    .customizer-content {
+      width: 410px;
+    }
   }
 }

+ 1 - 46
resources/views/form/file.blade.php

@@ -29,49 +29,4 @@
 
         @include('admin::form.help-block')
     </div>
-</div>
-
-<script data-exec-on-popstate>
-Dcat.ready(function () {
-    var upload, options = {!! $options !!}, listenComplete;
-
-    init();
-
-    function init() {
-        var opts = $.extend({
-            selector: '#{{ $containerId }}',
-            addFileButton: '#{{ $containerId }} .add-file-button',
-        }, options);
-
-        opts.upload = $.extend({
-            pick: {
-                id: '#{{ $containerId }} .file-picker',
-                label: '<i class="feather icon-folder"></i>&nbsp; {{trans('admin.uploader.add_new_media')}}'
-            },
-            dnd: '#{{ $containerId }} .dnd-area',
-            paste: '#{{ $containerId }} .web-uploader'
-        }, opts);
-
-        upload = Dcat.Uploader(opts);
-        upload.build();
-        upload.preview();
-
-        function resize() {
-            setTimeout(function () {
-                if (! upload) return;
-
-                upload.refreshButton();
-                resize();
-
-                if (! listenComplete) {
-                    listenComplete = 1;
-                    $(document).one('pjax:complete', function () {
-                        upload = null;
-                    });
-                }
-            }, 250);
-        }
-        resize();
-    }
-});
-</script>
+</div>

+ 3 - 3
resources/views/form/hasmany.blade.php

@@ -19,7 +19,7 @@
                 @endforeach
 
                 @if($options['allowDelete'])
-                <div class="form-group">
+                <div class="form-group row">
                     <label class="{{$viewClass['label']}} control-label"></label>
                     <div class="{{$viewClass['field']}}">
                         <div class="remove btn btn-warning btn-sm pull-right"><i class="fa fa-trash">&nbsp;</i>{{ trans('admin.remove') }}</div>
@@ -38,7 +38,7 @@
 
             {!! $template !!}
 
-            <div class="form-group">
+            <div class="form-group row">
                 <label class="{{$viewClass['label']}} control-label"></label>
                 <div class="{{$viewClass['field']}}">
                     <div class="remove btn btn-warning btn-sm pull-right"><i class="fa fa-trash"></i>&nbsp;{{ trans('admin.remove') }}</div>
@@ -49,7 +49,7 @@
     </template>
 
     @if($options['allowCreate'])
-    <div class="form-group">
+    <div class="form-group row">
         <label class="{{$viewClass['label']}} control-label"></label>
         <div class="{{$viewClass['field']}}">
             <div class="add btn btn-success btn-sm"><i class="feather icon-save"></i>&nbsp;{{ trans('admin.new') }}</div>

+ 4 - 4
src/Form/Field/Fieldset.php

@@ -15,11 +15,11 @@ class Fieldset
 
     public function start($title)
     {
-        $script = <<<SCRIPT
+        $script = <<<JS
 $('.{$this->name}-title').click(function () {
     $("i", this).toggleClass("fa-angle-double-down fa-angle-double-up");
 });
-SCRIPT;
+JS;
 
         Admin::script($script);
 
@@ -43,10 +43,10 @@ HTML;
 
     public function collapsed()
     {
-        $script = <<<SCRIPT
+        $script = <<<JS
 $("#{$this->name}").removeClass("in");
 $(".{$this->name}-title i").toggleClass("fa-angle-double-down fa-angle-double-up");
-SCRIPT;
+JS;
 
         Admin::script($script);
 

+ 58 - 3
src/Form/Field/File.php

@@ -5,6 +5,7 @@ namespace Dcat\Admin\Form\Field;
 use Dcat\Admin\Contracts\UploadField as UploadFieldInterface;
 use Dcat\Admin\Form\Field;
 use Dcat\Admin\Support\Helper;
+use Dcat\Admin\Support\JavaScript;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Support\Str;
@@ -31,6 +32,8 @@ class File extends Field implements UploadFieldInterface
         '@webuploader',
     ];
 
+    protected $containerId;
+
     /**
      * Create a new File instance.
      *
@@ -42,6 +45,8 @@ class File extends Field implements UploadFieldInterface
         parent::__construct($column, $arguments);
 
         $this->setupDefaultOptions();
+
+        $this->containerId = $this->generateId();
     }
 
     /**
@@ -163,19 +168,69 @@ class File extends Field implements UploadFieldInterface
             $this->setupPreviewOptions();
         }
 
+        $this->setupScript();
         $this->forceOptions();
-
         $this->formatValue();
 
         $this->addVariables([
-            'options'     => json_encode($this->options),
             'fileType'    => $this->options['isImage'] ? '' : 'file',
-            'containerId' => $this->generateId(),
+            'containerId' => $this->containerId,
         ]);
 
         return parent::render();
     }
 
+    protected function setupScript()
+    {
+        $newButton = trans('admin.uploader.add_new_media');
+        $options = JavaScript::format($this->options);
+
+        $this->script = <<<JS
+(function () {
+    var upload, options = {$options}, listenComplete;
+
+    build();
+
+    function build() {
+        var opts = $.extend({
+            selector: '#{$this->containerId}',
+            addFileButton: '#{$this->containerId} .add-file-button',
+        }, options);
+
+        opts.upload = $.extend({
+            pick: {
+                id: '#{$this->containerId} .file-picker',
+                label: '<i class="feather icon-folder"></i>&nbsp; {$newButton}'
+            },
+            dnd: '#{$this->containerId} .dnd-area',
+            paste: '#{$this->containerId} .web-uploader'
+        }, opts);
+
+        upload = Dcat.Uploader(opts);
+        upload.build();
+        upload.preview();
+
+        function resize() {
+            setTimeout(function () {
+                if (! upload) return;
+
+                upload.refreshButton();
+                resize();
+
+                if (! listenComplete) {
+                    listenComplete = 1;
+                    $(document).one('pjax:complete', function () {
+                        upload = null;
+                    });
+                }
+            }, 250);
+        }
+        resize();
+    }
+})();
+JS;
+    }
+
     /**
      * @return void
      */

+ 2 - 11
src/Form/Field/HasMany.php

@@ -309,16 +309,7 @@ class HasMany extends Field
         $form = $this->buildNestedForm($this->column, $this->builder);
 
         return array_values(
-            collect($form->setOriginal($this->original, $this->getKeyName())->prepare($input))
-                ->reject(function ($item) {
-                    return $item[NestedForm::REMOVE_FLAG_NAME] == 1;
-                })
-                ->map(function ($item) {
-                    unset($item[NestedForm::REMOVE_FLAG_NAME]);
-
-                    return $item;
-                })
-                ->toArray()
+            $form->setOriginal($this->original, $this->getKeyName())->prepare($input)
         );
     }
 
@@ -693,7 +684,7 @@ JS;
              * Get and remove the last script of Admin::$script stack.
              */
             if ($field->getScript()) {
-                $scripts[] = array_pop(Admin::$script);
+                $scripts[] = array_pop(Admin::asset()->script);
             }
         }
 

+ 1 - 1
src/Form/Field/Image.php

@@ -49,7 +49,7 @@ class Image extends File
 {
     use ImageField;
 
-    protected $rules = ['image'];
+    protected $rules = ['nullable', 'image'];
 
     protected $view = 'admin::form.file';
 

+ 2 - 4
src/Form/Field/SelectResource.php

@@ -172,8 +172,7 @@ class SelectResource extends Field
         $maxItem = (int) $this->maxItem;
         $queryName = SimpleGrid::QUERY_NAME;
 
-        Admin::script(
-            <<<JS
+        $this->script = <<<JS
 Dcat.ResourceSelector({
     title: '{$label}',
     column: "{$this->getElementName()}",
@@ -189,8 +188,7 @@ Dcat.ResourceSelector({
     displayer: 'navList',
     displayerContainer: $('#{$containerId}'),
 });
-JS
-        );
+JS;
     }
 
     protected function setupStyle()

+ 2 - 4
src/Form/Field/SwitchField.php

@@ -107,11 +107,9 @@ class SwitchField extends Field
         $this->attribute('type', 'checkbox');
         $this->attribute('data-plugin', $this->getFormElementId().'switchery');
 
-        Admin::script(
-            <<<JS
+        $this->script = <<<JS
 function swty(){\$('[data-plugin="{$this->getFormElementId()}switchery"]').each(function(){new Switchery($(this)[0],$(this).data())})} swty();
-JS
-        );
+JS;
 
         return parent::render();
     }

+ 1 - 1
src/Form/Field/Tags.php

@@ -187,7 +187,7 @@ class Tags extends Field
     protected function setupScript()
     {
         // 解决部分浏览器开启 tags: true 后无法输入中文的BUG
-        // 支持【逗号】【分号】【空格】结尾生成tags
+        // 支持"逗号" "分号" "空格"结尾生成tags
         $this->script = <<<JS
 $("{$this->getElementClassSelector()}").select2({
     tags: true,

+ 7 - 2
src/Form/NestedForm.php

@@ -179,7 +179,12 @@ class NestedForm
     public function prepare($input)
     {
         foreach ($input as $key => $record) {
+            if (! array_key_exists(static::REMOVE_FLAG_NAME, $record)) {
+                continue;
+            }
+
             $this->setFieldOriginalValue($key);
+
             $input[$key] = $this->prepareRecord($record);
         }
 
@@ -257,7 +262,7 @@ class NestedForm
                 $value = $field->prepare($value);
             }
 
-            if (($field instanceof \Dcat\Admin\Form\Field\Hidden) || $value != $field->original()) {
+            if (($field instanceof Form\Field\Hidden) || $value != $field->original()) {
                 if (is_array($columns)) {
                     foreach ($columns as $name => $column) {
                         Arr::set($prepared, $column, $value[$name]);
@@ -361,7 +366,7 @@ class NestedForm
              * Get and remove the last script of Admin::$script stack.
              */
             if ($field->getScript()) {
-                $scripts[] = array_pop(Admin::$script);
+                $scripts[] = array_pop(Admin::asset()->script);
             }
         }
 

+ 10 - 10
src/Layout/Asset.php

@@ -186,35 +186,35 @@ class Asset
      *
      * @var array
      */
-    protected $script = [];
+    public $script = [];
 
     /**
      * css代码.
      *
      * @var array
      */
-    protected $style = [];
+    public $style = [];
 
     /**
      * css脚本路径.
      *
      * @var array
      */
-    protected $css = [];
+    public $css = [];
 
     /**
      * js脚本路径.
      *
      * @var array
      */
-    protected $js = [];
+    public $js = [];
 
     /**
      * 在head标签内加载的js脚本.
      *
      * @var array
      */
-    protected $headerJs = [
+    public $headerJs = [
         'vendors' => '@vendors',
         'dcat'    => '@dcat',
     ];
@@ -224,7 +224,7 @@ class Asset
      *
      * @var array
      */
-    protected $baseCss = [
+    public $baseCss = [
         'vendors'            => '@vendors',
         'bootstrap'          => '@bootstrap',
         'bootstrap-extended' => '@bootstrap-extended',
@@ -244,7 +244,7 @@ class Asset
      *
      * @var array
      */
-    protected $baseJs = [
+    public $baseJs = [
         'menu'      => '@menu',
         'app'       => '@app',
         'toastr'    => '@toastr',
@@ -693,9 +693,9 @@ class Asset
         $script = implode(';', array_unique($this->script));
 
         return <<<HTML
-<script data-exec-on-popstate>
-Dcat.ready(function () { 
-    try {
+<script data-exec-on-popstate>
+Dcat.ready(function () { 
+    try {
         {$script}
     } catch (e) {
         console.error(e)