diff --git a/js/common.js b/js/common.js index c4f4bab7ef..0fe08b6328 100644 --- a/js/common.js +++ b/js/common.js @@ -41,6 +41,10 @@ var PMA_commonParams = (function () { if (params[i] !== undefined && params[i] !== obj[i]) { reload = true; } + // To expand the database in use and collapse the previous one + if(i == 'db' && obj[i] !== '') { + PMA_autoExpandDatabaseInUse(params['db'], obj[i]); + } params[i] = obj[i]; } if (reload) { @@ -71,6 +75,9 @@ var PMA_commonParams = (function () { PMA_querywindow.refresh(); PMA_reloadNavigation(); } + if(name == 'db' && value !== '') { + PMA_autoExpandDatabaseInUse(params['db'], value); + } params[name] = value; return this; }, @@ -108,6 +115,9 @@ var PMA_commonActions = { */ setDb: function (new_db) { if (new_db != PMA_commonParams.get('db')) { + if(new_db !== '') { + PMA_autoExpandDatabaseInUse(PMA_commonParams.get('db'), new_db); + } PMA_commonParams.set('db', new_db); PMA_querywindow.refresh(); } diff --git a/js/navigation.js b/js/navigation.js index 9198300a87..e0336ef042 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -29,63 +29,9 @@ $(function() { $('#pma_navigation_tree a.expander').live('click', function(event) { event.preventDefault(); event.stopImmediatePropagation(); - var $this = $(this); - var $children = $this.closest('li').children('div.list_container'); - var $icon = $this.find('img'); - if ($this.hasClass('loaded')) { - if ($icon.is('.ic_b_plus')) { - $icon.removeClass('ic_b_plus').addClass('ic_b_minus'); - $children.show('fast'); - } else { - $icon.removeClass('ic_b_minus').addClass('ic_b_plus'); - $children.hide('fast'); - } - } else { - var $destination = $this.closest('li'); - var $throbber = $('#pma_navigation .throbber') - .first() - .clone() - .css('visibility', 'visible'); - $icon.hide(); - $throbber.insertBefore($icon); - - var searchClause = PMA_fastFilter.getSearchClause(); - var searchClause2 = PMA_fastFilter.getSearchClause2($(this)); - - var params = { - aPath: $(this).find('span.aPath').text(), - vPath: $(this).find('span.vPath').text(), - pos: $(this).find('span.pos').text(), - pos2_name: $(this).find('span.pos2_name').text(), - pos2_value: $(this).find('span.pos2_value').text(), - searchClause: searchClause, - searchClause2: searchClause2 - }; - var url = $('#pma_navigation').find('a.navigation_url').attr('href'); - $.get(url, params, function (data) { - if (data.success === true) { - $this.addClass('loaded'); - $destination.find('div.list_container').remove(); // FIXME: Hack, there shouldn't be a list container there - $destination.append(data.message); - $icon.removeClass('ic_b_plus').addClass('ic_b_minus'); - $destination - .children('div.list_container') - .show('fast'); - if ($destination.find('ul > li').length == 1) { - $destination.find('ul > li') - .find('a.expander.container') - .click(); - } - } else { - PMA_ajaxShowMessage(data.error, false); - } - $icon.show(); - $throbber.remove(); - }); - } - $(this).blur(); + PMA_expandNavigationTree($(this)); }); - + /** * Register event handler for click on the reload * navigation icon at the top of the panel @@ -212,6 +158,115 @@ $(function() { }); }); +/** + * Expands/collapses the navigation tree and sets to view the expanded + * + * @param object $expandElem the element that initiated the expanding + * @return void + */ +function PMA_expandNavigationTree($expandElem) { + var $children = $expandElem.closest('li').children('div.list_container'); + var $icon = $expandElem.find('img'); + if ($expandElem.hasClass('loaded')) { + if ($icon.is('.ic_b_plus')) { + $icon.removeClass('ic_b_plus').addClass('ic_b_minus'); + $children.show('fast'); + } else { + $icon.removeClass('ic_b_minus').addClass('ic_b_plus'); + $children.hide('fast'); + } + } else { + var $destination = $expandElem.closest('li'); + var $throbber = $('#pma_navigation .throbber') + .first() + .clone() + .css('visibility', 'visible'); + $icon.hide(); + $throbber.insertBefore($icon); + + var searchClause = PMA_fastFilter.getSearchClause(); + var searchClause2 = PMA_fastFilter.getSearchClause2($expandElem); + + var params = { + aPath: $expandElem.find('span.aPath').text(), + vPath: $expandElem.find('span.vPath').text(), + pos: $expandElem.find('span.pos').text(), + pos2_name: $expandElem.find('span.pos2_name').text(), + pos2_value: $expandElem.find('span.pos2_value').text(), + searchClause: searchClause, + searchClause2: searchClause2 + }; + var url = $('#pma_navigation').find('a.navigation_url').attr('href'); + $.get(url, params, function (data) { + if (data.success === true) { + $expandElem.addClass('loaded'); + $destination.find('div.list_container').remove(); // FIXME: Hack, there shouldn't be a list container there + $destination.append(data.message); + $icon.removeClass('ic_b_plus').addClass('ic_b_minus'); + $destination + .children('div.list_container') + .show('fast'); + if ($destination.find('ul > li').length == 1) { + $destination.find('ul > li') + .find('a.expander.container') + .click(); + } + } else { + PMA_ajaxShowMessage(data.error, false); + } + $icon.show(); + $throbber.remove(); + }); + } + $expandElem.blur(); +} + +/* + * Auto-scrolls the newly chosen database + * + * @param object $element The element to set to view + * @param object $container The container srollable element + * + */ +function scrollToView($element, $container) { + var pushToOffset = $element.offset().top - $container.offset().top + $container.scrollTop(); + $('#pma_navigation_tree_content').stop().animate({ + scrollTop: pushToOffset + }); +} + +/* + * Auto-expands the newly chosen database + * + * @param string $oldDb The previous database + * @param string $newDb The newly chosen database + * + */ +function PMA_autoExpandDatabaseInUse($oldDb, $newDb) { + var $expandElem, $icon; + //Collapse the previous database + if($oldDb !== '' && $oldDb !== $newDb) { + $expandElem = $('#pma_navigation_tree a.dbLink:contains("' + $oldDb + '")') + .parent().find('a.expander').eq(0); + $icon = $expandElem.find('img'); + if ($icon.is('.ic_b_minus')) + PMA_expandNavigationTree($expandElem); + } + //expand the newly chosen database + $expandElem = $('#pma_navigation_tree a.dbLink:contains("' + $newDb + '")') + .parent().find('a.expander').eq(0); + $icon = $expandElem.find('img'); + if ($icon.is('.ic_b_plus')) { + PMA_expandNavigationTree($expandElem); + } + //scroll to new database + if ($oldDb !== $newDb) { + setTimeout(function() { + scrollToView($expandElem.closest('li'), $('#pma_navigation_tree_content')); + }, 150); + } +} + /** * Reloads the whole navigation tree while preserving its state * @@ -221,7 +276,10 @@ $(function() { function PMA_reloadNavigation(callback) { var $throbber = $('#pma_navigation .throbber') .first() - .css('visibility', 'visible'); + .css({ + 'visibility' : 'visible', + 'display' : 'block' + }); var params = { reload: true, pos: $('#pma_navigation_tree').find('a.expander:first > span.pos').text() @@ -264,7 +322,10 @@ function PMA_reloadNavigation(callback) { }); var url = $('#pma_navigation').find('a.navigation_url').attr('href'); $.post(url, params, function (data) { - $throbber.css('visibility', 'hidden'); + $throbber.css('visibility', 'hidden').css({ + 'visibility' : 'hidden', + 'display' : 'none' + }); if (data.success) { $('#pma_navigation_tree').html(data.message).children('div').show(); // Fire the callback, if any diff --git a/js/sql.js b/js/sql.js index 4866e6f98b..90942aa7f5 100644 --- a/js/sql.js +++ b/js/sql.js @@ -296,6 +296,7 @@ AJAX.registerOnload('sql.js', function() { } else if (typeof data.reload != 'undefined') { // this happens if a USE or DROP command was typed PMA_commonActions.setDb(data.db); + PMA_reloadNavigation(); PMA_commonActions.refreshMain(false, function () { if ($('#result_query').length) { $('#result_query').remove(); @@ -306,7 +307,6 @@ AJAX.registerOnload('sql.js', function() { .prependTo('#page_content'); } }); - PMA_reloadNavigation(); } $sqlqueryresults.show().trigger('makegrid'); diff --git a/libraries/navigation/NavigationTree.class.php b/libraries/navigation/NavigationTree.class.php index 40900cb09b..98cdcb8370 100644 --- a/libraries/navigation/NavigationTree.class.php +++ b/libraries/navigation/NavigationTree.class.php @@ -639,7 +639,7 @@ class PMA_NavigationTree $retval = $this->_fastFilterHtml($this->_tree); $retval .= $this->_getPageSelector($this->_tree); $this->groupTree(); - $retval .= "