From face85a0c81f5ec561663665130c881cf5b084ac Mon Sep 17 00:00:00 2001 From: sunhao Date: Tue, 26 Sep 2023 15:10:52 +0800 Subject: [PATCH] + zin: add treeEditor widget. --- lib/zin/wg/treeeditor/v1.php | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 lib/zin/wg/treeeditor/v1.php diff --git a/lib/zin/wg/treeeditor/v1.php b/lib/zin/wg/treeeditor/v1.php new file mode 100644 index 0000000000..4dcfb391ba --- /dev/null +++ b/lib/zin/wg/treeeditor/v1.php @@ -0,0 +1,76 @@ +setProp('items', $this->buildTree($this->prop('items'))); + $treeProps = $this->props->pick(array('items', 'activeClass', 'activeIcon', 'activeKey', 'onClickItem', 'defaultNestedShow', 'changeActiveKey', 'isDropdownMenu', 'collapsedIcon', 'expandedIcon', 'normalIcon', 'id', 'itemActions', 'hover', 'onClick')); + return zui::tree + ( + set::_tag('ul'), + set($treeProps) + ); + } + + private function buildTree(array $items): array + { + $canUpdateOrder = $this->prop('canUpdateOrder'); + $canEdit = $this->prop('canEdit'); + $canDelete = $this->prop('canDelete'); + $canSplit = $this->prop('canSplit'); + $editType = $this->prop('type'); + + foreach($items as $key => $item) + { + $item = (array)$item; + if(!isset($item['content'])) + { + if(!isset($item['text'])) $item['text'] = $item['name']; + if(!isset($item['url'])) $item['url'] = ''; + + if(isset($item['type']) && $item['type'] == 'product') + { + $item['icon'] = 'product'; + } + else + { + $item['actions'] = array(); + $item['actions']['items'] = array(); + + if($canEdit) $item['actions']['items'][] = array('key' => 'edit', 'icon' => 'edit', 'id' => $item['id'], 'editType' => $editType, 'onClick' => jsRaw('(event, item) => window.editItem(item)')); + if($canDelete) $item['actions']['items'][] = array('key' => 'delete', 'icon' => 'trash', 'id' => $item['id'], 'className' => 'btn ghost toolbar-item square size-sm rounded ajax-submit','url' => helper::createLink('tree', 'delete', 'module=' . $item['id'])); + if($canSplit) $item['actions']['items'][] = array('key' => 'view', 'icon' => 'split', 'url' => $item['url']); + } + } + + if(!empty($item['children'])) + { + $item['items'] = $this->buildTree($item['children']); + unset($item['children']); + } + $items[$key] = $item; + } + + return $items; + } +}