diff --git a/module/program/control.php b/module/program/control.php index 08bc51ac5e..1108142412 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -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(); diff --git a/module/program/js/browse.ui.js b/module/program/js/browse.ui.js index 0d2b43087f..e8d73ef158 100644 --- a/module/program/js/browse.ui.js +++ b/module/program/js/browse.ui.js @@ -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; diff --git a/module/program/ui/browse.html.php b/module/program/ui/browse.html.php index 0431168198..73a244f671 100644 --- a/module/program/ui/browse.html.php +++ b/module/program/ui/browse.html.php @@ -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), diff --git a/module/program/zen.php b/module/program/zen.php index 01408f5a51..5c10d5ce79 100644 --- a/module/program/zen.php +++ b/module/program/zen.php @@ -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);