jqh 5 年之前
父节点
当前提交
d8bd605ae6
共有 5 个文件被更改,包括 12 次插入10 次删除
  1. 1 0
      resources/lang/en/admin.php
  2. 1 0
      resources/lang/zh-CN/admin.php
  3. 6 2
      src/Form.php
  4. 2 6
      src/Repositories/EloquentRepository.php
  5. 2 2
      src/Traits/ModelTree.php

+ 1 - 0
resources/lang/en/admin.php

@@ -187,6 +187,7 @@ return [
     'selected_must_less_then'  => 'Only supports maximum :num options.',
     'quick_create'             => 'Quick create',
     'grid_items_selected'      => '{n} items selected',
+    'nothing_updated'          => 'Nothing has been updated.',
     'validation'               => [
         'match'     => 'The :attribute and :other must match.',
         'minlength' => 'The :attribute must be at least :min characters.',

+ 1 - 0
resources/lang/zh-CN/admin.php

@@ -188,6 +188,7 @@ return [
     'selected_must_less_then'  => '最多只能选择:num个选项',
     'quick_create'             => '快速创建',
     'grid_items_selected'      => '已选择 {n} 项',
+    'nothing_updated'          => '没有任何数据被更改',
     'validation'               => [
         'match'     => '与 :attribute 不匹配。',
         'minlength' => ':attribute 字符长度不能少于 :min。',

+ 6 - 2
src/Form.php

@@ -720,9 +720,13 @@ class Form implements Renderable
     protected function handleOrderable(array $input = [])
     {
         if (array_key_exists('_orderable', $input)) {
-            $input['_orderable'] == 1 ? $this->repository->moveOrderUp() : $this->repository->moveOrderDown();
+            $updated = $input['_orderable'] == 1
+                ? $this->repository->moveOrderUp()
+                : $this->repository->moveOrderDown();
 
-            return $this->ajaxResponse(__('admin.update_succeeded'));
+            return $updated
+                ? $this->ajaxResponse(__('admin.update_succeeded'))
+                : $this->error(__('admin.nothing_updated'));
         }
     }
 

+ 2 - 6
src/Repositories/EloquentRepository.php

@@ -313,9 +313,7 @@ class EloquentRepository extends Repository implements TreeRepository
                 )
             );
         }
-        $model->moveOrderUp();
-
-        return true;
+        return $model->moveOrderUp() ? true : false;
     }
 
     /**
@@ -337,9 +335,7 @@ class EloquentRepository extends Repository implements TreeRepository
             );
         }
 
-        $model->moveOrderDown();
-
-        return true;
+        return $model->moveOrderDown() ? true : false;
     }
 
     /**

+ 2 - 2
src/Traits/ModelTree.php

@@ -234,7 +234,7 @@ trait ModelTree
             ->first();
 
         if (! $swapWithModel) {
-            return $this;
+            return false;
         }
 
         return $this->swapOrderWithModel($swapWithModel);
@@ -252,7 +252,7 @@ trait ModelTree
             ->first();
 
         if (! $swapWithModel) {
-            return $this;
+            return false;
         }
 
         return $this->swapOrderWithModel($swapWithModel);