jqh 5 vuotta sitten
vanhempi
commit
8c47f7f2bf
3 muutettua tiedostoa jossa 12 lisäystä ja 43 poistoa
  1. 7 7
      resources/views/tree/branch.blade.php
  2. 2 2
      src/Models/Permission.php
  3. 3 34
      src/Tree.php

+ 7 - 7
resources/views/tree/branch.blade.php

@@ -3,7 +3,7 @@
         {!! $branchCallback($branch) !!}
         <span class="pull-right dd-nodrag">
             @if($useEdit)
-            <a href="{{ $path }}/{{ $branch[$keyName] }}/edit"><i class="ti-pencil-alt "></i>&nbsp;</a>
+                <a href="{{ $path }}/{{ $branch[$keyName] }}/edit"><i class="ti-pencil-alt "></i>&nbsp;</a>
             @endif
 
             @if($useQuickEdit)
@@ -11,15 +11,15 @@
             @endif
 
             @if($useDelete)
-            <a href="javascript:void(0);" data-id="{{ $branch[$keyName] }}" class="tree_branch_delete"><i class="ti-trash "></i></a>
+                <a href="javascript:void(0);" data-url="{{ $path }}/{{ $branch[$keyName] }}" data-action="delete"><i class="ti-trash "></i></a>
             @endif
         </span>
     </div>
     @if(isset($branch['children']))
-    <ol class="dd-list">
-        @foreach($branch['children'] as $branch)
-            @include($branchView, $branch)
-        @endforeach
-    </ol>
+        <ol class="dd-list">
+            @foreach($branch['children'] as $branch)
+                @include($branchView, $branch)
+            @endforeach
+        </ol>
     @endif
 </li>

+ 2 - 2
src/Models/Permission.php

@@ -27,6 +27,8 @@ class Permission extends Model
         'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD',
     ];
 
+    protected $titleColumn = 'name';
+
     /**
      * Create a new Eloquent model instance.
      *
@@ -40,8 +42,6 @@ class Permission extends Model
 
         $this->setTable(config('admin.database.permissions_table'));
 
-        $this->titleColumn = 'name';
-
         parent::__construct($attributes);
     }
 

+ 3 - 34
src/Tree.php

@@ -12,6 +12,7 @@ use Illuminate\Contracts\Support\Htmlable;
 use Illuminate\Contracts\Support\Renderable;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Str;
 use Illuminate\Support\Traits\Macroable;
 
 class Tree implements Renderable
@@ -137,7 +138,7 @@ class Tree implements Renderable
         $this->path = $this->path ?: request()->getPathInfo();
         $this->url = url($this->path);
 
-        $this->elementId .= uniqid();
+        $this->elementId .= Str::random(8);
 
         $this->setupTools();
         $this->collectAssets();
@@ -356,44 +357,12 @@ class Tree implements Renderable
      */
     protected function script()
     {
-        $deleteConfirm = trans('admin.delete_confirm');
         $saveSucceeded = trans('admin.save_succeeded');
-        $deleteSucceeded = trans('admin.delete_succeeded');
-        $confirm = trans('admin.confirm');
-        $cancel = trans('admin.cancel');
-
         $nestableOptions = json_encode($this->nestableOptions);
 
         return <<<JS
 $('#{$this->elementId}').nestable($nestableOptions);
 
-$('.tree_branch_delete').click(function() {
-    var id = $(this).data('id');
-    
-     LA.confirm("$deleteConfirm", function () {
-        LA.NP.start();
-        $.ajax({
-            method: 'post',
-            url:  '{$this->url}/' + id,
-            data: {
-                _method:'delete',
-                _token:LA.token,
-            },
-            success: function (data) {
-                LA.NP.done();
-                if (typeof data === 'object') {
-                    if (data.status) {
-                        LA.reload();
-                        LA.success("$deleteSucceeded");
-                    } else {
-                        LA.error(data.message || 'Delete failed.');
-                    }
-                }
-            }
-        });
-    }, "$confirm", "$cancel");
-});
-
 $('.{$this->elementId}-save').click(function () {
     var serialize = $('#{$this->elementId}').nestable('serialize');
     LA.NP.start();
@@ -401,7 +370,7 @@ $('.{$this->elementId}-save').click(function () {
         _token: LA.token,
         _order: JSON.stringify(serialize)
     },
-    function(data){
+    function () {
         LA.NP.done();
         LA.reload();
         LA.success('{$saveSucceeded}');