jqh 5 年之前
父节点
当前提交
984d91b887
共有 9 个文件被更改,包括 102 次插入62 次删除
  1. 1 1
      src/AdminServiceProvider.php
  2. 0 3
      src/Form.php
  3. 0 2
      src/Form/Builder.php
  4. 14 0
      src/Form/Field.php
  5. 0 4
      src/Grid.php
  6. 33 17
      src/Grid/Tools/CreateButton.php
  7. 6 6
      src/Traits/BuilderEvents.php
  8. 46 25
      src/Tree.php
  9. 2 4
      src/Widgets/DialogForm.php

+ 1 - 1
src/AdminServiceProvider.php

@@ -203,7 +203,7 @@ class AdminServiceProvider extends ServiceProvider
 
         $this->app->singleton('admin.menu', Menu::class);
 
-        $this->app->singleton('admin.object', Fluent::class);
+        $this->app->singleton('admin.temp', Fluent::class);
     }
 
     /**

+ 0 - 3
src/Form.php

@@ -3,7 +3,6 @@
 namespace Dcat\Admin;
 
 use Closure;
-use Dcat\Admin\Exception\Handler;
 use Dcat\Admin\Form\Builder;
 use Dcat\Admin\Form\Field;
 use Dcat\Admin\Form\Row;
@@ -13,8 +12,6 @@ use Dcat\Admin\Traits\BuilderEvents;
 use Dcat\Admin\Widgets\DialogForm;
 use Illuminate\Contracts\Support\MessageProvider;
 use Illuminate\Contracts\Support\Renderable;
-use Illuminate\Support\Facades\URL;
-use Illuminate\Http\Request;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Facades\Input;
 use Illuminate\Support\Fluent;

+ 0 - 2
src/Form/Builder.php

@@ -5,8 +5,6 @@ namespace Dcat\Admin\Form;
 use Dcat\Admin\Admin;
 use Dcat\Admin\Form;
 use Dcat\Admin\Form\Field\Hidden;
-use Dcat\Admin\Widgets\Box;
-use Dcat\Admin\Widgets\Card;
 use Illuminate\Contracts\Support\Renderable;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Collection;

+ 14 - 0
src/Form/Field.php

@@ -898,6 +898,20 @@ class Field implements Renderable
         return $formId . ' .'.implode('.', $elementClass);
     }
 
+    /**
+     * Remove the field in dialog.
+     *
+     * @return $this
+     */
+    public function hideInDialog()
+    {
+        if (Form::isDialogFormPage()) {
+            $this->setDisplay(false);
+        }
+
+        return $this;
+    }
+
     /**
      * @return string|null
      */

+ 0 - 4
src/Grid.php

@@ -3,13 +3,11 @@
 namespace Dcat\Admin;
 
 use Closure;
-use Dcat\Admin\Exception\Handler;
 use Dcat\Admin\Grid\Column;
 use Dcat\Admin\Grid\Displayers;
 use Dcat\Admin\Grid\Exporter;
 use Dcat\Admin\Grid\Exporters\AbstractExporter;
 use Dcat\Admin\Grid\Filter;
-use Dcat\Admin\Grid\Header;
 use Dcat\Admin\Grid\Model;
 use Dcat\Admin\Grid\Responsive;
 use Dcat\Admin\Grid\Row;
@@ -23,9 +21,7 @@ use Illuminate\Contracts\Support\Htmlable;
 use Illuminate\Contracts\Support\Renderable;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Input;
-use Illuminate\Support\Facades\URL;
 use Illuminate\Support\Str;
-use Jenssegers\Mongodb\Eloquent\Model as MongodbModel;
 
 class Grid
 {

+ 33 - 17
src/Grid/Tools/CreateButton.php

@@ -17,32 +17,48 @@ class CreateButton
         $this->grid = $grid;
     }
 
-    public function render()
+    protected function renderQuickCreateButton()
     {
+        if (! $this->grid->option('show_quick_create_btn')) {
+            return;
+        }
+
         $new = trans('admin.new');
         $url = $this->grid->getCreateUrl();
 
-        $quickBtn = $btn = '';
-        if ($this->grid->option('show_create_btn')) {
-            $btn = "<a href='{$url}' class='btn btn-sm btn-success btn-mini'>
-    <i class='ti-plus'></i><span class='hidden-xs'>&nbsp;&nbsp;{$new}</span>
-</a>";
-        }
+        list($width, $height) = $this->grid->option('dialog_form_area');
+
+        Form::popup($new)
+            ->click(".{$this->grid->getGridRowName()}-create")
+            ->success('LA.reload()')
+            ->dimensions($width, $height)
+            ->render();
 
-        if ($this->grid->option('show_quick_create_btn')) {
-            list($width, $height) = $this->grid->option('dialog_form_area');
+        $text = $this->grid->option('show_create_btn') ? '<i class="fa fa-clone"></i>' : "<i class='ti-plus'></i><span class='hidden-xs'> &nbsp; $new</span>";
 
-            Form::popup($new)
-                ->click(".{$this->grid->getGridRowName()}-create")
-                ->success('LA.reload()')
-                ->dimensions($width, $height)
-                ->render();
+        return "<a data-url='$url' class='btn btn-sm btn-success {$this->grid->getGridRowName()}-create'>$text</a>";
+    }
 
-            $text = $this->grid->option('show_create_btn') ? '<i class=\' fa fa-clone\'></i>' : "<i class='ti-plus'></i><span class='hidden-xs'> &nbsp; $new</span>";
+    protected function renderCreateButton()
+    {
+        if (! $this->grid->option('show_create_btn')) {
+            return;
+        }
 
-            $quickBtn = "<a data-url='$url' class='btn btn-sm btn-success {$this->grid->getGridRowName()}-create'>$text</a>";
+        $new = trans('admin.new');
+        $url = $this->grid->getCreateUrl();
+
+        return "<a href='{$url}' class='btn btn-sm btn-success btn-mini'>
+    <i class='ti-plus'></i><span class='hidden-xs'>&nbsp;&nbsp;{$new}</span>
+</a>";
+    }
+
+    public function render()
+    {
+        if (! $this->grid->option('show_create_btn') && ! $this->grid->option('show_quick_create_btn')) {
+            return;
         }
 
-        return "<div class='btn-group' style='margin-right:3px'>{$btn}{$quickBtn}</div>";
+        return "<div class='btn-group' style='margin-right:3px'>{$this->renderCreateButton()}{$this->renderQuickCreateButton()}</div>";
     }
 }

+ 6 - 6
src/Traits/BuilderEvents.php

@@ -48,11 +48,11 @@ trait BuilderEvents
      */
     protected function callBuilderListeners($key, ...$params)
     {
-        $object = app('admin.object');
+        $storage = app('admin.temp');
 
         $key = static::formatBuilderEventKey($key);
 
-        $listeners = $object->get($key) ?: [];
+        $listeners = $storage->get($key) ?: [];
 
         foreach ($listeners as $k => $listener) {
             list($callback, $once) = $listener;
@@ -64,7 +64,7 @@ trait BuilderEvents
             call_user_func($callback, $this, ...$params);
         }
 
-        $object[$key] = $listeners;
+        $storage[$key] = $listeners;
     }
 
     /**
@@ -74,15 +74,15 @@ trait BuilderEvents
      */
     protected static function setListeners($key, $callback, $once)
     {
-        $object = app('admin.object');
+        $storage = app('admin.temp');
 
         $key = static::formatBuilderEventKey($key);
 
-        $listeners = $object->get($key) ?: [];
+        $listeners = $storage->get($key) ?: [];
 
         $listeners[] = [$callback, $once];
 
-        $object[$key] = $listeners;
+        $storage[$key] = $listeners;
     }
 
     protected static function formatBuilderEventKey($key)

+ 46 - 25
src/Tree.php

@@ -59,6 +59,11 @@ class Tree implements Renderable
      */
     public $path;
 
+    /**
+     * @var string
+     */
+    public $url;
+
     /**
      * @var bool
      */
@@ -127,6 +132,7 @@ class Tree implements Renderable
         $this->model = $model;
 
         $this->path = $this->path ?: request()->getPathInfo();
