* Adjust code task #117514,117513.

This commit is contained in:
王怡栋
2024-05-09 08:52:38 +08:00
parent 83856ee6ca
commit a717cffec8
4 changed files with 13 additions and 26 deletions
+7 -19
View File
@@ -635,28 +635,16 @@ class program extends control
*/
public function updateOrder()
{
$sourceID = (int)$this->post->sourceID;
$targetID = (int)$this->post->targetID;
$type = $this->post->type == 'after' ? 'after' : 'before';
$programIdList = json_decode($this->post->programIdList, true);
if(!$programIdList) return $this->send(array('result' => 'success'));
$program = $this->program->fetchByID($sourceID);
$oldOrders = $this->dao->select('id,`order`')->from(TABLE_PROJECT)->where('parent')->eq($program->parent)->orderBy('`order`')->fetchPairs('id', 'order');
$newOrders = array();
foreach(array_keys($oldOrders) as $i => $programID)
{
if($programID == $sourceID) continue;
asort($programIdList);
$programIdList = array_flip($programIdList);
$newIndex = ($i + 1) * 5;
$newOrders[$newIndex] = $programID;
if($programID == $targetID)
{
$newIndex = $type == 'before' ? $newIndex - 1 : $newIndex - 1;
$newOrders[$newIndex] = $sourceID;
}
}
ksort($newOrders);
$newOrders = array_combine($newOrders, $oldOrders);
$oldOrders = $this->dao->select('id,`order`')->from(TABLE_PROJECT)->where('id')->in($programIdList)->orderBy('`order`')->fetchPairs('id', 'order');
if(count($programIdList) != count($oldOrders)) return $this->send(array('result' => 'success'));
$newOrders = array_combine($programIdList, $oldOrders);
foreach($newOrders as $programID => $order)
{
if($order != $oldOrders[$programID]) $this->dao->update(TABLE_PROJECT)->set('`order`')->eq($order)->where('id')->eq($programID)->exec();
+1 -3
View File
@@ -140,9 +140,7 @@ window.onSortEnd = function(from, to, type)
const url = $.createLink('program', 'updateOrder');
const form = new FormData();
form.append('sourceID', from.data.id);
form.append('targetID', to.data.id);
form.append('type', type);
form.append('programIdList', JSON.stringify(this.state.rowOrders));
$.ajaxSubmit({url, data:form});
return true;
+4 -4
View File
@@ -182,14 +182,14 @@ toolbar
);
$canBatchEdit = common::hasPriv('project', 'batchEdit');
$canSortable = (common::hasPriv('program', 'updateOrder') && strpos($orderBy, 'order_asc') !== false);
$canSort = (common::hasPriv('program', 'updateOrder') && strpos($orderBy, 'order_asc') !== false);
dtable
(
setID('projectviews'),
set::plugins(array('sortable')),
set::sortable($canSortable),
set::onSortEnd($canSortable ? jsRaw('window.onSortEnd') : null),
set::canSortTo($canSortable ? jsRaw('window.canSortTo') : null),
set::sortable($canSort),
set::onSortEnd($canSort ? jsRaw('window.onSortEnd') : null),
set::canSortTo($canSort ? jsRaw('window.canSortTo') : null),
set::cols($cols),
set::data(array_values($data)),
set::userMap($users),
+1
View File
@@ -121,6 +121,7 @@ class programZen extends program
$status = strtolower($status);
$this->view->summary = '';
if(strpos($orderBy, 'order') !== false) $orderBy = "grade,{$orderBy}";
if(strtolower($status) == 'bysearch')
{
$programs = $this->program->getListBySearch($orderBy, $param, true, $pager);