From eef7c3ddba79a106dac369b4bcf006b57cf750a2 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Thu, 9 Jan 2014 21:00:23 +0530 Subject: [PATCH 1/2] Rewrite simply and generalize table/view part and fix bug#4219 Signed-off-by: Atul Pratap Singh --- js/navigation.js | 75 +++++++++++++++---- .../Nodes/Node_Table_Container.class.php | 2 +- .../Nodes/Node_View_Container.class.php | 2 +- 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/js/navigation.js b/js/navigation.js index 23479ce850..f66bc4008e 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -467,34 +467,77 @@ function PMA_showCurrentNavigation() function loadAndHighlightTableOrView($dbItem, table) { var $container = $dbItem.children('div.list_container'); - var $tableContainer = $container - .children('ul') - .children('li.tableContainer'); - var $viewContainer = $container - .children('ul') - .children('li.viewContainer'); - - if ($tableContainer.length > 0) { - highlightTableOrView($tableContainer, table, 'table'); - } else if ($viewContainer.length > 0) { - highlightTableOrView($viewContainer, table, 'view'); + var $expander; + var $whichItem = isItemInContainer($container, table, 'li.table, li.view'); + //If item already there in some container + if ($whichItem) { + //get the relevant container while may also be a subcontainer + var $relatedContainer = $whichItem.closest('li.subContainer').length + ? $whichItem.closest('li.subContainer') + : $dbItem; + $whichItem = findLoadedItem( + $relatedContainer.children('div.list_container'), + table, null, true + ); + //Show directly + showTableOrView($whichItem, $relatedContainer.children('div:first').children('a.expander')); + //else if item not there, try loading once } else { - // no containers, highlight the item - highlightTableOrView($dbItem, table, null); + var $sub_containers = $dbItem.find('.subContainer'); + //If there are subContainers i.e. tableContainer or viewContainer + if($sub_containers.length > 0) { + var $containers = new Array(); + $sub_containers.each(function (index) { + $containers[index] = $(this); + $expander = $containers[index] + .children('div:first') + .children('a.expander'); + collapseTreeNode($expander); + loadAndShowTableOrView($expander, $containers[index], table); + }); + // else if no subContainers + } else { + $expander = $dbItem + .children('div:first') + .children('a.expander'); + collapseTreeNode($expander); + loadAndShowTableOrView($expander, $dbItem, table); + } } } + function loadAndShowTableOrView($expander, $relatedContainer, table) { + loadChildNodes($expander, function (data) { + var $whichItem = findLoadedItem( + $relatedContainer.children('div.list_container'), + table, null, true + ); + if ($whichItem) { + showTableOrView($whichItem, $expander); + } + }); + } + + function showTableOrView($whichItem, $expander) { + expandTreeNode($expander, function (data) { + if ($whichItem) { + scrollToView($whichItem, false); + } + }); + } + function isItemInContainer($container, name, clazz) { - $items = $container.find('li.' + clazz); + var $whichItem = null; + $items = $container.find(clazz); var found = false; $items.each(function () { if ($(this).children('a').text() == name) { - found = true; + $whichItem = $(this); return false; } }); - return found; + return $whichItem; } function highlightTableOrView($container, item, clazz) { diff --git a/libraries/navigation/Nodes/Node_Table_Container.class.php b/libraries/navigation/Nodes/Node_Table_Container.class.php index 7a4ece3d18..4c4ef20e09 100644 --- a/libraries/navigation/Nodes/Node_Table_Container.class.php +++ b/libraries/navigation/Nodes/Node_Table_Container.class.php @@ -40,7 +40,7 @@ class Node_Table_Container extends Node ); } $this->real_name = 'tables'; - $this->classes = 'tableContainer'; + $this->classes = 'tableContainer subContainer'; $new_label = _pgettext('Create new table', 'New'); $new = PMA_NodeFactory::getInstance('Node', $new_label); diff --git a/libraries/navigation/Nodes/Node_View_Container.class.php b/libraries/navigation/Nodes/Node_View_Container.class.php index 6eb26d4f8b..775c5500c3 100644 --- a/libraries/navigation/Nodes/Node_View_Container.class.php +++ b/libraries/navigation/Nodes/Node_View_Container.class.php @@ -39,7 +39,7 @@ class Node_View_Container extends Node $GLOBALS['cfg']['NavigationTreeTableLevel'] ); } - $this->classes = 'viewContainer'; + $this->classes = 'viewContainer subContainer'; $this->real_name = 'views'; $new_label = _pgettext('Create new view', 'New'); From 0577539109711aea474efcf35449edad8fafc1d8 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Thu, 9 Jan 2014 21:01:19 +0530 Subject: [PATCH 2/2] Remove redundant function and rename variable: auto-expand table/view Signed-off-by: Atul Pratap Singh --- js/navigation.js | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/js/navigation.js b/js/navigation.js index f66bc4008e..dcaca295c3 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -465,10 +465,10 @@ function PMA_showCurrentNavigation() return ret; } - function loadAndHighlightTableOrView($dbItem, table) { + function loadAndHighlightTableOrView($dbItem, itemName) { var $container = $dbItem.children('div.list_container'); var $expander; - var $whichItem = isItemInContainer($container, table, 'li.table, li.view'); + var $whichItem = isItemInContainer($container, itemName, 'li.table, li.view'); //If item already there in some container if ($whichItem) { //get the relevant container while may also be a subcontainer @@ -477,7 +477,7 @@ function PMA_showCurrentNavigation() : $dbItem; $whichItem = findLoadedItem( $relatedContainer.children('div.list_container'), - table, null, true + itemName, null, true ); //Show directly showTableOrView($whichItem, $relatedContainer.children('div:first').children('a.expander')); @@ -493,7 +493,7 @@ function PMA_showCurrentNavigation() .children('div:first') .children('a.expander'); collapseTreeNode($expander); - loadAndShowTableOrView($expander, $containers[index], table); + loadAndShowTableOrView($expander, $containers[index], itemName); }); // else if no subContainers } else { @@ -501,16 +501,16 @@ function PMA_showCurrentNavigation() .children('div:first') .children('a.expander'); collapseTreeNode($expander); - loadAndShowTableOrView($expander, $dbItem, table); + loadAndShowTableOrView($expander, $dbItem, itemName); } } } - function loadAndShowTableOrView($expander, $relatedContainer, table) { + function loadAndShowTableOrView($expander, $relatedContainer, itemName) { loadChildNodes($expander, function (data) { var $whichItem = findLoadedItem( $relatedContainer.children('div.list_container'), - table, null, true + itemName, null, true ); if ($whichItem) { showTableOrView($whichItem, $expander); @@ -539,33 +539,6 @@ function PMA_showCurrentNavigation() }); return $whichItem; } - - function highlightTableOrView($container, item, clazz) { - var $expander = $container - .children('div:first') - .children('a.expander'); - if (! $expander.hasClass('loaded') || - $expander.find('img').is('.ic_b_plus') - ) { - expandTreeNode($expander, function () { - var $item = findLoadedItem( - $container.children('div.list_container'), - item, clazz, true - ); - if ($item) { - scrollToView($item, false); - } - }); - } else { - var $item = findLoadedItem( - $container.children('div.list_container'), - item, clazz, true - ); - if ($item) { - scrollToView($item, false); - } - } - } } /**