* Adjust code task #117514,117513.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user