+        $this->url = url($this->path);
         $this->elementId .= uniqid();
 
         $this->setupTools();
@@ -136,8 +142,6 @@ class Tree implements Renderable
             call_user_func($callback, $this);
         }
 
-        $this->initBranchCallback();
-
         $this->callResolving();
     }
 
@@ -159,7 +163,7 @@ class Tree implements Renderable
      *
      * @return void
      */
-    protected function initBranchCallback()
+    protected function setDefaultBranchCallback()
     {
         if (is_null($this->branchCallback)) {
             $this->branchCallback = function ($branch) {
@@ -337,7 +341,7 @@ $('.tree_branch_delete').click(function() {
         LA.NP.start();
         $.ajax({
             method: 'post',
-            url:  '{$this->path}/' + id,
+            url:  '{$this->url}/' + id,
             data: {
                 _method:'delete',
                 _token:LA.token,
@@ -360,7 +364,7 @@ $('.tree_branch_delete').click(function() {
 $('.{$this->elementId}-save').click(function () {
     var serialize = $('#{$this->elementId}').nestable('serialize');
     LA.NP.start();
-    $.post('{$this->path}', {
+    $.post('{$this->url}', {
         _token: LA.token,
         _order: JSON.stringify(serialize)
     },
@@ -447,7 +451,7 @@ JS;
             return '';
         }
 
-        $url = $this->path . '/create';
+        $url = $this->url . '/create';
         $new = trans('admin.new');
 
         $quickBtn = $btn = '';
@@ -463,6 +467,38 @@ JS;
         return "<div class='btn-group pull-right' style='margin-right:3px'>{$btn}{$quickBtn}</div>";
     }
 
+    /**
+     * @return void
+     */
+    protected function renderQuickEditButton()
+    {
+        if ($this->useQuickEdit) {
+            list($width, $height) = $this->dialogFormDimensions;
+
+            Form::popup(trans('admin.edit'))
+                ->click('.tree-quick-edit')
+                ->success('LA.reload()')
+                ->dimensions($width, $height)
+                ->render();
+        }
+    }
+
+    /**
+     * @return void
+     */
+    protected function renderQuickCreateButton()
+    {
+        if ($this->useQuickCreate) {
+            list($width, $height) = $this->dialogFormDimensions;
+
+            Form::popup(trans('admin.new'))
+                ->click('.tree-quick-create')
+                ->success('LA.reload()')
+                ->dimensions($width, $height)
+                ->render();
+        }
+    }
+
     /**
      * Render a tree.
      *
@@ -473,30 +509,15 @@ JS;
         try {
             $this->callResolving();
 
-            if ($this->useQuickEdit) {
-                list($width, $height) = $this->dialogFormDimensions;
-
-                Form::popup(trans('admin.edit'))
-                    ->click('.tree-quick-edit')
-                    ->success('LA.reload()')
-                    ->dimensions($width, $height)
-                    ->render();
-            }
-
-            if ($this->useQuickCreate) {
-                list($width, $height) = $this->dialogFormDimensions;
+            $this->setDefaultBranchCallback();
 
-                Form::popup(trans('admin.new'))
-                    ->click('.tree-quick-create')
-                    ->success('LA.reload()')
-                    ->dimensions($width, $height)
-                    ->render();
-            }
+            $this->renderQuickEditButton();
+            $this->renderQuickCreateButton();
 
             Admin::script($this->script());
 
             view()->share([
-                'path'           => url($this->path),
+                'path'           => $this->url,
                 'keyName'        => $this->model->getKeyName(),
                 'branchView'     => $this->view['branch'],
                 'branchCallback' => $this->branchCallback,

+ 2 - 4
src/Widgets/DialogForm.php

@@ -290,10 +290,8 @@ JS
         $form->disableHeader();
         $form->disableFooter();
 
-        Form::composing(function (Form $form) {
-            $form->setWidth(9, 2);
-            $form->hidden('_token')->value(csrf_token());
-        });
+        $form->setWidth(9, 2);
+        $form->hidden('_token')->value(csrf_token());
 
         Content::composing(function (Content $content) {
             $content->setView(static::$contentView);