From 914152606211fd84206e247db51aafc17a403670 Mon Sep 17 00:00:00 2001 From: Erik Amaru Ortiz Date: Thu, 1 Aug 2013 19:06:05 -0400 Subject: [PATCH] FEATURE, was added a feature to enable load three level nodes on cases tree menu on HOME tab Now we can set from any menu file (core or plugin) a three level nodes on cases menu: Example: $G_TMP_MENU->AddIdRawOption('TEST1', '#', 'Enterprise Search', '', '', 'blockHeader'); $G_TMP_MENU->AddIdRawOption('TEST2', '#', 'New Seach', '', ''); $G_TMP_MENU->AddIdRawOption('TEST3', '#', 'Saved Searches (9)', '', ''); $G_TMP_MENU->AddIdRawOption('TEST4', '#', 'Favorites', '', '', 'rootNode'); $G_TMP_MENU->AddIdRawOption('TEST5', '#', 'test child 2.1', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST6', '#', 'test child 2.2', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST7', '#', 'test child 2.3', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST8', '#', 'test child 3', '', '', ''); $G_TMP_MENU->AddIdRawOption('TEST9', '#', 'test child 4', '', '', ''); On the last parameter was added two new menu types "rootNode" and "childNode" On the example the first node will be set by "blockHeader" menu type all menu options below that will be added such as its child nodes Now, if a menu option has a type "rootNode" (...'Favorites', '', '', 'rootNode'...) all menu options below this with type "childNode" (...'test child 2.2', '', '', 'childNode'...) will be consireded as its child nodes of menu with type "rootNode", inmediatly a menu option without any menu type is found (..'test child 3', '', '', ''..), this menu and all menu options like it will be added as child nodes of the last menu option with "blockHeader". The result of the example will be something like this: + Enterprise Search - New search - Saved Searches (9) + Favorites - test child 2.1 - test child 2.2 - test child 2.3 - test child 3 - test child 4 ... --- .../engine/methods/cases/casesMenuLoader.php | 59 ++++++++++++++++++- workflow/engine/templates/cases/main.js | 2 +- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/workflow/engine/methods/cases/casesMenuLoader.php b/workflow/engine/methods/cases/casesMenuLoader.php index 5c0656efd..4ee168108 100755 --- a/workflow/engine/methods/cases/casesMenuLoader.php +++ b/workflow/engine/methods/cases/casesMenuLoader.php @@ -43,7 +43,7 @@ function getLoadTreeMenuData () //now drawing the treeview using the menu options from menu/cases.php $menuCases = array (); - foreach ($oMenu->Options as $i => $option) { + for ($i = 0; $i < count($oMenu->Options); $i++) { if ($oMenu->Types[$i] == 'blockHeader') { $CurrentBlockID = $oMenu->Id[$i]; $menuCases[$CurrentBlockID]['blockTitle'] = $oMenu->Labels[$i]; @@ -60,8 +60,25 @@ function getLoadTreeMenuData () $menuCases[$CurrentBlockID]['blockTitle'] = $oMenu->Labels[$i]; $menuCases[$CurrentBlockID]['blockType'] = $oMenu->Types[$i]; $menuCases[$CurrentBlockID]['link'] = $oMenu->Options[$i]; + } elseif ($oMenu->Types[$i] == 'rootNode') { + $menuCases[$CurrentBlockID]['blockItems'][$oMenu->Id[$i]] = array ( + 'label' => $oMenu->Labels[$i], + 'link' => $oMenu->Options[$i], + 'icon' => (isset($oMenu->Icons[$i]) && $oMenu->Icons[$i] != '') ? $oMenu->Icons[$i] : 'kcmdf.png' + ); + + $index = $i; + list($childs, $index) = getChilds($oMenu, ++$index); + + $menuCases[$CurrentBlockID]['blockItems'][$oMenu->Id[$i]]['childs'] = $childs; + + $i = $index; } else { - $menuCases[$CurrentBlockID]['blockItems'][$oMenu->Id[$i]] = Array ('label' => $oMenu->Labels[$i],'link' => $oMenu->Options[$i],'icon' => (isset( $oMenu->Icons[$i] ) && $oMenu->Icons[$i] != '') ? $oMenu->Icons[$i] : 'kcmdf.png'); + $menuCases[$CurrentBlockID]['blockItems'][$oMenu->Id[$i]] = array ( + 'label' => $oMenu->Labels[$i], + 'link' => $oMenu->Options[$i], + 'icon' => (isset($oMenu->Icons[$i]) && $oMenu->Icons[$i] != '') ? $oMenu->Icons[$i] : 'kcmdf.png' + ); if (isset( $aTypesID[$oMenu->Id[$i]] )) { $menuCases[$CurrentBlockID]['blockItems'][$oMenu->Id[$i]]['cases_count'] = $aCount[$aTypesID[$oMenu->Id[$i]]]['count']; @@ -106,6 +123,23 @@ function getLoadTreeMenuData () // adding "menu_block" childs nodes foreach ($menuBlock['blockItems'] as $id => $menu) { + if (! empty($menu['childs'])) { + $rootNode = $menuBlockNode->addChild('menu_block'); + $rootNode->addAttribute('id', $id); + $rootNode->addAttribute('title', $menu['label']); + $rootNode->addAttribute('url', $menu['link']); + $rootNode->addAttribute('expanded', true); + + foreach ($menu['childs'] as $id => $child) { + $childNode = $rootNode->addChild('option'); + $childNode->addAttribute('id', $id); + $childNode->addAttribute('title', $child['label']); + $childNode->addAttribute('url', $child['link']); + } + + continue; + } + $option = $menuBlockNode->addChild('option'); $option->addAttribute('id', $id); $option->addAttribute('title', $menu['label']); @@ -275,3 +309,24 @@ function getAllCounters () echo G::json_encode( $response ); } +function getChilds($menu, $index) +{ + $childs = array(); + + for ($i = $index; $i < count($menu->Options); $i++) { + if ($menu->Types[$i] == 'childNode') { + + $childs[$menu->Id[$i]] = array( + 'label' => $menu->Labels[$i], + 'link' => $menu->Options[$i], + 'icon' => '' + ); + } else { + //TODO we can add more recursive logic here to enable more childs levels + break; + } + } + + return array($childs, --$i); +} + diff --git a/workflow/engine/templates/cases/main.js b/workflow/engine/templates/cases/main.js index 6c02ea9d8..1bd2294d5 100755 --- a/workflow/engine/templates/cases/main.js +++ b/workflow/engine/templates/cases/main.js @@ -726,7 +726,7 @@ Ext.app.menuLoader = Ext.extend(Ext.ux.tree.XmlTreeLoader, { attr.iconCls = 'ICON_' + attr.id; attr.loaded = true; - attr.expanded = false; + attr.expanded = attr.expanded ? true : false; } else if(attr.PRO_UID){ attr.loaded = true;