diff --git a/module/execution/control.php b/module/execution/control.php
index 605e0003de..cd58c689e7 100644
--- a/module/execution/control.php
+++ b/module/execution/control.php
@@ -2830,17 +2830,15 @@ class execution extends control
*/
public function storySort(int $executionID)
{
- if($_SERVER['REQUEST_METHOD'] !== 'POST') return $this->sendError($this->lang->error->unsupportedReq);
+ $storyIdList = json_decode($this->post->storyIdList, true);
+ $storyIdList = array_flip($storyIdList);
+ $orderBy = $this->post->orderBy;
- $idList = explode(',', trim($this->post->storyList, ','));
- $orderBy = $this->post->orderBy;
-
- $order = $this->dao->select('`order`')->from(TABLE_PROJECTSTORY)->where('story')->in($idList)->andWhere('project')->eq($executionID)->orderBy('order_asc')->fetch('order');
- if(strpos($orderBy, 'order_desc') !== false) $idList = array_reverse($idList);
- foreach($idList as $storyID)
+ krsort($storyIdList);
+ $order = $this->dao->select('`order`')->from(TABLE_PROJECTSTORY)->where('story')->in($storyIdList)->andWhere('project')->eq($executionID)->orderBy('order_asc')->fetch('order');
+ foreach($storyIdList as $storyID)
{
$this->dao->update(TABLE_PROJECTSTORY)->set('`order`')->eq($order)->where('story')->eq($storyID)->andWhere('project')->eq($executionID)->exec();
- if(dao::isError()) return $this->sendError(dao::getError());
$order++;
}
diff --git a/module/execution/js/story.ui.js b/module/execution/js/story.ui.js
index 9fa20c8cdb..e9728f1d03 100644
--- a/module/execution/js/story.ui.js
+++ b/module/execution/js/story.ui.js
@@ -161,6 +161,10 @@ window.renderStoryCell = function(result, info)
{
if(info.row.data.URChanged == '1') result[0] = {html: "" + URChanged + ""};
}
+ if(info.col.name == 'order')
+ {
+ result[0] = {html: "", className: 'text-gray cursor-move move-plan'};
+ }
return result;
};
@@ -181,3 +185,19 @@ window.toggleCheckRows = function(idList)
const dtable = zui.DTable.query($('#table-execution-story'));
dtable.$.toggleCheckRows(idList.split(','), true);
}
+
+window.onSortEnd = function(from, to, type)
+{
+ if(!from || !to) return false;
+
+ const url = $.createLink('execution', 'storySort', `execution=${executionID}`);
+ const form = new FormData();
+
+ form.append('storyIdList', JSON.stringify(this.state.rowOrders));
+ form.append('orderBy', orderBy);
+ form.append('pageID', storyPageID);
+ form.append('recPerPage', storyRecPerPage);
+
+ $.ajaxSubmit({url, data:form});
+ return true;
+}
diff --git a/module/execution/ui/story.html.php b/module/execution/ui/story.html.php
index 48ddb42c36..4b0bd80631 100644
--- a/module/execution/ui/story.html.php
+++ b/module/execution/ui/story.html.php
@@ -12,6 +12,9 @@ declare(strict_types=1);
namespace zin;
data('activeMenuID', $storyType);
+jsVar('orderBy', $orderBy);
+jsVar('storyPageID', $pager->pageID);
+jsVar('storyRecPerPage', $pager->recPerPage);
jsVar('executionID', $execution->id);
jsVar('childrenAB', $lang->story->childrenAB);
jsVar('modulePairs', $modulePairs);
@@ -583,6 +586,10 @@ dtable
set::groupDivider(true),
set::cols($cols),
set::data($data),
+ set::plugins(array('sortable')),
+ set::sortHandler('.move-plan'),
+ set::sortable($orderBy == 'order_desc'),
+ set::onSortEnd($orderBy == 'order_desc' ? jsRaw('window.onSortEnd') : null),
set::noNestedCheck(),
set::footToolbar($footToolbar),
set::onRenderCell(jsRaw('window.renderStoryCell')),
diff --git a/module/story/config/dtable.php b/module/story/config/dtable.php
index 0e1d686a33..d8413ffeb1 100644
--- a/module/story/config/dtable.php
+++ b/module/story/config/dtable.php
@@ -19,8 +19,9 @@ if($app->tab == 'execution')
$config->story->dtable->fieldList['order']['name'] = 'order';
$config->story->dtable->fieldList['order']['title'] = $lang->story->order;
$config->story->dtable->fieldList['order']['fixed'] = 'left';
- $config->story->dtable->fieldList['order']['sortType'] = false;
+ $config->story->dtable->fieldList['order']['sortType'] = true;
$config->story->dtable->fieldList['order']['width'] = '45';
+ $config->story->dtable->fieldList['order']['show'] = true;
}
$config->story->dtable->fieldList['title']['name'] = 'title';