From 2f15304a76b29fa603511725e4b0133ebcc54529 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 25 Jul 2023 09:44:15 +0800 Subject: [PATCH] + Zin: Add module function. --- lib/zin/wg/docmenu/css/v1.css | 6 ++-- lib/zin/wg/docmenu/js/v1.js | 59 +++++++++++++++++++++++++++++++++++ lib/zin/wg/docmenu/v1.php | 51 ++++++++++++++++-------------- 3 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 lib/zin/wg/docmenu/js/v1.js diff --git a/lib/zin/wg/docmenu/css/v1.css b/lib/zin/wg/docmenu/css/v1.css index 000e1f4030..d6d174f991 100644 --- a/lib/zin/wg/docmenu/css/v1.css +++ b/lib/zin/wg/docmenu/css/v1.css @@ -7,8 +7,10 @@ #docDropmenu .is-leading {display: none;} #docDropmenu .primary {--tw-ring-color: var(--btn-border-color); background-color: var(--btn-bg); color: inherit; width: 100%;} -.module-menu .tree .tree-link {text-overflow: clip; overflow: hidden; flex: 1 1 auto;} -.module-menu .tree .tree-actions {margin-left: 0;} +.module-menu .tree .tree-item .tree-link {text-overflow: clip; overflow: hidden; flex: 1 10 auto;} +.module-menu .tree .tree-item .tree-actions {margin-left: 0;} +.module-menu .tree .tree-item .tree-actions .icon {display: none;} +.module-menu .tree .tree-item .tree-item-content:hover .tree-actions .icon {display: block;} .tree > .tree-item > .project-tree-title {font-size: 16px; margin-bottom: 0.5rem;} .tree > .tree-item > .project-tree-title .text {margin-left: 0.5rem;} diff --git a/lib/zin/wg/docmenu/js/v1.js b/lib/zin/wg/docmenu/js/v1.js new file mode 100644 index 0000000000..44c403ac99 --- /dev/null +++ b/lib/zin/wg/docmenu/js/v1.js @@ -0,0 +1,59 @@ +window.saveModule = function() +{ + const name = $(this).val(); + if(!name) return $(this).closest('.tree-item').remove(); + + const {id, type, lib, module} = $(this).data(); + const parentID = $(this).data('parent'); + + const $element = $(`div[data-id='${id}']`); + $.ajaxSubmit({ + url: $.createLink('tree', 'ajaxCreateModule'), + data: { + name : name, + libID : lib, + parentID : parentID, + objectID : id, + moduleType : module, + isUpdate : false, + createType : type, + } + }); +} + +window.addModule = function(id, addType) +{ + const $element = $(`div[data-id='${id}']`); + const {lib, type, module} = $element.data(); + + const parentID = ['docLib'].includes(type) ? '0' : $element.data('parent'); + const level = addType == 'same' ? $element.data('level') : $element.data('level') + 1; + const style = `style="margin-left: calc(${level} * var(--tree-indent, 20px))"`; + + let inputTpl = '
  • '; + inputTpl += `
    `; + inputTpl += ``; + inputTpl += '
  • '; + + if(addType == 'same') + { + $(`div[data-id='${id}']`).before(inputTpl); + } + else + { + if(!$element.parent().hasClass('show')) $element.find('.tree-toggle-icon').trigger('click'); + + setTimeout(function() + { + $(`div[data-id='${id}']`).next('.tree').prepend(inputTpl); + }, 1); + } + + setTimeout(function() + { + $('#moduleName').trigger('focus'); + document.getElementById("moduleName").addEventListener('blur', saveModule); + }, 1); +} diff --git a/lib/zin/wg/docmenu/v1.php b/lib/zin/wg/docmenu/v1.php index 23446c5dfd..217cf1b571 100644 --- a/lib/zin/wg/docmenu/v1.php +++ b/lib/zin/wg/docmenu/v1.php @@ -99,12 +99,17 @@ class docMenu extends wg $setting->parentID = $parentID; $item = array( - 'key' => $setting->id, - 'text' => $setting->name, - 'icon' => $this->getIcon($setting), - 'url' => $this->buildLink($setting), - 'active' => zget($setting, 'active', $setting->id == $activeKey), - 'actions' => $this->getActions($setting) + 'key' => $setting->id, + 'text' => $setting->name, + 'icon' => $this->getIcon($setting), + 'url' => $this->buildLink($setting), + 'data-id' => $setting->id, + 'data-lib' => $setting->type == 'docLib' ? $setting->id : $setting->libID, + 'data-type' => $setting->type, + 'data-parent' => $setting->parentID, + 'data-module' => $this->currentModule, + 'active' => zget($setting, 'active', $setting->id == $activeKey), + 'actions' => $this->getActions($setting) ); $children = zget($setting, 'children', array()); @@ -164,8 +169,8 @@ class docMenu extends wg $treeIcon = 'paper-clip'; } $items[] = array( - 'text' => $treeTitle, - 'icon' => $treeIcon, + 'text' => $treeTitle, + 'icon' => $treeIcon, 'class' => 'project-tree-title ' . ($index > 0 ? 'border-t mt-2 pt-2' : ''), ); @@ -206,19 +211,19 @@ class docMenu extends wg if(hasPriv($this->currentModule, 'addCatalog')) { $menus[] = array( - 'key' => 'adddirectory', - 'icon' => 'add-directory', - 'text' => $this->lang->doc->libDropdown['addModule'], - 'link' => '', + 'key' => 'adddirectory', + 'icon' => 'add-directory', + 'text' => $this->lang->doc->libDropdown['addModule'], + 'onClick' => jsRaw("() => addModule({$item->parentID}, 'child')") ); } if(hasPriv($this->currentModule, 'editCatalog')) { $menus[] = array( - 'key' => 'editlib', - 'icon' => 'edit', - 'text' => $this->lang->doc->libDropdown['editLib'], + 'key' => 'editlib', + 'icon' => 'edit', + 'text' => $this->lang->doc->libDropdown['editLib'], 'data-toggle' => 'modal', 'data-url' => createlink($this->currentModule, 'editlib', "libid={$item->parentID}"), ); @@ -241,16 +246,16 @@ class docMenu extends wg if(hasPriv($this->currentModule, 'addCatalog')) { $menus[] = array( - 'key' => 'adddirectory', - 'icon' => 'add-directory', - 'text' => $this->lang->doc->libDropdown['addSameModule'], - 'link' => '', + 'key' => 'adddirectory', + 'icon' => 'add-directory', + 'text' => $this->lang->doc->libDropdown['addSameModule'], + 'onClick' => jsRaw("() => addModule({$item->id}, 'same')") ); $menus[] = array( - 'key' => 'addsubdirectory', - 'icon' => 'add-directory', - 'text' => $this->lang->doc->libDropdown['addSubModule'], - 'link' => '', + 'key' => 'addsubdirectory', + 'icon' => 'add-directory', + 'text' => $this->lang->doc->libDropdown['addSubModule'], + 'onClick' => jsRaw("() => addModule({$item->id}, 'child')") ); }