From b715ecd177780ee37a3c51e68afe68702d2b5d7a Mon Sep 17 00:00:00 2001 From: tianshujie Date: Wed, 11 May 2022 11:13:41 +0800 Subject: [PATCH 1/3] * Finish task #53655. --- module/doc/control.php | 20 ++++++++++++++++ module/doc/lang/en.php | 1 + module/doc/lang/zh-cn.php | 1 + module/doc/model.php | 30 ++++++++++++++--------- module/doc/view/side.html.php | 44 +++++++++++++++++++++++++++------- module/group/lang/resource.php | 1 + 6 files changed, 77 insertions(+), 20 deletions(-) diff --git a/module/doc/control.php b/module/doc/control.php index 362d8e7ef4..a8a29389c1 100644 --- a/module/doc/control.php +++ b/module/doc/control.php @@ -695,6 +695,26 @@ class doc extends control } } + /** + * Update order. + * + * @access public + * @return void + */ + public function updateOrder() + { + if($_SERVER['REQUEST_METHOD'] == 'POST') + { + foreach($_POST['orders'] as $id => $order) + { + $this->dao->update(TABLE_DOC)->set('`order`')->eq($order)->where('id')->eq($id)->exec(); + } + + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + return $this->send(array('result' => 'success')); + } + } + /** * Ajax get modules by libID. * diff --git a/module/doc/lang/en.php b/module/doc/lang/en.php index bd888eb70d..ac26a6ddbb 100644 --- a/module/doc/lang/en.php +++ b/module/doc/lang/en.php @@ -93,6 +93,7 @@ $lang->doc->collector = 'Collector'; $lang->doc->main = 'Main Document Library'; $lang->doc->order = 'Order'; $lang->doc->doc = 'Document'; +$lang->doc->updateOrder = 'Update Order'; $lang->doc->moduleDoc = 'By Module'; $lang->doc->searchDoc = 'Search'; diff --git a/module/doc/lang/zh-cn.php b/module/doc/lang/zh-cn.php index ff69f8c514..1fd47b0c4d 100644 --- a/module/doc/lang/zh-cn.php +++ b/module/doc/lang/zh-cn.php @@ -93,6 +93,7 @@ $lang->doc->collector = '收藏者'; $lang->doc->main = '文档主库'; $lang->doc->order = '排序'; $lang->doc->doc = '文档'; +$lang->doc->updateOrder = '更新排序'; $lang->doc->moduleDoc = '按模块浏览'; $lang->doc->searchDoc = '搜索'; diff --git a/module/doc/model.php b/module/doc/model.php index bd6c10c81c..a94dae1220 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -2379,6 +2379,7 @@ EOT; $docs = $this->dao->select('*')->from(TABLE_DOC) ->where('lib')->eq($rootID) ->andWhere('deleted')->eq(0) + ->orderBy('`order` asc') ->fetchAll(); $moduleDocs = array(); foreach($docs as $doc) @@ -2410,7 +2411,8 @@ EOT; { if(!$docID and $currentMethod != 'tablecontents') $docID = $doc->id; - $treeMenu[0] .= 'id == $docID ? ' class="active"' : ' class="independent"') . " data-id=$doc->id>"; + $class = common::hasPriv('doc', 'updateOrder') ? ' sortDoc' : ''; + $treeMenu[0] .= 'id>"; if($currentMethod == 'tablecontents') { @@ -2418,11 +2420,13 @@ EOT; } if($currentMethod == 'objectlibs') { - $treeMenu[0] .= "
" . html::a(inlink('objectLibs', "type=$type&objectID=$objectID&libID=$rootID&docID={$doc->id}"), "  " . $doc->title, '', "data-app='{$this->app->tab}' class='doc-title' title='{$doc->title}'") . ''; - if(common::hasPriv('doc', 'edit')) + $class = common::hasPriv('doc', 'updateOrder') ? 'sortDoc' : ''; + $treeMenu[0] .= "
" . html::a(inlink('objectLibs', "type=$type&objectID=$objectID&libID=$rootID&docID={$doc->id}"), "  " . $doc->title, '', "data-app='{$this->app->tab}' class='doc-title $class' title='{$doc->title}'") . ''; + if(common::hasPriv('doc', 'edit') or common::hasPriv('doc', 'updateOrder')) { $treeMenu[0] .= "
"; - $treeMenu[0] .= html::a(helper::createLink('doc', 'edit', "docID={$doc->id}&comment=false&objectType=$type&objectID=$objectID&libID=$rootID"), "", '', "title={$this->lang->doc->edit} data-app='{$this->app->tab}'"); + if(common::hasPriv('doc', 'edit')) $treeMenu[0] .= html::a(helper::createLink('doc', 'edit', "docID={$doc->id}&comment=false&objectType=$type&objectID=$objectID&libID=$rootID"), "", '', "title={$this->lang->doc->edit} data-app='{$this->app->tab}'"); + if(common::hasPriv('doc', 'updateOrder')) $treeMenu[0] .= html::a('javascript:;', "", '', "title='{$this->lang->doc->updateOrder}' class='sortDoc'"); $treeMenu[0] .= '
'; } } @@ -2477,7 +2481,8 @@ EOT; else { if(!$docID and $currentMethod != 'tablecontents') $docID = $doc->id; - $treeMenu[$module->id] .= 'id == $docID ? ' class="active"' : ' class="doc"') . " data-id=$doc->id>"; + $class = common::hasPriv('doc', 'updateOrder') ? ' sortDoc' : ''; + $treeMenu[$module->id] .= 'id>"; if($currentMethod == 'tablecontents') { @@ -2486,11 +2491,13 @@ EOT; if($currentMethod == 'objectlibs') { - $treeMenu[$module->id] .= "
" . html::a(inlink('objectLibs', "type=$type&objectID=$objectID&libID=$libID&docID={$doc->id}"), "  " . $doc->title, '', "data-app='{$this->app->tab}' class='doc-title' title='{$doc->title}'") . ''; - if(common::hasPriv('doc', 'edit')) + $class = common::hasPriv('doc', 'updateOrder') ? 'sortDoc' : ''; + $treeMenu[$module->id] .= "
" . html::a(inlink('objectLibs', "type=$type&objectID=$objectID&libID=$libID&docID={$doc->id}"), "  " . $doc->title, '', "data-app='{$this->app->tab}' class='doc-title $class' title='{$doc->title}'") . ''; + if(common::hasPriv('doc', 'edit') or common::hasPriv('doc', 'updateOrder')) { $treeMenu[$module->id] .= "
"; - $treeMenu[$module->id] .= html::a(helper::createLink('doc', 'edit', "docID={$doc->id}&comment=false&objectType=$type&objectID=$objectID&libID=$libID"), "", '', "title={$this->lang->doc->edit} data-app={$this->app->tab}"); + if(common::hasPriv('doc', 'edit')) $treeMenu[$module->id] .= html::a(helper::createLink('doc', 'edit', "docID={$doc->id}&comment=false&objectType=$type&objectID=$objectID&libID=$libID"), "", '', "title={$this->lang->doc->edit} data-app={$this->app->tab}"); + if(common::hasPriv('doc', 'updateOrder')) $treeMenu[$module->id] .= html::a('javascript:;', "", '', "title='{$this->lang->doc->updateOrder}' class='sortDoc'"); $treeMenu[$module->id] .= '
'; } $treeMenu[$module->id] .= '
'; @@ -2518,11 +2525,12 @@ EOT; else { $li = "
" . $module->name . ''; - if(common::hasPriv('tree', 'edit') or common::hasPriv('tree', 'browse')) + if(common::hasPriv('tree', 'edit') or common::hasPriv('tree', 'browse') or common::hasPriv('tree', 'updateOrder')) { $li .= "
"; - if(common::hasPriv('tree', 'edit')) $li .= html::a(helper::createLink('tree', 'edit', "module=$module->id&type=doc"), "", '', "data-toggle='modal' title={$this->lang->doc->editType}"); - if(common::hasPriv('tree', 'browse')) $li .= html::a(helper::createLink('tree', 'browse', "rootID=$libID&type=doc&module=$module->id", '', 1), "", '', "class='iframe' title={$this->lang->doc->editChildType}"); + if(common::hasPriv('tree', 'edit')) $li .= html::a(helper::createLink('tree', 'edit', "module=$module->id&type=doc"), "", '', "data-toggle='modal' title='{$this->lang->doc->editType}'"); + if(common::hasPriv('tree', 'browse')) $li .= html::a(helper::createLink('tree', 'browse', "rootID=$libID&type=doc&module=$module->id", '', 1), "", '', "class='iframe' title='{$this->lang->doc->editChildType}'"); + if(common::hasPriv('tree', 'updateOrder')) $li .= html::a('javascript:;', "", '', "title='{$this->lang->doc->updateOrder}' class='sortModule'"); $li .= '
'; } $li .= '
'; diff --git a/module/doc/view/side.html.php b/module/doc/view/side.html.php index 32cbbc41b9..701393f393 100644 --- a/module/doc/view/side.html.php +++ b/module/doc/view/side.html.php @@ -79,7 +79,7 @@ $sideWidth = common::checkNotCN() ? '270' : '238'; /* Make modules tree sortable */ $('#modules').sortable( { - trigger: '.module-name>a.sort-module', + trigger: '.module-name>a.sort-module, .tree-actions>.sortModule>.icon-move, .module-name>a.sortDoc, .tree-actions>.sortDoc>.icon-move', dropToClass: 'sort-to', stopPropagation: true, nested: true, @@ -100,7 +100,15 @@ $sideWidth = common::checkNotCN() ? '270' : '238'; { if($('#modules').hasClass('sortable-sorting')) $ul.addClass('is-sorting'); }, 100); - return $ul.children('li'); + + if($ele.hasClass('sortDoc')) + { + return $ul.children('li.sortDoc'); + } + else + { + return $ul.children('li.catalog'); + } }, always: function() { @@ -110,16 +118,34 @@ $sideWidth = common::checkNotCN() ? '270' : '238'; { if(!e.changed) return; - var orders = {}; - $('#modules').find('li.can-sort').each(function() + var orders = {}; + var link = ''; + var elementClass = e.list.context.className; + if(elementClass.indexOf('sortDoc') >= 0) { - var $li = $(this); + $('#modules').find('li.sortDoc').each(function() + { + var $li = $(this); - var item = $li.data(); - '' == 'book' ? orders['sort[' + item.id + ']'] = $li.attr('data-order') || item.order : orders['orders[' + item.id + ']'] = $li.attr('data-order') || item.order; - }); + var item = $li.data(); + orders['orders[' + item.id + ']'] = $li.attr('data-order') || item.order; + }); + + link = createLink('doc', 'updateOrder'); + } + else + { + $('#modules').find('li.can-sort').each(function() + { + var $li = $(this); + + var item = $li.data(); + '' == 'book' ? orders['sort[' + item.id + ']'] = $li.attr('data-order') || item.order : orders['orders[' + item.id + ']'] = $li.attr('data-order') || item.order; + }); + + link = '' == 'book' ? createLink('doc', 'sortBookOrder') : createLink('tree', 'updateOrder'); + } - var link = '' == 'book' ? createLink('doc', 'sortBookOrder') : createLink('tree', 'updateOrder'); $.post(link, orders, function(data){}).error(function() { bootbox.alert(lang.timeout); diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index 60aa69d0a4..9e7c18a9bd 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -1215,6 +1215,7 @@ $lang->resource->doc->objectLibs = 'objectLibs'; $lang->resource->doc->collect = 'collectAction'; $lang->resource->doc->tableContents = 'tableContents'; $lang->resource->doc->showFiles = 'showFiles'; +$lang->resource->doc->updateOrder = 'updateOrder'; $lang->doc->methodOrder[0] = 'index'; $lang->doc->methodOrder[5] = 'browse'; From e316483175dc7a4d4d65cdceae7ddd2838727abb Mon Sep 17 00:00:00 2001 From: tianshujie Date: Wed, 11 May 2022 14:13:30 +0800 Subject: [PATCH 2/3] * Finish task #53831. --- module/doc/css/tablecontents.css | 18 ++++++++ module/doc/js/tablecontents.js | 77 ++++++++++++++++++++++++++++++++ module/doc/model.php | 25 ++++++++--- 3 files changed, 114 insertions(+), 6 deletions(-) diff --git a/module/doc/css/tablecontents.css b/module/doc/css/tablecontents.css index a864562332..9cd6f9101e 100644 --- a/module/doc/css/tablecontents.css +++ b/module/doc/css/tablecontents.css @@ -20,3 +20,21 @@ span.dotted-line+a {display: block;} .tree li.has-list.open:before {content: unset;} #modules i.icon-file-text {color: #D0D2D6; font-size: 14px;} .tree li>a {max-width: 80%;} + +.sortable-sorting .module-name > a {cursor: move;} +.sortable-sorting li >.tree-group {opacity: .5;} +.sortable-sorting .drop-here .tree-group {background-color: #fff3e0;} +.sortable-sorting .drop-here .tree-group > * {opacity: .1;} +.sortable-sorting .drag-shadow .tree-group {opacity: 1!important;} +.sortable-sorting .drag-shadow .tree-actions {visibility: hidden;} +.is-sorting > li > .tree-group {opacity: 1; border-radius: 4px;} +.is-sorting > li ul {display: none!important;} + +.tree-group {position: relative;} +.tree-group > .module-name {white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; display: block;} +.tree-group .tree-actions {display: none; position: absolute; right: 0; top: 0; background-color: #fff; white-space: nowrap;} +.tree-group:hover > .module-name {width: calc(100% - 20px);} +.tree-group:hover .tree-actions {display: block} +.tree li.has-list.open:before {left: 6px;} +.sortDoc>.tail-info{right: 20px;} +.sortDoc>.tree-actions{position: absolute; right: 0px; background: #fff;} diff --git a/module/doc/js/tablecontents.js b/module/doc/js/tablecontents.js index a3e3e75859..15891830ea 100644 --- a/module/doc/js/tablecontents.js +++ b/module/doc/js/tablecontents.js @@ -18,4 +18,81 @@ $(function() }) $('.menu-actions > a').blur(function() {$(this).css('background', 'none');}) + + /* Make modules tree sortable. */ + $('#modules').sortable( + { + trigger: '.module-name>a.sort-module, .tree-actions>.sortModule>.icon-move, .module-name>a.sortDoc, .tree-actions>.sortDoc>.icon-move', + dropToClass: 'sort-to', + stopPropagation: true, + nested: true, + selector: 'li', + dragCssClass: 'drop-here', + canMoveHere: function($ele, $target) + { + var maxTop = $('.side-col > .cell > ul').height() - $ele.height(); + if(parseFloat($('.drag-shadow').css('top')) < 0) $('.drag-shadow').css('top', '0'); + if(parseFloat($('.drag-shadow').css('left')) != 0) $('.drag-shadow').css('left', '0'); + if(parseFloat($('.drag-shadow').css('top')) > maxTop) $('.drag-shadow').css('top', maxTop + 'px'); + return true; + }, + targetSelector: function($ele, $root) + { + var $ul = $ele.closest('ul'); + setTimeout(function() + { + if($('#modules').hasClass('sortable-sorting')) $ul.addClass('is-sorting'); + }, 100); + + if($ele.hasClass('sortDoc')) + { + return $ul.children('li.sortDoc'); + } + else + { + return $ul.children('li.catalog'); + } + }, + always: function() + { + $('#modules,#modules .is-sorting').removeClass('is-sorting'); + }, + finish: function(e) + { + if(!e.changed) return; + + var orders = {}; + var link = ''; + var elementClass = e.list.context.className; + if(elementClass.indexOf('sortDoc') >= 0) + { + $('#modules').find('li.sortDoc').each(function() + { + var $li = $(this); + + var item = $li.data(); + orders['orders[' + item.id + ']'] = $li.attr('data-order') || item.order; + }); + + link = createLink('doc', 'updateOrder'); + } + else + { + $('#modules').find('li.can-sort').each(function() + { + var $li = $(this); + + var item = $li.data(); + '' == 'book' ? orders['sort[' + item.id + ']'] = $li.attr('data-order') || item.order : orders['orders[' + item.id + ']'] = $li.attr('data-order') || item.order; + }); + + link = createLink('tree', 'updateOrder'); + } + + $.post(link, orders, function(data){}).error(function() + { + bootbox.alert(lang.timeout); + }); + } + }); }) diff --git a/module/doc/model.php b/module/doc/model.php index a94dae1220..8c86a191c6 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -2486,7 +2486,13 @@ EOT; if($currentMethod == 'tablecontents') { - $treeMenu[$module->id] .= '' . zget($users, $doc->editedBy) . '  ' . $doc->editedDate . ''; + $treeMenu[$module->id] .= '
' . zget($users, $doc->editedBy) . '  ' . $doc->editedDate . ''; + if(common::hasPriv('doc', 'updateOrder')) + { + $treeMenu[$module->id] .= "
"; + $treeMenu[$module->id] .= html::a('javascript:;', "", '', "title='{$this->lang->doc->updateOrder}' class='sortDoc'"); + $treeMenu[$module->id] .= '
'; + } } if($currentMethod == 'objectlibs') @@ -2504,7 +2510,9 @@ EOT; } elseif($currentMethod == 'tablecontents') { - $treeMenu[$module->id] .= html::a(inlink('objectLibs', "type=$type&objectID=$objectID&libID=$libID&docID={$doc->id}"), "  " . $doc->title, '', "data-app='{$this->app->tab}' class='doc-title' title='{$doc->title}'"); + $class = common::hasPriv('doc', 'updateOrder') ? 'sortDoc' : ''; + $treeMenu[$module->id] .= html::a(inlink('objectLibs', "type=$type&objectID=$objectID&libID=$libID&docID={$doc->id}"), "  " . $doc->title, '', "data-app='{$this->app->tab}' class='doc-title $class' title='{$doc->title}'"); + $treeMenu[$module->id] .= '
'; } $treeMenu[$module->id] .= ''; @@ -2518,14 +2526,19 @@ EOT; } else { + $li = "
" . $module->name . ''; if($currentMethod == 'tablecontents') { - $li = "" . $module->name . ''; + if(common::hasPriv('tree', 'updateOrder')) + { + $li .= "
"; + $li .= html::a('javascript:;', "", '', "title='{$this->lang->doc->updateOrder}' class='sortModule'"); + $li .= '
'; + } } else { - $li = "
" . $module->name . ''; - if(common::hasPriv('tree', 'edit') or common::hasPriv('tree', 'browse') or common::hasPriv('tree', 'updateOrder')) + if(common::hasPriv('tree', 'edit') or common::hasPriv('tree', 'browse') or common::hasPriv('tree', 'browse') or common::hasPriv('tree', 'updateOrder')) { $li .= "
"; if(common::hasPriv('tree', 'edit')) $li .= html::a(helper::createLink('tree', 'edit', "module=$module->id&type=doc"), "", '', "data-toggle='modal' title='{$this->lang->doc->editType}'"); @@ -2533,8 +2546,8 @@ EOT; if(common::hasPriv('tree', 'updateOrder')) $li .= html::a('javascript:;', "", '', "title='{$this->lang->doc->updateOrder}' class='sortModule'"); $li .= '
'; } - $li .= '
'; } + $li .= '
'; } if($treeMenu[$module->id]) { From 2bdfa7449d4b2b3752f0ad41efdbac2f520237ac Mon Sep 17 00:00:00 2001 From: tianshujie Date: Wed, 11 May 2022 14:44:16 +0800 Subject: [PATCH 3/3] * Finish task #53831. --- module/doc/js/tablecontents.js | 2 +- module/doc/model.php | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/module/doc/js/tablecontents.js b/module/doc/js/tablecontents.js index 15891830ea..d11c77d92a 100644 --- a/module/doc/js/tablecontents.js +++ b/module/doc/js/tablecontents.js @@ -22,7 +22,7 @@ $(function() /* Make modules tree sortable. */ $('#modules').sortable( { - trigger: '.module-name>a.sort-module, .tree-actions>.sortModule>.icon-move, .module-name>a.sortDoc, .tree-actions>.sortDoc>.icon-move', + trigger: '.module-name>a.sort-module, .tree-actions>.sortModule>.icon-move, a.sortDoc, .tree-actions>.sortDoc>.icon-move', dropToClass: 'sort-to', stopPropagation: true, nested: true, diff --git a/module/doc/model.php b/module/doc/model.php index 8c86a191c6..87f9a94b0c 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -2416,7 +2416,13 @@ EOT; if($currentMethod == 'tablecontents') { - $treeMenu[0] .= '' . zget($users, $doc->editedBy) . '  ' . $doc->editedDate . ''; + $treeMenu[0] .= '
' . zget($users, $doc->editedBy) . '  ' . $doc->editedDate . ''; + if(common::hasPriv('doc', 'updateOrder')) + { + $treeMenu[0] .= "
"; + $treeMenu[0] .= html::a('javascript:;', "", '', "title='{$this->lang->doc->updateOrder}' class='sortDoc'"); + $treeMenu[0] .= '
'; + } } if($currentMethod == 'objectlibs') { @@ -2432,7 +2438,9 @@ EOT; } else { - $treeMenu[0] .= html::a(inlink('objectLibs', "type=$type&objectID=$objectID&libID=$rootID&docID={$doc->id}"), "  " . $doc->title, '', "data-app='{$this->app->tab}' class='doc-title' title='{$doc->title}'"); + $class = common::hasPriv('doc', 'updateOrder') ? 'sortDoc' : ''; + $treeMenu[0] .= html::a(inlink('objectLibs', "type=$type&objectID=$objectID&libID=$rootID&docID={$doc->id}"), "  " . $doc->title, '', "data-app='{$this->app->tab}' class='doc-title $class' title='{$doc->title}'"); + $treeMenu[0] .= '
'; } $treeMenu[0] .= ''; @@ -2527,14 +2535,11 @@ EOT; else { $li = "
" . $module->name . ''; - if($currentMethod == 'tablecontents') + if($currentMethod == 'tablecontents' and common::hasPriv('tree', 'updateOrder')) { - if(common::hasPriv('tree', 'updateOrder')) - { - $li .= "
"; - $li .= html::a('javascript:;', "", '', "title='{$this->lang->doc->updateOrder}' class='sortModule'"); - $li .= '
'; - } + $li .= "
"; + $li .= html::a('javascript:;', "", '', "title='{$this->lang->doc->updateOrder}' class='sortModule'"); + $li .= '
'; } else {