Przeglądaj źródła

表格删除数据后刷新时保持url get参数 #961

jqh 5 lat temu
rodzic
commit
6f9fdff219

+ 5 - 4
resources/assets/dcat/js/bootstrappers/DataActions.js

@@ -27,8 +27,8 @@ let defaultActions = {
 
                         response.data.detail = msg;
 
-                        if (! response.then) {
-                            response.then = {action: 'redirect', value: redirect}
+                        if (redirect && ! response.data.then) {
+                            response.data.then = {action: 'redirect', value: redirect}
                         }
 
                         Dcat.handleJsonResponse(response);
@@ -42,6 +42,7 @@ let defaultActions = {
         $document.on('click', action, function() {
             let url = $(this).data('url'),
                 name = $(this).data('name'),
+                redirect = $(this).data('redirect'),
                 keys = Dcat.grid.selected(name),
                 lang = Dcat.lang;
 
@@ -57,8 +58,8 @@ let defaultActions = {
                     success: function (response) {
                         Dcat.NP.done();
 
-                        if (! response.then) {
-                            response.then = {action: 'refresh', value: true}
+                        if (redirect && ! response.data.then) {
+                            response.data.then = {action: 'redirect', value: redirect}
                         }
 
                         Dcat.handleJsonResponse(response);

Plik diff jest za duży
+ 0 - 0
resources/dist/dcat/js/dcat-app.js


Plik diff jest za duży
+ 0 - 0
resources/dist/dcat/js/dcat-app.js.map


+ 16 - 6
resources/dist/dcat/plugins/number-input/bootstrap-number-input.js

@@ -36,6 +36,16 @@
             var min = self.attr('min');
             var max = self.attr('max');
 
+            function getVal() {
+                var val = clone.val();
+
+                if (! val || val === "NaN") {
+                    return 0;
+                }
+
+                return parseInt(val);
+            }
+
             function setText(n) {
                 if ((min && n < min) || (max && n > max)) {
                     return false;
@@ -47,10 +57,10 @@
 
             var group = $("<div class='input-group'></div>");
             var down = $("<button type='button'>-</button>").attr('class', 'btn btn-' + settings.downClass).click(function () {
-                setText(parseInt(clone.val()) - 1);
+                setText(getVal() - 1);
             });
             var up = $("<button type='button'>+</button>").attr('class', 'btn btn-' + settings.upClass).click(function () {
-                setText(parseInt(clone.val()) + 1);
+                setText(getVal() + 1);
             });
             $("<span class='input-group-btn'></span>").append(down).appendTo(group);
             clone.appendTo(group);
@@ -62,8 +72,8 @@
             // remove spins from original
             clone.prop('type', 'text').keydown(function (e) {
                 if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
-					(e.keyCode == 65 && e.ctrlKey === true) ||
-					(e.keyCode >= 35 && e.keyCode <= 39)) {
+                    (e.keyCode == 65 && e.ctrlKey === true) ||
+                    (e.keyCode >= 35 && e.keyCode <= 39)) {
                     return;
                 }
                 if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
@@ -71,7 +81,7 @@
                 }
 
                 var c = String.fromCharCode(e.which);
-                var n = parseInt(clone.val() + c);
+                var n = (getVal() + c);
 
                 //if ((min && n < min) || (max && n > max)) {
                 //    e.preventDefault();
@@ -80,7 +90,7 @@
 
             clone.prop('type', 'text').blur(function (e) {
                 var c = String.fromCharCode(e.which);
-                var n = parseInt(clone.val() + c);
+                var n = getVal() + c;
                 if ((min && n < min)) {
                     setText(min);
                 }

+ 0 - 1
src/Form.php

@@ -590,7 +590,6 @@ class Form implements Renderable
                 ->alert()
                 ->status($status)
                 ->message($message)
-                ->redirectIf($status, $this->resource(-1))
         );
     }
 

+ 8 - 3
src/Grid/Actions/Delete.php

@@ -11,15 +11,20 @@ class Delete extends RowAction
      */
     public function title()
     {
+        if ($this->title) {
+            return $this->title;
+        }
+
         return '<i class="feather icon-trash"></i> '.__('admin.delete');
     }
 
     public function render()
     {
         $this->setHtmlAttribute([
-            'data-url'     => $this->url(),
-            'data-message' => "ID - {$this->getKey()}",
-            'data-action'  => 'delete',
+            'data-url'      => $this->url(),
+            'data-message'  => "ID - {$this->getKey()}",
+            'data-action'   => 'delete',
+            'data-redirect' => request()->fullUrl(),
         ]);
 
         return parent::render();

+ 4 - 0
src/Grid/Actions/Edit.php

@@ -11,6 +11,10 @@ class Edit extends RowAction
      */
     public function title()
     {
+        if ($this->title) {
+            return $this->title;
+        }
+
         return '<i class="feather icon-edit-1"></i> '.__('admin.edit');
     }
 

+ 4 - 0
src/Grid/Actions/QuickEdit.php

@@ -14,6 +14,10 @@ class QuickEdit extends RowAction
      */
     public function title()
     {
+        if ($this->title) {
+            return $this->title;
+        }
+
         return '<i class="feather icon-edit"></i> '.__('admin.quick_edit');
     }
 

+ 4 - 0
src/Grid/Actions/Show.php

@@ -11,6 +11,10 @@ class Show extends RowAction
      */
     public function title()
     {
+        if ($this->title) {
+            return $this->title;
+        }
+
         return '<i class="feather icon-eye"></i> '.__('admin.show');
     }
 

+ 1 - 1
src/Grid/BatchAction.php

@@ -31,6 +31,6 @@ JS;
      */
     public function getSelectedKeysScript()
     {
-        return "Dcat.grid.selected('{$this->parent->getName()}');";
+        return "Dcat.grid.selected('{$this->parent->getName()}')";
     }
 }

+ 28 - 20
src/Grid/Displayers/Actions.php

@@ -4,6 +4,10 @@ namespace Dcat\Admin\Grid\Displayers;
 
 use Dcat\Admin\Actions\Action;
 use Dcat\Admin\Form;
+use Dcat\Admin\Grid\Actions\Delete;
+use Dcat\Admin\Grid\Actions\Edit;
+use Dcat\Admin\Grid\Actions\QuickEdit;
+use Dcat\Admin\Grid\Actions\Show;
 use Dcat\Admin\Grid\RowAction;
 use Dcat\Admin\Support\Helper;
 use Illuminate\Contracts\Support\Htmlable;
@@ -229,11 +233,12 @@ class Actions extends AbstractDisplayer
     {
         $label = trans('admin.show');
 
-        return <<<EOT
-<a href="{$this->resource()}/{$this->getKey()}" title="{$label}">
-    <i class="feather icon-eye grid-action-icon"></i>
-</a>&nbsp;
-EOT;
+        return Show::make(
+            "<i title='{$label}' class=\"feather icon-eye grid-action-icon\"></i> &nbsp;"
+        )
+            ->setGrid($this->grid)
+            ->setRow($this->row)
+            ->render();
     }
 
     /**
@@ -245,11 +250,12 @@ EOT;
     {
         $label = trans('admin.edit');
 
-        return <<<EOT
-<a href="{$this->grid->getEditUrl($this->getKey())}" title="{$label}">
-    <i class="feather icon-edit-1 grid-action-icon"></i>
-</a>&nbsp;
-EOT;
+        return Edit::make(
+            "<i title='{$label}' class=\"feather icon-edit-1 grid-action-icon\"></i> &nbsp;"
+        )
+            ->setGrid($this->grid)
+            ->setRow($this->row)
+            ->render();
     }
 
     /**
@@ -270,11 +276,12 @@ EOT;
 
         $label = trans('admin.quick_edit');
 
-        return <<<EOF
-<a title="{$label}" class="{$this->grid->getRowName()}-edit" data-url="{$this->resource()}/{$this->getKey()}/edit" href="javascript:void(0);">
-    <i class="feather icon-edit grid-action-icon"></i>
-</a>&nbsp;
-EOF;
+        return QuickEdit::make(
+            "<i title='{$label}' class=\"feather icon-edit grid-action-icon\"></i> &nbsp;"
+        )
+            ->setGrid($this->grid)
+            ->setRow($this->row)
+            ->render();
     }
 
     /**
@@ -286,10 +293,11 @@ EOF;
     {
         $label = trans('admin.delete');
 
-        return <<<EOT
-<a title="{$label}" href="javascript:void(0);" data-message="ID - {$this->getKey()}" data-url="{$this->resource()}/{$this->getKey()}" data-action="delete">
-    <i class="feather icon-trash grid-action-icon"></i>
-</a>&nbsp;
-EOT;
+        return Delete::make(
+            "<i class=\"feather icon-trash grid-action-icon\" title='{$label}'></i> &nbsp;"
+        )
+            ->setGrid($this->grid)
+            ->setRow($this->row)
+            ->render();
     }
 }

+ 6 - 1
src/Grid/Tools/BatchDelete.php

@@ -13,8 +13,13 @@ class BatchDelete extends BatchAction
 
     public function render()
     {
+        $redirect = request()->fullUrl();
+
         return <<<HTML
-<a href="#" data-name="{$this->parent->getName()}" data-action="batch-delete" data-url="{$this->resource()}"><i class="feather icon-trash"></i> {$this->title}</a>
+<a  data-name="{$this->parent->getName()}" 
+    data-action="batch-delete" 
+    data-redirect="{$redirect}"
+    data-url="{$this->resource()}"><i class="feather icon-trash"></i> {$this->title}</a>
 HTML;
     }
 }

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików