diff --git a/module/doc/control.php b/module/doc/control.php index ff7f5a9bb6..8f839885ad 100644 --- a/module/doc/control.php +++ b/module/doc/control.php @@ -75,8 +75,9 @@ class doc extends control /* Set browseType.*/ $browseType = strtolower($browseType); + if(($this->cookie->browseType == 'bymenu' or $this->cookie->browseType == 'bytree') and $browseType != 'bysearch') $browseType = $this->cookie->browseType; $queryID = ($browseType == 'bysearch') ? (int)$param : 0; - $moduleID = ($browseType == 'bymodule') ? (int)$param : 0; + $moduleID = ($browseType == 'bymodule' or $browseType == 'bymenu') ? (int)$param : 0; $type = 'custom'; if($libID) @@ -121,11 +122,23 @@ class doc extends control if($item->name == "custom$libID" and empty($item->hidden)) $this->view->fixedMenu = true; } + if($this->cookie->browseType == 'bymenu') + { + $this->view->modules = $this->doc->getDocMenu($libID, $moduleID); + $this->view->parents = $this->loadModel('tree')->getParents($moduleID); + } + elseif($this->cookie->browseType == 'bytree') + { + $this->view->tree = $this->doc->getDocTree($libID); + } + else + { + $this->view->moduleTree = $this->loadModel('tree')->getTreeMenu($libID, $viewType = 'doc', $startModuleID = 0, array('treeModel', 'createDocLink')); + } + $this->view->libID = $libID; $this->view->libName = $this->libs[$libID]; $this->view->moduleID = $moduleID; - $this->view->moduleTree = $this->loadModel('tree')->getTreeMenu($libID, $viewType = 'doc', $startModuleID = 0, array('treeModel', 'createDocLink')); - $this->view->parentModules = $this->tree->getParents($moduleID); $this->view->docs = $docs; $this->view->pager = $pager; $this->view->users = $this->loadModel('user')->getPairs('noletter'); diff --git a/module/doc/js/browse.js b/module/doc/js/browse.js index 6fea69fe6f..846542ea8b 100644 --- a/module/doc/js/browse.js +++ b/module/doc/js/browse.js @@ -17,8 +17,15 @@ function browseBySearch() $('#querybox').addClass('show'); } +function setBrowseType(type) +{ + $.cookie('browseType', type, {expires:config.cookieLife, path:config.webRoot}); + location.href = location.href; +} + $(function(){ $('#' + browseType + 'Tab').addClass('active'); + if(fixedMenu) $('#modulemenu .nav li[data-id="custom' + libID + '"]').addClass('active'); if(browseType == "bysearch") { ajaxGetSearchForm(); diff --git a/module/doc/js/common.js b/module/doc/js/common.js index 0577677165..029c23ea5c 100644 --- a/module/doc/js/common.js +++ b/module/doc/js/common.js @@ -19,5 +19,6 @@ function toggleAcl(acl) $(document).ready(function() { $('[data-id="create"] a').modalTrigger({type: 'iframe', width: 800}); + $('#modulemenu .nav li').removeClass('active'); if(typeof(type) != 'undefined') $('#modulemenu .nav li[data-id="' + type + '"]').addClass('active'); }); diff --git a/module/doc/lang/zh-cn.php b/module/doc/lang/zh-cn.php index ef8a577d6a..5f37ec26be 100644 --- a/module/doc/lang/zh-cn.php +++ b/module/doc/lang/zh-cn.php @@ -77,6 +77,11 @@ $lang->doc->aclList['private'] = '私有'; $lang->doc->contentTypeList['html'] = 'HTML'; $lang->doc->contentTypeList['markdown'] = 'MarkDown'; +$lang->doc->browseType = '浏览方式'; +$lang->doc->browseTypeList['list'] = '列表'; +$lang->doc->browseTypeList['menu'] = '目录'; +$lang->doc->browseTypeList['tree'] = '树状图'; + $lang->doc->confirmDelete = "您确定删除该文档吗?"; $lang->doc->confirmDeleteLib = "您确定删除该文档库吗?"; $lang->doc->errorEditSystemDoc = "系统文档库无需修改。"; diff --git a/module/doc/model.php b/module/doc/model.php index d46954a1a3..8c287f2cbd 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -170,6 +170,20 @@ class docModel extends model if($moduleID) $modules = $this->loadModel('tree')->getAllChildId($moduleID); $docs = $this->getDocs($libID, $modules, $sort, $pager); } + elseif($browseType == "bymenu") + { + $condition = $this->buildConditionSQL(); + $docs = $this->dao->select('*')->from(TABLE_DOC)->where('deleted')->eq(0)->andWhere('lib')->in($libID) + ->andWhere('module')->eq($moduleID) + ->beginIF($condition)->andWhere("($condition)")->fi() + ->orderBy($sort) + ->page($pager) + ->fetchAll(); + } + elseif($browseType == 'bytree') + { + return array(); + } elseif($browseType == "bysearch") { if($queryID) @@ -494,6 +508,22 @@ class docModel extends model ->fetchPairs('id', 'name'); } + /** + * Get doc menu. + * + * @param int $libID + * @param int $parent + * @access public + * @return void + */ + public function getDocMenu($libID, $parent) + { + return $this->dao->select('*')->from(TABLE_MODULE)->where('root')->eq($libID) + ->andWhere('type')->eq('doc') + ->andWhere('parent')->eq($parent) + ->fetchAll('id'); + } + /** * Extract css styles for tables created in kindeditor. * @@ -788,4 +818,79 @@ class docModel extends model } return $condition; } + + /** + * Get doc tree. + * + * @param int $libID + * @access public + * @return array + */ + public function getDocTree($libID) + { + $fullTrees = $this->loadModel('tree')->getTreeStructure($libID, 'doc'); + array_unshift($fullTrees, array('id' => 0, 'name' => '/', 'type' => 'doc', 'actions' => false, 'root' => $libID)); + foreach($fullTrees as $i => $tree) + { + $tree = (object)$tree; + $fullTrees[$i] = $this->fillDocsInTree($tree, $libID); + } + if(empty($fullTrees[0]->children)) array_shift($fullTrees); + return $fullTrees; + } + + /** + * Fill docs in tree. + * + * @param object $node + * @param int $libID + * @access public + * @return array + */ + public function fillDocsInTree($node, $libID) + { + $node = (object)$node; + static $docGroups; + if(empty($docGroups)) + { + $condition = $this->buildConditionSQL(); + $docs = $this->dao->select('*')->from(TABLE_DOC) + ->where('lib')->eq((int)$libID) + ->beginIF($condition)->andWhere("($condition)")->fi() + ->andWhere('deleted')->eq(0) + ->fetchAll(); + $docGroups = array(); + foreach($docs as $doc) $docGroups[$doc->module][$doc->id] = $doc; + } + + if(!empty($node->children)) foreach($node->children as $i => $child) $node->children[$i] = $this->fillDocsInTree($child, $libID); + if(!isset($node->id))$node->id = 0; + + $node->type = 'module'; + $docs = isset($docGroups[$node->id]) ? $docGroups[$node->id] : array(); + if(!empty($docs)) + { + $docItems = array(); + foreach($docs as $doc) + { + $docItem = new stdclass(); + $docItem->type = 'doc'; + $docItem->id = $doc->id; + $docItem->title = $doc->title; + $docItem->url = helper::createLink('doc', 'view', "doc=$doc->id"); + + $buttons = ''; + $buttons .= common::buildIconButton('doc', 'edit', "docID=$doc->id", '', 'list'); + if(common::hasPriv('doc', 'delete'))$buttons .= html::a(helper::createLink('doc', 'delete', "docID=$doc->id"), "", 'hiddenwin', "class='btn-icon' title='{$this->lang->doc->delete}'"); + $docItem->buttons = $buttons; + $docItem->actions = false; + $docItems[] = $docItem; + } + $node->docsCount = count($docItems); + $node->children = $docItems; + } + + $node->actions = false; + return $node; + } } diff --git a/module/doc/view/browse.html.php b/module/doc/view/browse.html.php index 69e6fe5c18..d168ffc756 100644 --- a/module/doc/view/browse.html.php +++ b/module/doc/view/browse.html.php @@ -12,11 +12,18 @@ ?> -doc->confirmDelete)?> -; +doc->confirmDelete)?> + + + +cookie->browseType == 'bymenu'):?> + +cookie->browseType == 'bytree'):?> + +