diff --git a/module/testcase/control.php b/module/testcase/control.php index 609de098b8..ff5c8b3683 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -2787,32 +2787,36 @@ class testcase extends control */ public function updateOrder() { - $idList = explode(',', trim($this->post->idList, ',')); - $orderBy = $this->post->orderBy; - if(strpos($orderBy, 'sort') === false) return false; + $type = $this->post->type; + $sourceID = $this->post->sourceID; + $targetID = $this->post->targetID; + $dataList = $this->post->dataList; + if(!$type || !$sourceID || !$targetID || !$dataList) return false; - $caseIDList = array_filter(array_map(function($id){return strpos($id, 'case_') !== false ? str_replace('case_', '', $id) : '';}, $idList)); - $sceneIDList = array_filter(array_map(function($id){return strpos($id, 'scene_') !== false ? str_replace('scene_', '', $id) : '';}, $idList)); + $idList = array_map(function($data){return $data['id'];}, $dataList); + $orderList = array_map(function($data){return $data['order'];}, $dataList); + $sourceIndex = array_search($sourceID, $idList); + $targetIndex = array_search($targetID, $idList); - if(count($caseIDList) > 1) + if($sourceIndex > $targetIndex) { - $caseSorts = $this->dao->select('id, sort')->from(TABLE_CASE)->where('id')->in($caseIDList)->orderBy($orderBy)->fetchPairs(); - foreach($caseSorts as $id => $sort) - { - $caseID = array_shift($caseIDList); - - if($id != $caseID) $this->dao->update(TABLE_CASE)->set('sort')->eq($sort)->where('id')->eq($caseID)->exec(); - } + $idList = array_slice($idList, $targetIndex, $sourceIndex - $targetIndex + 1); + $orderList = array_slice($orderList, $targetIndex, $sourceIndex - $targetIndex + 1); + array_unshift($idList, array_pop($idList)); + } + else + { + $idList = array_slice($idList, $sourceIndex, $targetIndex - $sourceIndex + 1); + $orderList = array_slice($orderList, $sourceIndex, $targetIndex - $sourceIndex + 1); + array_splice($idList, -1, 0, array_shift($idList)); } - if(count($sceneIDList) > 1) + $table = $type == 'case' ? TABLE_CASE : TABLE_SCENE; + + foreach($idList as $key => $id) { - $sceneSorts = $this->dao->select('id, sort')->from(TABLE_SCENE)->where('id')->in($sceneIDList)->orderBy($orderBy)->fetchPairs(); - foreach($sceneSorts as $id => $sort) - { - $sceneID = array_shift($sceneIDList); - if($id != $sceneID) $this->dao->update(TABLE_SCENE)->set('sort')->eq($sort)->where('id')->eq($sceneID)->exec(); - } + if(!isset($orderList[$key])) continue; + $this->dao->update($table)->set('sort')->eq($orderList[$key])->where('id')->eq($id)->exec(); } } diff --git a/module/testcase/js/browse.js b/module/testcase/js/browse.js index 90c065aa1c..0199b7afdd 100644 --- a/module/testcase/js/browse.js +++ b/module/testcase/js/browse.js @@ -70,6 +70,8 @@ var DtSort = {}; DtSort.defaultConfig = { idAttrName: 'data-id', parentAttrName: 'data-parent', + productAttrName: 'data-product', + orderAttrName: 'data-order', dataNestedAttrName: 'data-nested', nestPathAttrName: 'data-nest-path', isSceneAttrName: 'data-is-scene', @@ -154,6 +156,8 @@ DtSort.Table.prototype.measure = function() var rowIndex = i; var id = $row.attr(this.options.idAttrName); var parent = $row.attr(this.options.parentAttrName); + var product = $row.attr(this.options.productAttrName); + var order = $row.attr(this.options.orderAttrName); var dataNested = $row.attr(this.options.dataNestedAttrName); var nestPath = $row.attr(this.options.nestPathAttrName); var isScene = $row.attr(this.options.isSceneAttrName); @@ -173,6 +177,8 @@ DtSort.Table.prototype.measure = function() id: id, index: i, parent: parent, + product: product, + order: order, dataNested: dataNested, nestPath: nestPath, isScene: isScene, diff --git a/module/testcase/view/browse.html.php b/module/testcase/view/browse.html.php index c36686e136..7fa510d35d 100644 --- a/module/testcase/view/browse.html.php +++ b/module/testcase/view/browse.html.php @@ -416,145 +416,121 @@ $(function(){$('#caseForm').table();})