diff --git a/module/api/control.php b/module/api/control.php index a9ddca2f49..94a621c832 100755 --- a/module/api/control.php +++ b/module/api/control.php @@ -983,4 +983,25 @@ class api extends control { echo $this->fetch('tree', 'delete', "rootID=$rootID&moduleID=$moduleID&confirm=$confirm"); } + + /** + * Catalog sort. + * + * @access public + * @return void + */ + public function sortCatalog() + { + if($_SERVER['REQUEST_METHOD'] == 'POST') + { + foreach($_POST['orders'] as $id => $order) + { + $this->dao->update(TABLE_MODULE)->set('`order`')->eq($order)->where('id')->eq($id)->andWhere('type')->eq('api')->exec(); + } + + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + return $this->send(array('result' => 'success')); + } + + } } diff --git a/module/doc/control.php b/module/doc/control.php index 8a6791bf55..7fc73089d9 100755 --- a/module/doc/control.php +++ b/module/doc/control.php @@ -1567,4 +1567,25 @@ class doc extends control $this->display(); } + + /** + * Catalog sort. + * + * @access public + * @return void + */ + public function sortCatalog() + { + if($_SERVER['REQUEST_METHOD'] == 'POST') + { + foreach($_POST['orders'] as $id => $order) + { + $this->dao->update(TABLE_MODULE)->set('`order`')->eq($order)->where('id')->eq($id)->andWhere('type')->eq('doc')->exec(); + } + + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + return $this->send(array('result' => 'success')); + } + + } } diff --git a/module/doc/view/lefttree.html.php b/module/doc/view/lefttree.html.php index 257ef76390..2435c9a5e4 100644 --- a/module/doc/view/lefttree.html.php +++ b/module/doc/view/lefttree.html.php @@ -270,11 +270,12 @@ $(function() var objectType = config.currentModule == 'api' ? item.objectType : item.type; var libClass = ['lib', 'annex', 'api', 'execution'].indexOf(objectType) !== -1 ? 'lib' : ''; var moduleClass = item.type == 'doc' || item.type == 'apiDoc' ? 'catalog' : ''; - var sortClass = item.type == 'doc' && canSortDocCatalog ? ' sort-module' : ''; - if(item.type == 'apiDoc' && canSortAPICatalog) sortClass = 'sort-module'; - var hasChild = item.children ? !!item.children.length : false; - var link = item.type != 'execution' || item.hasAction ? '###' : '#'; - var $item = ''; + var sortClass = ''; + if(config.currentMethod != 'view' && ((item.type == 'doc' && canSortDocCatalog) || (item.type == 'apiDoc' && canSortAPICatalog))) sortClass = 'sort-module'; + + var hasChild = item.children ? !!item.children.length : false; + var link = item.type != 'execution' || item.hasAction ? '###' : '#'; + var $item = ''; $item += '
'; if((libClass == 'lib' && item.type != 'execution') || (item.type == 'execution' && item.hasAction)) $item += ''; @@ -301,7 +302,7 @@ $(function() if(item.versions) versionsData[item.id] = item.versions; $li.append($item); - $li.addClass(libClass).addClass(moduleClass).attr('data-order', item.order); + $li.addClass(libClass).addClass(moduleClass).attr('data-order', item.order).attr('data-type', item.type); if(item.active) $li.addClass('active'); }, }); @@ -687,7 +688,28 @@ $(function() }, finish: function(e) { + $('a.sort-module').removeClass('dragging-shadow'); if(!e.changed) return; + + var orders = {}; + var link = ''; + var module = e.list.context; + var moduleType = $(module).attr('data-type'); + $('#fileTree').find("li[data-type='" + moduleType + "'].catalog").each(function() + { + var $li = $(this); + var item = $li.data(); + orders['orders[' + item.id + ']'] = $li.attr('data-order') || item.order; + }); + + var moduleName = moduleType == 'apiDoc' ? 'api' : 'doc'; + link = createLink(moduleName, 'sortCatalog'); + + $.post(link, orders, function(data){}).error(function() + { + bootbox.alert(lang.timeout); + }); + } }); }) diff --git a/module/tree/model.php b/module/tree/model.php index 583f366afd..1f8c61c4c3 100644 --- a/module/tree/model.php +++ b/module/tree/model.php @@ -1837,8 +1837,14 @@ class treeModel extends model if($self) { - $self->parent = $module->parent; if($self->root and !isset($module->root)) $module->root = $self->root; + if($self->parent != $module->parent or $self->root != $module->root) + { + $maxOrder = $this->dao->select('MAX(`order`) AS `order`')->from(TABLE_MODULE)->where('parent')->eq($module->parent)->andWhere('root')->eq($module->root)->fetch('order'); + $module->order = $maxOrder ? ++ $maxOrder : $self->order; + } + + if($module->parent) $self->parent = $module->parent; } $repeatName = $this->checkUnique($self, array("id{$self->id}" => $module->name), array("id{$self->id}" => $module->branch));